@jpmorganchase/mosaic-cli 0.1.0-beta.5 → 0.1.0-beta.6
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 +11 -10
- package/dist/index.js +2 -5
- package/dist/serve-snapshot.js +24 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/build.js
CHANGED
|
@@ -3,7 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const fsExtra = require('fs-extra');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
|
|
6
|
-
module.exports = async (config, targetDir,
|
|
6
|
+
module.exports = async (config, targetDir, options) => {
|
|
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
|
|
@@ -11,9 +11,10 @@ module.exports = async (config, targetDir, scope) => {
|
|
|
11
11
|
...source,
|
|
12
12
|
options: { ...source.options, cache: false }
|
|
13
13
|
}));
|
|
14
|
+
const scope = options.scope && options.scope.split(',');
|
|
14
15
|
const pullDocs = new PullDocs(config);
|
|
15
|
-
const
|
|
16
|
-
await fsExtra.emptyDir(
|
|
16
|
+
const pathDir = path.posix.join(targetDir, options.name ?? new Date().toISOString());
|
|
17
|
+
await fsExtra.emptyDir(pathDir);
|
|
17
18
|
await pullDocs.start();
|
|
18
19
|
// If `scope` arg was used, scope the filesystem to those namespaces
|
|
19
20
|
const filesystem = Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem;
|
|
@@ -45,10 +46,10 @@ module.exports = async (config, targetDir, scope) => {
|
|
|
45
46
|
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.`);
|
|
46
47
|
}
|
|
47
48
|
//}
|
|
48
|
-
await fs.promises.mkdir(path.dirname(path.join(
|
|
49
|
+
await fs.promises.mkdir(path.dirname(path.join(pathDir, String(filePath))), {
|
|
49
50
|
recursive: true
|
|
50
51
|
});
|
|
51
|
-
await fs.promises.writeFile(path.join(
|
|
52
|
+
await fs.promises.writeFile(path.join(pathDir, String(filePath)), rawFile);
|
|
52
53
|
}
|
|
53
54
|
for (const alias in symlinks) {
|
|
54
55
|
if (alias.startsWith('/.tags')) {
|
|
@@ -58,20 +59,20 @@ Try using \`--scope\` to just output certain namespaced sources, or adding a \`p
|
|
|
58
59
|
if (target.startsWith('/.tags')) {
|
|
59
60
|
continue;
|
|
60
61
|
}
|
|
61
|
-
await fsExtra.ensureDir(path.join(
|
|
62
|
+
await fsExtra.ensureDir(path.join(pathDir, path.dirname(alias)));
|
|
62
63
|
|
|
63
64
|
try {
|
|
64
|
-
const exists = !!(await fs.promises.stat(path.join(
|
|
65
|
+
const exists = !!(await fs.promises.stat(path.join(pathDir, alias)));
|
|
65
66
|
if (exists) {
|
|
66
67
|
console.error(
|
|
67
68
|
new Error(
|
|
68
|
-
`Symlink at '${path.join(
|
|
69
|
+
`Symlink at '${path.join(pathDir, alias)}' already exists. Aborting build.`
|
|
69
70
|
)
|
|
70
71
|
);
|
|
71
72
|
process.exit(1);
|
|
72
73
|
}
|
|
73
74
|
} catch {
|
|
74
|
-
await fs.promises.symlink(path.join(
|
|
75
|
+
await fs.promises.symlink(path.join(pathDir, target), path.join(pathDir, alias));
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -79,7 +80,7 @@ Try using \`--scope\` to just output certain namespaced sources, or adding a \`p
|
|
|
79
80
|
console.log(
|
|
80
81
|
`Filesystem for ${
|
|
81
82
|
Array.isArray(scope) ? scope.length : config.sources.length
|
|
82
|
-
} source(s) written to disk at '${
|
|
83
|
+
} source(s) written to disk at '${pathDir}'`
|
|
83
84
|
);
|
|
84
85
|
pullDocs.stop();
|
|
85
86
|
}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ program
|
|
|
11
11
|
.option('-o, --out <string>', 'Output directory', '.tmp/.mosaic-build')
|
|
12
12
|
.option('-s, --scope <strings>', 'Command separated namespaces')
|
|
13
13
|
.option('-p, --port <number>', 'Port to serve on', 8080)
|
|
14
|
+
.option('-n, --name <string>', 'Snapshot name')
|
|
14
15
|
.option('-S, --snapshot <string>', 'Snapshot path');
|
|
15
16
|
|
|
16
17
|
program.parse();
|
|
@@ -25,11 +26,7 @@ if (program.args[0] === 'build') {
|
|
|
25
26
|
`Could not find config file at ${path.resolve(process.cwd(), options.config)}.`
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
|
-
build(
|
|
29
|
-
config,
|
|
30
|
-
path.resolve(process.cwd(), options.out),
|
|
31
|
-
options.scope && options.scope.split(',')
|
|
32
|
-
);
|
|
29
|
+
build(config, path.resolve(process.cwd(), options.out), options);
|
|
33
30
|
}
|
|
34
31
|
} else if (program.args[0] === 'serve') {
|
|
35
32
|
if (options.snapshot !== undefined) {
|
package/dist/serve-snapshot.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
2
|
const cors = require('cors');
|
|
3
|
-
const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
|
|
4
3
|
const path = require('path');
|
|
5
4
|
|
|
6
5
|
const app = express();
|
|
@@ -22,25 +21,42 @@ module.exports = async (targetDir, port, scope) => {
|
|
|
22
21
|
try {
|
|
23
22
|
fs.stat(fullPath, (err, stats) => {
|
|
24
23
|
if (err) {
|
|
24
|
+
console.error(`[PULLDOCS] snapshot for ${fullPath} not found... sending 404..\n`, err);
|
|
25
25
|
res.status(404).end();
|
|
26
|
+
return;
|
|
26
27
|
}
|
|
27
28
|
if (stats != undefined) {
|
|
28
29
|
if (stats.isDirectory()) {
|
|
29
30
|
fs.stat(path.join(fullPath, 'index'), (err, _stats) => {
|
|
30
31
|
if (err) {
|
|
32
|
+
console.error(
|
|
33
|
+
`[PULLDOCS] No index found in snapshot directory ${fullPath} ... sending 404 ...\n`,
|
|
34
|
+
err
|
|
35
|
+
);
|
|
31
36
|
res.status(404).end();
|
|
37
|
+
return;
|
|
32
38
|
}
|
|
39
|
+
console.info(`[PULLDOCS] sending redirect to for snapshot ${fullPath} ... \n`);
|
|
33
40
|
res.status(302).json({ redirect: path.join(req.path, 'index') });
|
|
34
41
|
});
|
|
35
42
|
} else {
|
|
36
43
|
fs.realpath(fullPath, (err, pagePath) => {
|
|
37
44
|
if (err) {
|
|
45
|
+
console.error(
|
|
46
|
+
`[PULLDOCS] snapshot not found for ${fullPath} ... sending 404 ...\n`,
|
|
47
|
+
err
|
|
48
|
+
);
|
|
38
49
|
res.status(404).end();
|
|
50
|
+
return;
|
|
39
51
|
}
|
|
40
|
-
|
|
41
52
|
fs.readFile(pagePath, (err, data) => {
|
|
42
53
|
if (err) {
|
|
54
|
+
console.error(
|
|
55
|
+
`[PULLDOCS] unable to read file for ${fullPath} / ${pagePath} ... sending 404 ...\n`,
|
|
56
|
+
err
|
|
57
|
+
);
|
|
43
58
|
res.status(404).end();
|
|
59
|
+
return;
|
|
44
60
|
}
|
|
45
61
|
if (path.extname(pagePath) === '.mdx') {
|
|
46
62
|
res.contentType('text/mdx');
|
|
@@ -49,16 +65,21 @@ module.exports = async (targetDir, port, scope) => {
|
|
|
49
65
|
} else if (path.extname(pagePath) === '.xml') {
|
|
50
66
|
res.contentType('application/xml');
|
|
51
67
|
}
|
|
68
|
+
console.info(`[PULLDOCS] sending data for ${fullPath} / ${pagePath} ... `);
|
|
52
69
|
res.send(data);
|
|
53
70
|
});
|
|
54
71
|
});
|
|
55
72
|
}
|
|
56
73
|
} else {
|
|
74
|
+
console.error(
|
|
75
|
+
`[PULLDOCS] cannot fs.stat anything in snapshot for ${fullPath} ... sending 404..\n`,
|
|
76
|
+
err
|
|
77
|
+
);
|
|
57
78
|
res.status(404).end();
|
|
58
79
|
}
|
|
59
80
|
});
|
|
60
81
|
} catch (e) {
|
|
61
|
-
console.error(e);
|
|
82
|
+
console.error(`[PULLDOCS] `, e);
|
|
62
83
|
res.status(500).end();
|
|
63
84
|
}
|
|
64
85
|
});
|
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.6",
|
|
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.6",
|
|
27
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.6",
|
|
28
28
|
"commander": "^9.3.0"
|
|
29
29
|
}
|
|
30
30
|
}
|