@jpmorganchase/mosaic-cli 0.1.0-beta.5 → 0.1.0-beta.7

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,24 @@
1
1
  # @jpmorganchase/mosaic-cli
2
2
 
3
+ ## 0.1.0-beta.7
4
+
5
+ ### Minor Changes
6
+
7
+ - 46adaec: Initial release of theme and client side search
8
+
9
+ We are iterating towards deploying our site code.
10
+
11
+ This release includes
12
+
13
+ - initial work for client-side search support
14
+ - Mosaic theme.
15
+
16
+ ## 0.1.0-beta.6
17
+
18
+ ### Patch Changes
19
+
20
+ - c103b24: Release fixes for snapshot serve
21
+
3
22
  ## 0.1.0-beta.5
4
23
 
5
24
  ### Patch Changes
package/dist/build.js CHANGED
@@ -1,9 +1,9 @@
1
- const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
1
+ const { default: Mosaic } = require('@jpmorganchase/mosaic-core');
2
2
  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, scope) => {
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,14 +11,15 @@ module.exports = async (config, targetDir, scope) => {
11
11
  ...source,
12
12
  options: { ...source.options, cache: false }
13
13
  }));
14
- const pullDocs = new PullDocs(config);
15
- const datedDir = path.posix.join(targetDir, new Date().toISOString());
16
- await fsExtra.emptyDir(datedDir);
17
- await pullDocs.start();
14
+ const scope = options.scope && options.scope.split(',');
15
+ const mosaic = new Mosaic(config);
16
+ const pathDir = path.posix.join(targetDir, options.name ?? new Date().toISOString());
17
+ await fsExtra.emptyDir(pathDir);
18
+ await mosaic.start();
18
19
  // If `scope` arg was used, scope the filesystem to those namespaces
19
- const filesystem = Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem;
20
+ const filesystem = Array.isArray(scope) ? mosaic.filesystem.scope(scope) : mosaic.filesystem;
20
21
  let calls = 0;
21
- pullDocs.onSourceUpdate(async (value, source) => {
22
+ mosaic.onSourceUpdate(async (value, source) => {
22
23
  try {
23
24
  if (++calls === config.sources.length) {
24
25
  const symlinks = filesystem.symlinksToJSON();
@@ -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(datedDir, String(filePath))), {
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(datedDir, String(filePath)), rawFile);
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(datedDir, path.dirname(alias)));
62
+ await fsExtra.ensureDir(path.join(pathDir, path.dirname(alias)));
62
63
 
63
64
  try {
64
- const exists = !!(await fs.promises.stat(path.join(datedDir, alias)));
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(datedDir, alias)}' already exists. Aborting build.`
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(datedDir, target), path.join(datedDir, alias));
75
+ await fs.promises.symlink(path.join(pathDir, target), path.join(pathDir, alias));
75
76
  }
76
77
  }
77
78
  }
@@ -79,9 +80,9 @@ 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 '${datedDir}'`
83
+ } source(s) written to disk at '${pathDir}'`
83
84
  );
84
- pullDocs.stop();
85
+ mosaic.stop();
85
86
  }
86
87
  } catch (e) {
87
88
  console.error(e);
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) {
@@ -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(`[Mosaic] 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
+ `[Mosaic] 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(`[Mosaic] 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
+ `[Mosaic] 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
+ `[Mosaic] 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(`[Mosaic] sending data for ${fullPath} / ${pagePath} ... `);
52
69
  res.send(data);
53
70
  });
54
71
  });
55
72
  }
56
73
  } else {
74
+ console.error(
75
+ `[Mosaic] 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(`[Mosaic] `, e);
62
83
  res.status(500).end();
63
84
  }
64
85
  });
package/dist/serve.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const express = require('express');
2
2
  const cors = require('cors');
3
- const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
3
+ const { default: MosaicCore } = require('@jpmorganchase/mosaic-core');
4
4
  const path = require('path');
5
5
 
6
6
  const app = express();
@@ -8,17 +8,17 @@ const app = express();
8
8
  module.exports = async (config, port, scope) => {
9
9
  app.listen(port, () => {
10
10
  console.log(
11
- `[PullDocs] Listening on port ${port}${
11
+ `[Mosaic] Listening on port ${port}${
12
12
  Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''
13
13
  }`
14
14
  );
15
15
  });
16
- const pullDocs = new PullDocs(config);
17
- await pullDocs.start();
16
+ const mosaic = new MosaicCore(config);
17
+ await mosaic.start();
18
18
 
19
- const fs = Array.isArray(scope) ? pullDocs.filesystem.scope(scope) : pullDocs.filesystem;
19
+ const fs = Array.isArray(scope) ? mosaic.filesystem.scope(scope) : mosaic.filesystem;
20
20
 
21
- app.use(cors());
21
+ app.use(cors(), express.json());
22
22
 
23
23
  app.get('/**', async (req, res) => {
24
24
  try {
@@ -50,4 +50,27 @@ module.exports = async (config, port, scope) => {
50
50
  res.status(500).end();
51
51
  }
52
52
  });
53
+
54
+ app.post('/workflows', async (req, res) => {
55
+ try {
56
+ const { user, route: routeReq, markdown, name } = req.body;
57
+
58
+ if (!name) {
59
+ throw new Error('Workflow name is required');
60
+ }
61
+
62
+ if (await fs.promises.exists(routeReq)) {
63
+ const route = (await fs.promises.stat(routeReq)).isDirectory()
64
+ ? path.posix.join(routeReq, 'index')
65
+ : routeReq;
66
+ const pagePath = await fs.promises.realpath(route);
67
+ const result = await mosaic.triggerWorkflow(name, pagePath, { user, markdown });
68
+ res.contentType('application/json');
69
+ res.send(result);
70
+ }
71
+ } catch (e) {
72
+ console.error(e);
73
+ res.status(500).send(e.message).end();
74
+ }
75
+ });
53
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-cli",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.7",
4
4
  "author": "",
5
5
  "description": "Mosaic command line scripts",
6
6
  "license": "Apache-2.0",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "scripts": {
18
- "build": "mkdir -p ./dist && cp -f ./src/** ./dist",
18
+ "build": "mkdirp dist && cp -f src/** dist",
19
19
  "clean": "rm -fr dist"
20
20
  },
21
21
  "repository": {
@@ -23,8 +23,11 @@
23
23
  "url": "git@github.com:jpmorganchase/mosaic.git"
24
24
  },
25
25
  "devDependencies": {
26
- "@jpmorganchase/mosaic-core": "^0.1.0-beta.5",
27
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.5",
26
+ "@jpmorganchase/mosaic-core": "^0.1.0-beta.7",
27
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.7",
28
28
  "commander": "^9.3.0"
29
+ },
30
+ "dependencies": {
31
+ "mkdirp": "^1.0.4"
29
32
  }
30
33
  }