-
Notifications
You must be signed in to change notification settings - Fork 1
/
copyjrls.js
65 lines (53 loc) · 1.82 KB
/
copyjrls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @license
* Copyright 2022 The FOAM Authors. All Rights Reserved.
* http://www.apache.org/licenses/LICENSE-2.0
*/
// TODO: don't actually load files
// print warning if uglify not found
// create sourcemap
// merge with processArgs.js
const startTime = Date.now();
const path_ = require('path');
const fs_ = require('fs');
const path = require('path/posix');
require('./foam3/src/foam_node.js');
var [argv, X, flags] = require('./foam3/tools/processArgs.js')(
'',
{ version: '', license: '', pom: 'pom' },
{ debug: true, java: false, web: true }
);
foam.require(X.pom, false, true);
const outPath = 'runtime/journals';
if ( ! fs_.existsSync(outPath) ) {
fs_.mkdirSync(outPath, { recursive: true });
}
async function findJournals({ jrls, srcPath }) {
const walker = foam.util.filesystem.FileWalker.create();
walker.files.sub((_1, _2, info) => {
for ( const fileInfo of info.files ) {
const extName = path_.extname(fileInfo.name);
if ( extName !== '.jrl' ) continue;
const fullPath = fileInfo.fullPath;
const baseName = path_.basename(fileInfo.name, extName);
if ( ! jrls[baseName] ) jrls[baseName] = '';
jrls[baseName] += fs_.readFileSync(fullPath).toString();
}
})
await walker.walk(srcPath);
}
const main = async function () {
const jrls = {};
// names = fs_.readFileSync('./journals').toString().split('\n');
// for ( let name of names ) {
// if ( name === '' ) continue;
// jrls[name] = '';
// }
await findJournals({ jrls, srcPath: 'foam3/src' });
await findJournals({ jrls, srcPath: 'myproject/src' });
for ( const key in jrls ) {
fs_.writeFileSync(path_.join(outPath, key + '.0'), jrls[key]);
fs_.writeFileSync(path_.join(outPath, key), '');
}
};
main();