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

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.
@@ -0,0 +1 @@
1
+ export default function build(config: any, targetDir: any, options: any): Promise<void>;
package/dist/build.js CHANGED
@@ -1,84 +1,94 @@
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.
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import fsExtra from 'fs-extra';
4
+ import MosaicCore from '@jpmorganchase/mosaic-core';
5
+ export default async function build(config, targetDir, options) {
6
+ // Strip out any plugins that are meant for runtime use only (i.e. `LazyPagePlugin`)
7
+ config.plugins = config.plugins.filter(({ runTimeOnly }) => !runTimeOnly);
8
+ // Turn off `cache` for each source
9
+ config.sources = config.sources.map(source => ({
10
+ ...source,
11
+ options: { ...source.options, cache: false }
12
+ }));
13
+ const scope = options.scope && options.scope.split(',');
14
+ const mosaic = new MosaicCore(config);
15
+ const pathDir = path.posix.join(targetDir, options.name ?? new Date().toISOString());
16
+ await fsExtra.emptyDir(pathDir);
17
+ await mosaic.start();
18
+ // If `scope` arg was used, scope the filesystem to those namespaces
19
+ const filesystem = Array.isArray(scope) ? mosaic.filesystem.scope(scope) : mosaic.filesystem;
20
+ let calls = 0;
21
+ mosaic.onSourceUpdate(async () => {
22
+ try {
23
+ if (++calls === config.sources.length) {
24
+ const symlinks = filesystem.symlinksToJSON();
25
+ const allFiles = await filesystem.promises.glob('**', {
26
+ cwd: '/',
27
+ onlyFiles: true
28
+ });
29
+ for (const filePath of allFiles) {
30
+ // if (dotDirRegExp.test(filePath)) {
31
+ // continue;
32
+ // }
33
+ const rawFiles = await filesystem.promises.readFile(String(filePath), {
34
+ includeConflicts: true
35
+ });
36
+ const rawFile = rawFiles[0];
37
+ if (rawFiles.length > 1) {
38
+ // TODO: We could join colliding JSON files together. e.g. sidebar.json files
39
+ // if (path.basename(String(filePath)).startsWith('.') && path.extname(String(filePath)) === '.json') {
40
+ // 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\`.`);
41
+ // rawFile = Buffer.from(JSON.stringify(merge(...rawFiles.map(fileData => JSON.parse(String(fileData))))));
42
+ // } else {
43
+ throw new Error(`'${filePath}' returned multiple files at the same location, this will result in overwritten data in the output. Aborting build.
40
44
 
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
- }
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));
46
+ }
47
+ //}
48
+ await fs.promises.mkdir(path.dirname(path.join(pathDir, String(filePath))), {
49
+ recursive: true
50
+ });
51
+ await fs.promises.writeFile(path.join(pathDir, String(filePath)), rawFile);
52
+ }
53
+ const pwd = process.cwd();
54
+ for (const alias in symlinks) {
55
+ if (alias.startsWith('/.tags')) {
56
+ continue;
57
+ }
58
+ for (const { target } of symlinks[alias]) {
59
+ if (target.startsWith('/.tags')) {
60
+ continue;
61
+ }
62
+ await fsExtra.ensureDir(path.join(pathDir, path.dirname(alias)));
63
+ try {
64
+ const exists = !!(await fs.promises.stat(path.join(pathDir, alias)));
65
+ if (exists) {
66
+ console.error(new Error(`Symlink at '${path.join(pathDir, alias)}' already exists. Aborting build.`));
67
+ process.exit(1);
68
+ }
69
+ }
70
+ catch {
71
+ const targetPath = path.join(pathDir, target);
72
+ const aliasPath = path.join(pathDir, alias);
73
+ const aliasBasename = path.basename(aliasPath);
74
+ const targetSymlink = path.relative(path.dirname(aliasPath), targetPath);
75
+ process.chdir(path.dirname(aliasPath));
76
+ if (fs.existsSync(aliasBasename)) {
77
+ fs.unlinkSync(aliasBasename);
78
+ }
79
+ await fs.promises.symlink(targetSymlink, aliasBasename);
80
+ }
81
+ }
82
+ }
83
+ process.chdir(pwd);
84
+ console.log(`[Mosaic] filesystem for ${Array.isArray(scope) ? scope.length : config.sources.length} source(s) written to disk at '${pathDir}'`);
85
+ mosaic.stop();
70
86
  }
71
- }
72
87
  }
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
- };
88
+ catch (e) {
89
+ console.error(e);
90
+ process.exit(1);
91
+ }
92
+ });
93
+ }
94
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,UAAU,MAAM,4BAA4B,CAAC;AAEpD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO;IAC5D,oFAAoF;IACpF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1E,mCAAmC;IACnC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7C,GAAG,MAAM;QACT,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;KAC7C,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AC,CAAC,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js CHANGED
@@ -1,28 +1,40 @@
1
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
-
2
+ import { program } from 'commander';
3
+ import path from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import serve from './serve.js';
6
+ import uploadS3Snapshot from './upload-s3-snapshot.js';
7
+ import build from './build.js';
8
+ import { updateTraceFile } from './vercel-snapshot.js';
8
9
  program
9
- .requiredOption('-c, --config <string>', 'Config path')
10
+ .option('-c, --config <string>', 'Config path')
10
11
  .option('-o, --out <string>', 'Output directory', '.tmp/.mosaic-build')
11
12
  .option('-s, --scope <strings>', 'Command separated namespaces')
12
- .option('-p, --port <number>', 'Port to serve on', 8080);
13
-
13
+ .option('-p, --port <number>', 'Port to serve on', '8080')
14
+ .option('-n, --name <string>', 'Snapshot name')
15
+ .option('-S, --snapshot <string>', 'Snapshot path');
14
16
  program.parse();
15
-
16
17
  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)}.`);
18
+ let config;
19
+ if (options.config !== undefined) {
20
+ config = await import(pathToFileURL(path.resolve(process.cwd(), options.config)).toString());
21
+ if (!config) {
22
+ throw new Error(`[Mosaic] could not find config file at ${path.resolve(process.cwd(), options.config)}.`);
23
+ }
24
+ }
25
+ else {
26
+ throw new Error(`[Mosaic] no config file provided`);
22
27
  }
23
-
24
28
  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(','));
29
+ build(config.default, path.resolve(process.cwd(), options.out), options);
30
+ }
31
+ if (program.args[0] === 'serve') {
32
+ serve(config.default, options.port, options.scope && options.scope.split(','));
33
+ }
34
+ if (program.args[0] === 'upload') {
35
+ uploadS3Snapshot(path.resolve(process.cwd(), options.snapshot));
36
+ }
37
+ if (program.args[0] === 'deploy') {
38
+ updateTraceFile(config.default, options);
28
39
  }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAEvD,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO;KACJ,MAAM,CAAC,uBAAuB,EAAE,aAAa,CAAC;KAC9C,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,CAAC;KACtE,MAAM,CAAC,uBAAuB,EAAE,8BAA8B,CAAC;KAC/D,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,CAAC;KACzD,MAAM,CAAC,qBAAqB,EAAE,eAAe,CAAC;KAC9C,MAAM,CAAC,yBAAyB,EAAE,eAAe,CAAC,CAAC;AAEtD,OAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAE/B,IAAI,MAAM,CAAC;AACX,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE;IAChC,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE7F,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,0CAA0C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CACzF,CAAC;KACH;CACF;KAAM;IACL,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;CACrD;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IAC/B,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;CAC1E;AACD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IAC/B,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;CAChF;AACD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAChC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;CACjE;AACD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAChC,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC1C"}
@@ -0,0 +1 @@
1
+ export default function serve(config: any, port: any, scope: any): Promise<void>;
package/dist/serve.js CHANGED
@@ -1,51 +1,72 @@
1
- const express = require('express');
2
- const cors = require('cors');
3
- const { default: PullDocs } = require('@jpmorganchase/mosaic-core');
4
- const path = require('path');
5
-
1
+ import express from 'express';
2
+ import cors from 'cors';
3
+ import path from 'node:path';
4
+ import MosaicCore from '@jpmorganchase/mosaic-core';
6
5
  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);
6
+ export default async function serve(config, port, scope) {
7
+ app.listen(port, () => {
8
+ console.log(`[Mosaic] Listening on port ${port}${Array.isArray(scope) ? ` (scoped to ${scope.join(', ')})` : ''}`);
9
+ });
10
+ const mosaic = new MosaicCore(config);
11
+ await mosaic.start();
12
+ const fs = Array.isArray(scope) ? mosaic.filesystem.scope(scope) : mosaic.filesystem;
13
+ app.use(cors(), express.json());
14
+ app.get('/**', async (req, res) => {
15
+ try {
16
+ if (await fs.promises.exists(req.path)) {
17
+ if ((await fs.promises.stat(req.path)).isDirectory()) {
18
+ if (await fs.promises.exists(path.join(req.path, 'index'))) {
19
+ // Don't do an actual redirect - just send the URL as the response
20
+ res.status(302).json({ redirect: path.join(req.path, 'index') });
21
+ }
22
+ else {
23
+ res.status(404).end();
24
+ }
25
+ }
26
+ else {
27
+ const pagePath = await fs.promises.realpath(req.path);
28
+ if (path.extname(pagePath) === '.mdx') {
29
+ res.contentType('text/mdx');
30
+ }
31
+ else if (path.extname(pagePath) === '.json') {
32
+ res.contentType('application/json');
33
+ }
34
+ else if (path.extname(pagePath) === '.xml') {
35
+ res.contentType('application/xml');
36
+ }
37
+ const result = await fs.promises.readFile(req.path);
38
+ res.send(result);
39
+ }
40
+ }
41
+ else {
42
+ res.status(404).end();
43
+ }
41
44
  }
42
- }
43
- else {
44
- res.status(404).end();
45
- }
46
- } catch (e) {
47
- console.error(e);
48
- res.status(500).end();
49
- }
50
- });
51
- };
45
+ catch (e) {
46
+ console.error(e);
47
+ res.status(500).end();
48
+ }
49
+ });
50
+ app.post('/workflows', async (req, res) => {
51
+ try {
52
+ const { user, route: routeReq, markdown, name } = req.body;
53
+ if (!name) {
54
+ throw new Error('Workflow name is required');
55
+ }
56
+ if (await fs.promises.exists(routeReq)) {
57
+ const route = (await fs.promises.stat(routeReq)).isDirectory()
58
+ ? path.posix.join(routeReq, 'index')
59
+ : routeReq;
60
+ const pagePath = await fs.promises.realpath(route);
61
+ const result = await mosaic.triggerWorkflow(name, pagePath, { user, markdown });
62
+ res.contentType('application/json');
63
+ res.send(result);
64
+ }
65
+ }
66
+ catch (e) {
67
+ console.error(e);
68
+ res.status(500).send(e.message).end();
69
+ }
70
+ });
71
+ }
72
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,UAAU,MAAM,4BAA4B,CAAC;AAEpD,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,KAAK,CAAC,M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,IAAI,CAAC,IAAI,EAAE;gBACT,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;aAC9C;YAED,IAAI,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBACtC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE;oBAC5D,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC;oBACpC,CAAC,CAAC,QAAQ,CAAC;gBACb,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACnD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAChF,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;gBACpC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aAClB;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;SACvC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ export default function uploadS3Snapshot(targetDir: any): Promise<void>;
@@ -0,0 +1,39 @@
1
+ import { globby } from 'globby';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import { S3Client, CreateBucketCommand, PutObjectCommand } from '@aws-sdk/client-s3';
5
+ import assert from 'assert';
6
+ function createClient(region, accessKeyId, secretAccessKey) {
7
+ return new S3Client({
8
+ region,
9
+ credentials: {
10
+ accessKeyId,
11
+ secretAccessKey
12
+ }
13
+ });
14
+ }
15
+ export default async function uploadS3Snapshot(targetDir) {
16
+ assert(process.env.MOSAIC_S3_BUCKET, 'Cannot read S3 bucket - MOSAIC_S3_BUCKET environment var is missing');
17
+ assert(process.env.MOSAIC_S3_REGION, 'Cannot read S3 bucket - MOSAIC_S3_REGION environment var is missing');
18
+ assert(process.env.MOSAIC_S3_ACCESS_KEY_ID, 'Cannot read S3 bucket - MOSAIC_S3_ACCESS_KEY_ID environment var is missing');
19
+ assert(process.env.MOSAIC_S3_SECRET_ACCESS_KEY, 'Cannot read S3 bucket - MOSAIC_S3_SECRET_ACCESS_KEY environment var is missing');
20
+ const bucket = process.env.MOSAIC_S3_BUCKET;
21
+ const region = process.env.MOSAIC_S3_REGION;
22
+ const accessKeyId = process.env.MOSAIC_S3_ACCESS_KEY_ID;
23
+ const secretAccessKey = process.env.MOSAIC_S3_SECRET_ACCESS_KEY;
24
+ const client = createClient(region, accessKeyId, secretAccessKey);
25
+ await client.send(new CreateBucketCommand({ Bucket: bucket }));
26
+ const paths = await globby(targetDir);
27
+ paths.forEach(async (filePath) => {
28
+ const key = filePath.replace(`${targetDir}${path.sep}`, '');
29
+ console.log(`Upload ${key} to bucket ${bucket}`);
30
+ const body = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
31
+ const putCommand = new PutObjectCommand({
32
+ Bucket: bucket,
33
+ Key: key,
34
+ Body: body
35
+ });
36
+ await client.send(putCommand);
37
+ });
38
+ }
39
+ //# sourceMappingURL=upload-s3-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-s3-snapshot.js","sourceRoot":"","sources":["../src/upload-s3-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;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AAE,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,cAAc,MAAM,EAAE,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACzE,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC;YACtC,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG;YACR,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * When deploying a mosaic site to vercel, snapshot files are ignored resulting in a 404 when a page is accessed from the site.
3
+ *
4
+ * Vercel uses output file tracing (https://nextjs.org/docs/advanced-features/output-file-tracing) to determine what files need to be deployed.
5
+ * Due to the dynamic nature of mosaic sites, files that are required, the snapshots, are not traced correctly.
6
+ *
7
+ * This script adds an entry into the [...route].js.nft.json file for each file in the provided snapshot ensuring that the snapshot files are deployed.
8
+ *
9
+ */
10
+ export declare function updateTraceFile(config: any, options: any): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import path from 'path';
2
+ import { globby } from 'globby';
3
+ import fsExtra from 'fs-extra';
4
+ /**
5
+ * When deploying a mosaic site to vercel, snapshot files are ignored resulting in a 404 when a page is accessed from the site.
6
+ *
7
+ * Vercel uses output file tracing (https://nextjs.org/docs/advanced-features/output-file-tracing) to determine what files need to be deployed.
8
+ * Due to the dynamic nature of mosaic sites, files that are required, the snapshots, are not traced correctly.
9
+ *
10
+ * This script adds an entry into the [...route].js.nft.json file for each file in the provided snapshot ensuring that the snapshot files are deployed.
11
+ *
12
+ */
13
+ export async function updateTraceFile(config, options) {
14
+ const { mode, platform } = config.deployment;
15
+ if (mode === 'snapshot-file' && platform === 'vercel') {
16
+ console.info('[Mosaic] deployment platform is vercel...adding snapshot files to site output trace');
17
+ const projectBase = process.cwd();
18
+ const buildDir = path.posix.join(projectBase, '.next');
19
+ const snapshotDir = options.out;
20
+ const snapshotName = options.name ?? new Date().toISOString();
21
+ if (!fsExtra.existsSync(buildDir)) {
22
+ console.warn('[Mosaic] unable to update nextjs trace file. Build the site before generating the snapshot');
23
+ }
24
+ const nftFilePath = path.posix.join(buildDir, 'server', 'pages', '[...route].js.nft.json');
25
+ // Find all snapshot files
26
+ const paths = await globby(`**/${snapshotDir}/${snapshotName}/**`, {
27
+ cwd: projectBase,
28
+ onlyFiles: true
29
+ });
30
+ const data = JSON.parse(await fsExtra.promises.readFile(nftFilePath, 'utf-8'));
31
+ // Add the snapshot file paths to the nft trace
32
+ paths.forEach(snapshotFile => {
33
+ // Determine relative path to the file we want to include
34
+ const nftFileDir = path.posix.dirname(nftFilePath);
35
+ const newEntry = path.posix.relative(nftFileDir, path.posix.resolve(snapshotFile));
36
+ // Add the file and write our changes
37
+ data.files.push(newEntry);
38
+ });
39
+ await fsExtra.promises.writeFile(nftFilePath, JSON.stringify(data));
40
+ }
41
+ }
42
+ //# sourceMappingURL=vercel-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-snapshot.js","sourceRoot":"","sources":["../src/vercel-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAM,EAAE,OAAO;IACnD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;IAE7C,IAAI,IAAI,KAAK,eAAe,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACrD,OAAO,CAAC,IAAI,CACV,qFAAqF,CACtF,CAAC;QAEF,MAAM,WAAW,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AC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACrE;AACH,CAAC"}
package/package.json CHANGED
@@ -1,27 +1,48 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-cli",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.30",
4
4
  "author": "",
5
- "description": "",
5
+ "description": "Mosaic command line scripts",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/index.js",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "node": "./dist/index.js"
14
+ }
15
+ },
8
16
  "engines": {
9
- "node": ">= 12.0.0"
17
+ "node": ">=16.10.0 || >=18.0.0"
10
18
  },
