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