@jpmorganchase/mosaic-cli 0.1.0-beta.3 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @jpmorganchase/mosaic-cli
2
2
 
3
+ ## 0.1.0-beta.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 61a246c: This releases add support for generate / build and serve snapshots
8
+
9
+ ## 0.1.0-beta.4
10
+
11
+ ### Patch Changes
12
+
13
+ - bd285df: added dist to package.json
14
+
3
15
  ## 0.1.0-beta.3
4
16
 
5
17
  ### Patch Changes
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 => ({ ...source, options: { ...source.options, cache: false } }));
10
+ config.sources = config.sources.map(source => ({
11
+ ...source,
12
+ options: { ...source.options, cache: false }
13
+ }));
11
14
  const pullDocs = new PullDocs(config);
12
- await fsExtra.emptyDir(targetDir);
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 = (Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.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(targetDir, String(filePath))), {
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(targetDir, path.dirname(alias)));
61
+ await fsExtra.ensureDir(path.join(datedDir, path.dirname(alias)));
61
62
 
62
63
  try {
63
- const exists = !!(await fs.promises.stat(path.join(targetDir, alias)));
64
+ const exists = !!(await fs.promises.stat(path.join(datedDir, alias)));
64
65
  if (exists) {
65
- console.error(new Error(`Symlink at '${path.join(targetDir, alias)}' already exists. Aborting build.`));
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(targetDir, target), path.join(targetDir, alias));
74
+ await fs.promises.symlink(path.join(datedDir, target), path.join(datedDir, alias));
70
75
  }
71
76
  }
72
77
  }
73
78
 
74
- console.log(`Filesystem for ${Array.isArray(scope) ? scope.length : config.sources.length} source(s) written to disk at '${targetDir}'`);
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("./serve");
5
- const build = require("./build");
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
- .requiredOption('-c, --config <string>', 'Config path')
10
- .option('-o, --out <string>', 'Output directory', '.tmp/.mosaic-build')
11
- .option('-s, --scope <strings>', 'Command separated namespaces')
12
- .option('-p, --port <number>', 'Port to serve on', 8080);
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
- build(config, path.resolve(process.cwd(), options.out), options.scope && options.scope.split(','));
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(`[PullDocs] Listening on port ${port}${Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''}`);
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,8 +1,8 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-cli",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.5",
4
4
  "author": "",
