@jpmorganchase/mosaic-cli 0.1.0-beta.4 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/build.js +22 -15
- package/dist/index.js +33 -13
- package/dist/serve-snapshot.js +65 -0
- package/dist/serve.js +7 -5
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/dist/build.js
CHANGED
|
@@ -7,12 +7,16 @@ module.exports = async (config, targetDir, scope) => {
|
|
|
7
7
|
// Strip out any plugins that are meant for runtime use only (i.e. `LazyPagePlugin`)
|
|
8
8
|
config.plugins = config.plugins.filter(({ runTimeOnly }) => !runTimeOnly);
|
|
9
9
|
// Turn off `cache` for each source
|
|
10
|
-
config.sources = config.sources.map(source => ({
|
|
10
|
+
config.sources = config.sources.map(source => ({
|
|
11
|
+
...source,
|
|
12
|
+
options: { ...source.options, cache: false }
|
|
13
|
+
}));
|
|
11
14
|
const pullDocs = new PullDocs(config);
|
|
12
|
-
|
|
15
|
+
const datedDir = path.posix.join(targetDir, new Date().toISOString());
|
|
16
|
+
await fsExtra.emptyDir(datedDir);
|
|
13
17
|
await pullDocs.start();
|
|
14
18
|
// If `scope` arg was used, scope the filesystem to those namespaces
|
|
15
|
-
const filesystem =
|
|
19
|
+
const filesystem = Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem;
|
|
16
20
|
let calls = 0;
|
|
17
21
|
pullDocs.onSourceUpdate(async (value, source) => {
|
|
18
22
|
try {
|
|
@@ -41,13 +45,10 @@ module.exports = async (config, targetDir, scope) => {
|
|
|
41
45
|
Try using \`--scope\` to just output certain namespaced sources, or adding a \`prefixDir\` to the source options to move the source files into a separate folder.`);
|
|
42
46
|
}
|
|
43
47
|
//}
|
|
44
|
-
await fs.promises.mkdir(path.dirname(path.join(
|
|
48
|
+
await fs.promises.mkdir(path.dirname(path.join(datedDir, String(filePath))), {
|
|
45
49
|
recursive: true
|
|
46
50
|
});
|
|
47
|
-
await fs.promises.writeFile(
|
|
48
|
-
path.join(targetDir, String(filePath)),
|
|
49
|
-
rawFile
|
|
50
|
-
);
|
|
51
|
+
await fs.promises.writeFile(path.join(datedDir, String(filePath)), rawFile);
|
|
51
52
|
}
|
|
52
53
|
for (const alias in symlinks) {
|
|
53
54
|
if (alias.startsWith('/.tags')) {
|
|
@@ -57,21 +58,29 @@ Try using \`--scope\` to just output certain namespaced sources, or adding a \`p
|
|
|
57
58
|
if (target.startsWith('/.tags')) {
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
|
-
await fsExtra.ensureDir(path.join(
|
|
61
|
+
await fsExtra.ensureDir(path.join(datedDir, path.dirname(alias)));
|
|
61
62
|
|
|
62
63
|
try {
|
|
63
|
-
const exists = !!(await fs.promises.stat(path.join(
|
|
64
|
+
const exists = !!(await fs.promises.stat(path.join(datedDir, alias)));
|
|
64
65
|
if (exists) {
|
|
65
|
-
console.error(
|
|
66
|
+
console.error(
|
|
67
|
+
new Error(
|
|
68
|
+
`Symlink at '${path.join(datedDir, alias)}' already exists. Aborting build.`
|
|
69
|
+
)
|
|
70
|
+
);
|
|
66
71
|
process.exit(1);
|
|
67
72
|
}
|
|
68
73
|
} catch {
|
|
69
|
-
await fs.promises.symlink(path.join(
|
|
74
|
+
await fs.promises.symlink(path.join(datedDir, target), path.join(datedDir, alias));
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
console.log(
|
|
79
|
+
console.log(
|
|
80
|
+
`Filesystem for ${
|
|
81
|
+
Array.isArray(scope) ? scope.length : config.sources.length
|
|
82
|
+
} source(s) written to disk at '${datedDir}'`
|
|
83
|
+
);
|
|
75
84
|
pullDocs.stop();
|
|
76
85
|
}
|
|
77
86
|
} catch (e) {
|
|
@@ -79,6 +88,4 @@ Try using \`--scope\` to just output certain namespaced sources, or adding a \`p
|
|
|
79
88
|
process.exit(1);
|
|
80
89
|
}
|
|
81
90
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
91
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { program } = require('commander');
|
|
4
|
-
const serve = require(
|
|
5
|
-
const
|
|
4
|
+
const serve = require('./serve');
|
|
5
|
+
const serveSnapshot = require('./serve-snapshot');
|
|
6
|
+
const build = require('./build');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
|
|
8
9
|
program
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
.option('-c, --config <string>', 'Config path')
|
|
11
|
+
.option('-o, --out <string>', 'Output directory', '.tmp/.mosaic-build')
|
|
12
|
+
.option('-s, --scope <strings>', 'Command separated namespaces')
|
|
13
|
+
.option('-p, --port <number>', 'Port to serve on', 8080)
|
|
14
|
+
.option('-S, --snapshot <string>', 'Snapshot path');
|
|
13
15
|
|
|
14
16
|
program.parse();
|
|
15
17
|
|
|
16
18
|
const options = program.opts();
|
|
17
19
|
|
|
18
|
-
const config = require(path.resolve(process.cwd(), options.config));
|
|
19
|
-
|
|
20
|
-
if (!config) {
|
|
21
|
-
throw new Error(`Could not find config file at ${path.resolve(process.cwd(), options.config)}.`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
if (program.args[0] === 'build') {
|
|
25
|
-
|
|
21
|
+
if (options.config !== undefined) {
|
|
22
|
+
const config = require(path.resolve(process.cwd(), options.config));
|
|
23
|
+
if (!config) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Could not find config file at ${path.resolve(process.cwd(), options.config)}.`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
build(
|
|
29
|
+
config,
|
|
30
|
+
path.resolve(process.cwd(), options.out),
|
|
31
|
+
options.scope && options.scope.split(',')
|
|
32
|
+
);
|
|
33
|
+
}
|
|
26
34
|
} else if (program.args[0] === 'serve') {
|
|
35
|
+
if (options.snapshot !== undefined) {
|
|
36
|
+
const targetDir = path.resolve(process.cwd(), options.snapshot);
|
|
37
|
+
serveSnapshot(targetDir, options.port, options.scope && options.scope.split(','));
|
|
38
|
+
}
|
|
39
|
+
if (options.config !== undefined) {
|
|
40
|
+
const config = require(path.resolve(process.cwd(), options.config));
|
|
41
|
+
if (!config) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Could not find config file at ${path.resolve(process.cwd(), options.config)}.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
27
46
|
serve(config, options.port, options.scope && options.scope.split(','));
|
|
47
|
+
}
|
|
28
48
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const cors = require('cors');
|
|
3
|
+
const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const app = express();
|
|
7
|
+
|
|
8
|
+
module.exports = async (targetDir, port, scope) => {
|
|
9
|
+
app.listen(port, () => {
|
|
10
|
+
console.log(
|
|
11
|
+
`Serving ${targetDir} on port ${port}${
|
|
12
|
+
Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''
|
|
13
|
+
}`
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
|
|
19
|
+
app.use(cors());
|
|
20
|
+
app.get('/**', async (req, res) => {
|
|
21
|
+
const fullPath = path.posix.join(targetDir, req.path);
|
|
22
|
+
try {
|
|
23
|
+
fs.stat(fullPath, (err, stats) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
res.status(404).end();
|
|
26
|
+
}
|
|
27
|
+
if (stats != undefined) {
|
|
28
|
+
if (stats.isDirectory()) {
|
|
29
|
+
fs.stat(path.join(fullPath, 'index'), (err, _stats) => {
|
|
30
|
+
if (err) {
|
|
31
|
+
res.status(404).end();
|
|
32
|
+
}
|
|
33
|
+
res.status(302).json({ redirect: path.join(req.path, 'index') });
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
fs.realpath(fullPath, (err, pagePath) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
res.status(404).end();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fs.readFile(pagePath, (err, data) => {
|
|
42
|
+
if (err) {
|
|
43
|
+
res.status(404).end();
|
|
44
|
+
}
|
|
45
|
+
if (path.extname(pagePath) === '.mdx') {
|
|
46
|
+
res.contentType('text/mdx');
|
|
47
|
+
} else if (path.extname(pagePath) === '.json') {
|
|
48
|
+
res.contentType('application/json');
|
|
49
|
+
} else if (path.extname(pagePath) === '.xml') {
|
|
50
|
+
res.contentType('application/xml');
|
|
51
|
+
}
|
|
52
|
+
res.send(data);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
res.status(404).end();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
res.status(500).end();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
package/dist/serve.js
CHANGED
|
@@ -6,9 +6,12 @@ const path = require('path');
|
|
|
6
6
|
const app = express();
|
|
7
7
|
|
|
8
8
|
module.exports = async (config, port, scope) => {
|
|
9
|
-
|
|
10
9
|
app.listen(port, () => {
|
|
11
|
-
console.log(
|
|
10
|
+
console.log(
|
|
11
|
+
`[PullDocs] Listening on port ${port}${
|
|
12
|
+
Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''
|
|
13
|
+
}`
|
|
14
|
+
);
|
|
12
15
|
});
|
|
13
16
|
const pullDocs = new PullDocs(config);
|
|
14
17
|
await pullDocs.start();
|
|
@@ -35,12 +38,11 @@ module.exports = async (config, port, scope) => {
|
|
|
35
38
|
res.contentType('application/json');
|
|
36
39
|
} else if (path.extname(pagePath) === '.xml') {
|
|
37
40
|
res.contentType('application/xml');
|
|
38
|
-
}
|
|
41
|
+
}
|
|
39
42
|
const result = await fs.promises.readFile(req.path);
|
|
40
43
|
res.send(result);
|
|
41
44
|
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
45
|
+
} else {
|
|
44
46
|
res.status(404).end();
|
|
45
47
|
}
|
|
46
48
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"author": "",
|
|
5
5
|
"description": "Mosaic command line scripts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@jpmorganchase/mosaic-core": "^0.1.0-beta.
|
|
27
|
-
"@jpmorganchase/mosaic-types": "^0.1.0-beta.
|
|
26
|
+
"@jpmorganchase/mosaic-core": "^0.1.0-beta.5",
|
|
27
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.5",
|
|
28
28
|
"commander": "^9.3.0"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|