@jpmorganchase/mosaic-cli 0.1.0-beta.3 → 0.1.0-beta.4

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,11 @@
1
1
  # @jpmorganchase/mosaic-cli
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - bd285df: added dist to package.json
8
+
3
9
  ## 0.1.0-beta.3
4
10
 
5
11
  ### Patch Changes
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.4",
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.4",
27
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.4",
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
- }