11
19
  "bin": {
12
20
  "mosaic": "./dist/index.js"
13
21
  },
22
+ "files": [
23
+ "dist"
24
+ ],
14
25
  "scripts": {
15
- "build": "mkdir -p ./dist && cp -f ./src/** ./dist",
16
- "clean": "rm -fr dist"
26
+ "build": "tsc",
27
+ "clean": "rm -fr dist",
28
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
17
29
  },
18
30
  "repository": {
19
31
  "type": "git",
20
- "url": "git@github.com:jpmorganchase/mosaic.git"
32
+ "url": "git@github.com:jpmorganchase/mosaic.git",
33
+ "directory": "packages/cli"
21
34
  },
22
35
  "devDependencies": {
23
- "@jpmorganchase/mosaic-core": "^0.1.0-beta.3",
24
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.3",
25
- "commander": "^9.3.0"
36
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.30"
37
+ },
38
+ "dependencies": {
39
+ "@jpmorganchase/mosaic-core": "^0.1.0-beta.30",
40
+ "@aws-sdk/client-s3": "^3.278.0",
41
+ "commander": "^9.4.1",
42
+ "cors": "^2.8.5",
43
+ "express": "^4.18.2",
44
+ "fs-extra": "^10.1.0",
45
+ "globby": "^13.1.3",
46
+ "mkdirp": "^1.0.4"
26
47
  }
27
- }
48
+ }
@@ -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/CHANGELOG.md DELETED
@@ -1,25 +0,0 @@
1
- # @jpmorganchase/mosaic-cli
2
-
3
- ## 0.1.0-beta.3
4
-
5
- ### Patch Changes
6
-
7
- - 457df5e: switch to public package
8
-
9
- ## 0.1.0-beta.2
10
-
11
- ### Patch Changes
12
-
13
- - e1bbbe7: Initial release of Mosaic Core file-system.
14
-
15
- Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
16
-
17
- - 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
18
-
19
- ## 0.1.0
20
-
21
- ### Patch Changes
22
-
23
- - e1bbbe7: Initial release of Mosaic Core file-system.
24
-
25
- Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
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
- }