5
- "description": "",
5
+ "description": "Mosaic command line scripts",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/index.js",
8
8
  "engines": {
@@ -11,6 +11,9 @@
11
11
  "bin": {
12
12
  "mosaic": "./dist/index.js"
13
13
  },
14
+ "files": [
15
+ "dist"
16
+ ],
14
17
  "scripts": {
15
18
  "build": "mkdir -p ./dist && cp -f ./src/** ./dist",
16
19
  "clean": "rm -fr dist"
@@ -20,8 +23,8 @@
20
23
  "url": "git@github.com:jpmorganchase/mosaic.git"
21
24
  },
22
25
  "devDependencies": {
23
- "@jpmorganchase/mosaic-core": "^0.1.0-beta.3",
24
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.3",
26
+ "@jpmorganchase/mosaic-core": "^0.1.0-beta.5",
27
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.5",
25
28
  "commander": "^9.3.0"
26
29
  }
27
- }
30
+ }
@@ -1,2 +0,0 @@
1
- @jpmorganchase/mosaic-cli:build: cache hit, replaying output b556821cea3f960d
2
- @jpmorganchase/mosaic-cli:build: $ mkdir -p ./dist && cp -f ./src/** ./dist
package/src/build.js DELETED
@@ -1,84 +0,0 @@
1
- const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
2
- const path = require('path');
3
- const fsExtra = require('fs-extra');
4
- const fs = require('fs');
5
-
6
- module.exports = async (config, targetDir, scope) => {
7
- // Strip out any plugins that are meant for runtime use only (i.e. `LazyPagePlugin`)
8
- config.plugins = config.plugins.filter(({ runTimeOnly }) => !runTimeOnly);
9
- // Turn off `cache` for each source
10
- config.sources = config.sources.map(source => ({ ...source, options: { ...source.options, cache: false } }));
11
- const pullDocs = new PullDocs(config);
12
- await fsExtra.emptyDir(targetDir);
13
- await pullDocs.start();
14
- // If `scope` arg was used, scope the filesystem to those namespaces
15
- const filesystem = (Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem);
16
- let calls = 0;
17
- pullDocs.onSourceUpdate(async (value, source) => {
18
- try {
19
- if (++calls === config.sources.length) {
20
- const symlinks = filesystem.symlinksToJSON();
21
- const allFiles = await filesystem.promises.glob('**', {
22
- cwd: '/',
23
- onlyFiles: true
24
- });
25
- for (const filePath of allFiles) {
26
- // if (dotDirRegExp.test(filePath)) {
27
- // continue;
28
- // }
29
- const rawFiles = await filesystem.promises.readFile(String(filePath), {
30
- includeConflicts: true
31
- });
32
- let rawFile = rawFiles[0];
33
- if (rawFiles.length > 1) {
34
- // TODO: We could join colliding JSON files together. e.g. sidebar.json files
35
- // if (path.basename(String(filePath)).startsWith('.') && path.extname(String(filePath)) === '.json') {
36
- // console.warn(`'${filePath}' returned multiple files at the same location. Since the files were JSON dot files, they were merged using a basic Lodash \`merge\`.`);
37
- // rawFile = Buffer.from(JSON.stringify(merge(...rawFiles.map(fileData => JSON.parse(String(fileData))))));
38
- // } else {
39
- throw new Error(`'${filePath}' returned multiple files at the same location, this will result in overwritten data in the output. Aborting build.
40
-
41
- 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
- }
43
- //}
44
- await fs.promises.mkdir(path.dirname(path.join(targetDir, String(filePath))), {
45
- recursive: true
46
- });
47
- await fs.promises.writeFile(
48
- path.join(targetDir, String(filePath)),
49
- rawFile
50
- );
51
- }
52
- for (const alias in symlinks) {
53
- if (alias.startsWith('/.tags')) {
54
- continue;
55
- }
56
- for (const { target } of symlinks[alias]) {
57
- if (target.startsWith('/.tags')) {
58
- continue;
59
- }
60
- await fsExtra.ensureDir(path.join(targetDir, path.dirname(alias)));
61
-
62
- try {
63
- const exists = !!(await fs.promises.stat(path.join(targetDir, alias)));
64
- if (exists) {
65
- console.error(new Error(`Symlink at '${path.join(targetDir, alias)}' already exists. Aborting build.`));
66
- process.exit(1);
67
- }
68
- } catch {
69
- await fs.promises.symlink(path.join(targetDir, target), path.join(targetDir, alias));
70
- }
71
- }
72
- }
73
-
74
- console.log(`Filesystem for ${Array.isArray(scope) ? scope.length : config.sources.length} source(s) written to disk at '${targetDir}'`);
75
- pullDocs.stop();
76
- }
77
- } catch (e) {
78
- console.error(e);
79
- process.exit(1);
80
- }
81
- });
82
-
83
-
84
- };
package/src/index.js DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { program } = require('commander');
4
- const serve = require("./serve");
5
- const build = require("./build");
6
- const path = require('path');
7
-
8
- program
9
- .requiredOption('-c, --config <string>', 'Config path')
10
- .option('-o, --out <string>', 'Output directory', '.tmp/.mosaic-build')
11
- .option('-s, --scope <strings>', 'Command separated namespaces')
12
- .option('-p, --port <number>', 'Port to serve on', 8080);
13
-
14
- program.parse();
15
-
16
- const options = program.opts();
17
-
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
- if (program.args[0] === 'build') {
25
- build(config, path.resolve(process.cwd(), options.out), options.scope && options.scope.split(','));
26
- } else if (program.args[0] === 'serve') {
27
- serve(config, options.port, options.scope && options.scope.split(','));
28
- }
package/src/serve.js DELETED
@@ -1,51 +0,0 @@
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 (config, port, scope) => {
9
-
10
- app.listen(port, () => {
11
- console.log(`[PullDocs] Listening on port ${port}${Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''}`);
12
- });
13
- const pullDocs = new PullDocs(config);
14
- await pullDocs.start();
15
-
16
- const fs = Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem;
17
-
18
- app.use(cors());
19
-
20
- app.get('/**', async (req, res) => {
21
- try {
22
- if (await fs.promises.exists(req.path)) {
23
- if ((await fs.promises.stat(req.path)).isDirectory()) {
24
- if (await fs.promises.exists(path.join(req.path, 'index'))) {
25
- // Don't do an actual redirect - just send the URL as the response
26
- res.status(302).json({ redirect: path.join(req.path, 'index') });
27
- } else {
28
- res.status(404).end();
29
- }
30
- } else {
31
- const pagePath = await fs.promises.realpath(req.path);
32
- if (path.extname(pagePath) === '.mdx') {
33
- res.contentType('text/mdx');
34
- } else if (path.extname(pagePath) === '.json') {
35
- res.contentType('application/json');
36
- } else if (path.extname(pagePath) === '.xml') {
37
- res.contentType('application/xml');
38
- }
39
- const result = await fs.promises.readFile(req.path);
40
- res.send(result);
41
- }
42
- }
43
- else {
44
- res.status(404).end();
45
- }
46
- } catch (e) {
47
- console.error(e);
48
- res.status(500).end();
49
- }
50
- });
51
- };
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "allowJs": true,
5
- "target": "es2015",
6
- "esModuleInterop": true,
7
- "moduleResolution": "NodeNext",
8
- "sourceMap": true,
9
- "outDir": "dist",
10
- "skipLibCheck": true,
11
- "rootDir": "./src"
12
- },
13
- "include": ["src/**/*", "../common/src/types"],
14
- "exclude": ["node_modules", "src/**/__tests__/**/*", "src/__tests__/**/*", "**/dist/**/*"]
15
- }