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

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/dist/build.mjs ADDED
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-73UKEGXN.mjs";import"./chunk-AY5WSHSM.mjs";export{a as default};
@@ -0,0 +1,3 @@
1
+ import{a as d,b as w}from"./chunk-AY5WSHSM.mjs";import o from"fs";import t from"path";import y from"fs-extra";import k from"@jpmorganchase/mosaic-core";async function b(r,h,p){r.plugins=r.plugins.filter(({runTimeOnly:i})=>!i),r.sources=r.sources.map(i=>w(d({},i),{options:w(d({},i.options),{cache:!1})}));let c=p.scope&&p.scope.split(","),a=new k(r),e=t.posix.join(h,p.name??new Date().toISOString());await y.emptyDir(e),await a.start();let m=Array.isArray(c)?a.filesystem.scope(c):a.filesystem,g=0;a.onSourceUpdate(async()=>{try{if(++g===r.sources.length){let i=m.symlinksToJSON(),S=await m.promises.glob("**",{cwd:"/",onlyFiles:!0});for(let s of S){let n=await m.promises.readFile(String(s),{includeConflicts:!0}),l=n[0];if(n.length>1)throw new Error(`'${s}' returned multiple files at the same location, this will result in overwritten data in the output. Aborting build.
2
+
3
+ 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.`);await o.promises.mkdir(t.dirname(t.join(e,String(s))),{recursive:!0}),await o.promises.writeFile(t.join(e,String(s)),l)}let x=process.cwd();for(let s in i)if(!s.startsWith("/.tags")){for(let{target:n}of i[s])if(!n.startsWith("/.tags")){await y.ensureDir(t.join(e,t.dirname(s)));try{!!await o.promises.stat(t.join(e,s))&&(console.error(new Error(`Symlink at '${t.join(e,s)}' already exists. Aborting build.`)),process.exit(1))}catch{let l=t.join(e,n),u=t.join(e,s),f=t.basename(u),j=t.relative(t.dirname(u),l);process.chdir(t.dirname(u)),o.existsSync(f)&&o.unlinkSync(f),await o.promises.symlink(j,f)}}}process.chdir(x),console.log(`[Mosaic] filesystem for ${Array.isArray(c)?c.length:r.sources.length} source(s) written to disk at '${e}'`),a.stop()}}catch(i){console.error(i),process.exit(1)}})}export{b as a};
@@ -0,0 +1 @@
1
+ var f=Object.defineProperty,g=Object.defineProperties;var h=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var i=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var e=(c,a,b)=>a in c?f(c,a,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[a]=b,k=(c,a)=>{for(var b in a||(a={}))i.call(a,b)&&e(c,b,a[b]);if(d)for(var b of d(a))j.call(a,b)&&e(c,b,a[b]);return c},l=(c,a)=>g(c,h(a));export{k as a,l as b};
@@ -0,0 +1 @@
1
+ import{globby as _}from"globby";import m from"path";import E from"fs";import{S3Client as p,CreateBucketCommand as A,PutObjectCommand as I}from"@aws-sdk/client-s3";import s from"assert";function d(n,e,t){return new p({region:n,credentials:{accessKeyId:e,secretAccessKey:t}})}async function u(n){s(process.env.MOSAIC_S3_BUCKET,"Cannot read S3 bucket - MOSAIC_S3_BUCKET environment var is missing"),s(process.env.MOSAIC_S3_REGION,"Cannot read S3 bucket - MOSAIC_S3_REGION environment var is missing"),s(process.env.MOSAIC_S3_ACCESS_KEY_ID,"Cannot read S3 bucket - MOSAIC_S3_ACCESS_KEY_ID environment var is missing"),s(process.env.MOSAIC_S3_SECRET_ACCESS_KEY,"Cannot read S3 bucket - MOSAIC_S3_SECRET_ACCESS_KEY environment var is missing");let e=process.env.MOSAIC_S3_BUCKET,t=process.env.MOSAIC_S3_REGION,c=process.env.MOSAIC_S3_ACCESS_KEY_ID,C=process.env.MOSAIC_S3_SECRET_ACCESS_KEY,o=d(t,c,C);await o.send(new A({Bucket:e})),(await _(n)).forEach(async S=>{let r=S.replace(`${n}${m.sep}`,"");console.log(`Upload ${r} to bucket ${e}`);let a=await E.promises.readFile(S,{encoding:"utf-8"}),i=new I({Bucket:e,Key:r,Body:a});await o.send(i)})}export{u as a};
@@ -0,0 +1 @@
1
+ import u from"express";import x from"cors";import r from"path";import g from"@jpmorganchase/mosaic-core";var p=u(),f=new Set;async function j(w,l,d){p.listen(l,()=>{console.log(`[Mosaic] Listening on port ${l}${Array.isArray(d)?` (scoped to ${d.join(", ")})`:""}`)});let i=new g(w);await i.start();let a=Array.isArray(d)?i.filesystem.scope(d):i.filesystem;p.use(x(),u.json()),p.get("/**",async(t,s)=>{try{if(await a.promises.exists(t.path))if((await a.promises.stat(t.path)).isDirectory())await a.promises.exists(r.join(t.path,"index"))?s.status(302).json({redirect:r.join(t.path,"index")}):s.status(404).end();else{let e=await a.promises.realpath(t.path);r.extname(e)===".mdx"?s.contentType("text/mdx"):r.extname(e)===".json"?s.contentType("application/json"):r.extname(e)===".xml"&&s.contentType("application/xml");let o=await a.promises.readFile(t.path);s.send(o)}else s.status(404).end()}catch(e){console.error(e),s.status(500).end()}}),p.post("/workflows",async(t,s)=>{try{let{user:e,route:o,markdown:m,name:c}=t.body;if(!c)throw new Error("Workflow name is required");if(await a.promises.exists(o)){let n=(await a.promises.stat(o)).isDirectory()?r.posix.join(o,"index"):o,y=await a.promises.realpath(n),h=await i.triggerWorkflow(c,y,{user:e,markdown:m});s.contentType("application/json"),s.send(h)}}catch(e){console.error(e),s.status(500).send(e.message).end()}}),p.post("/sources/add",async(t,s)=>{try{let{definition:e,name:o,isPreview:m=!0}=t.body;if(process.env.MOSAIC_ENABLE_SOURCE_PUSH!=="true")throw new Error("Source push is disabled.");if(!e)throw new Error("Source definition is required");if(o)f.forEach(n=>{n.name===o&&i.stopSource(n.id)});else throw new Error("A name is required");if(m){let n=`preview-${e.namespace}`;e.namespace=n}let c=await i.addSource(e);f.add({name:o,id:c.id}),s.send(c!==void 0?e.namespace:"Unable to add source")}catch(e){console.error(e),s.status(500).send(e.message).end()}})}export{j as a};
@@ -0,0 +1 @@
1
+ import e from"path";import{globby as x}from"globby";import o from"fs-extra";async function j(r,s){let{mode:p,platform:c}=r.deployment;if(p==="snapshot-file"&&c==="vercel"){console.info("[Mosaic] deployment platform is vercel...adding snapshot files to site output trace");let i=process.cwd(),n=e.posix.join(i,".next"),l=s.out,f=s.name??new Date().toISOString();o.existsSync(n)||console.warn("[Mosaic] unable to update nextjs trace file. Build the site before generating the snapshot");let t=e.posix.join(n,"server","pages","[...route].js.nft.json"),m=await x(`**/${l}/${f}/**`,{cwd:i,onlyFiles:!0}),a=JSON.parse(await o.promises.readFile(t,"utf-8"));m.forEach(d=>{let u=e.posix.dirname(t),h=e.posix.relative(u,e.posix.resolve(d));a.files.push(h)}),await o.promises.writeFile(t,JSON.stringify(a))}}export{j as a};
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a as e}from"./chunk-73UKEGXN.mjs";import{a as s}from"./chunk-UD5ZA5MY.mjs";import{a as p}from"./chunk-P3RXN7HU.mjs";import{a as n}from"./chunk-VIYGD5XX.mjs";import"./chunk-AY5WSHSM.mjs";import{program as r}from"commander";import i from"path";import{pathToFileURL as a}from"url";r.option("-c, --config <string>","Config path").option("-o, --out <string>","Output directory",".tmp/.mosaic-build").option("-s, --scope <strings>","Command separated namespaces").option("-p, --port <number>","Port to serve on","8080").option("-n, --name <string>","Snapshot name").option("-S, --snapshot <string>","Snapshot path");r.parse();var o=r.opts(),t;if(o.config!==void 0){if(t=await import(a(i.resolve(process.cwd(),o.config)).toString()),!t)throw new Error(`[Mosaic] could not find config file at ${i.resolve(process.cwd(),o.config)}.`)}else throw new Error("[Mosaic] no config file provided");r.args[0]==="build"&&e(t.default,i.resolve(process.cwd(),o.out),o);r.args[0]==="serve"&&s(t.default,o.port,o.scope&&o.scope.split(","));r.args[0]==="upload"&&p(i.resolve(process.cwd(),o.snapshot));r.args[0]==="deploy"&&n(t.default,o);
package/dist/serve.mjs ADDED
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-UD5ZA5MY.mjs";import"./chunk-AY5WSHSM.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-P3RXN7HU.mjs";import"./chunk-AY5WSHSM.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-VIYGD5XX.mjs";import"./chunk-AY5WSHSM.mjs";export{a as updateTraceFile};
package/package.json CHANGED
@@ -1,30 +1,34 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-cli",
3
- "version": "0.1.0-beta.30",
3
+ "version": "0.1.0-beta.32",
4
4
  "author": "",
5
5
  "description": "Mosaic command line scripts",
6
6
  "license": "Apache-2.0",
7
- "main": "./dist/index.js",
7
+ "main": "./dist/index.mjs",
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "node": "./dist/index.js"
12
+ "import": "./dist/index.mjs",
13
+ "node": "./dist/index.mjs"
14
14
  }
15
15
  },
16
16
  "engines": {
17
17
  "node": ">=16.10.0 || >=18.0.0"
18
18
  },
19
19
  "bin": {
20
- "mosaic": "./dist/index.js"
20
+ "mosaic": "./dist/index.mjs"
21
21
  },
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
25
  "scripts": {
26
- "build": "tsc",
26
+ "build": "npm-run-all --parallel build:*",
27
+ "build:types": "tsc",
28
+ "build:cli": "node ./scripts/bundle.js",
27
29
  "clean": "rm -fr dist",
30
+ "docker:build": "docker build . --tag mosaic-fs:latest",
31
+ "docker:start": "docker run -it --rm --ipc=host -p 8080:8080 --mount source=docs,destination=/app/docs --network mosaic-net --name mosaic-fs mosaic-fs:latest",
28
32
  "lint": "eslint --ignore-pattern \"**/__tests__/**\""
29
33
  },
30
34
  "repository": {
@@ -33,13 +37,20 @@
33
37
  "directory": "packages/cli"
34
38
  },
35
39
  "devDependencies": {
36
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.30"
40
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.32",
41
+ "esbuild": "0.14.35",
42
+ "esbuild-node-externals": "^1.0.2",
43
+ "fast-glob": "^3.2.7"
37
44
  },
38
45
  "dependencies": {
39
- "@jpmorganchase/mosaic-core": "^0.1.0-beta.30",
46
+ "@jpmorganchase/mosaic-core": "^0.1.0-beta.32",
47
+ "@jpmorganchase/mosaic-plugins": "^0.1.0-beta.32",
48
+ "@jpmorganchase/mosaic-standard-generator": "^0.1.0-beta.32",
49
+ "@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.32",
40
50
  "@aws-sdk/client-s3": "^3.278.0",
41
51
  "commander": "^9.4.1",
42
52
  "cors": "^2.8.5",
53
+ "deepmerge": "^4.2.2",
43
54
  "express": "^4.18.2",
44
55
  "fs-extra": "^10.1.0",
45
56
  "globby": "^13.1.3",
package/dist/build.js DELETED
@@ -1,94 +0,0 @@
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.
44
-
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.`);
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();
86
- }
87
- }
88
- catch (e) {
89
- console.error(e);
90
- process.exit(1);
91
- }
92
- });
93
- }
94
- //# sourceMappingURL=build.js.map
package/dist/build.js.map DELETED
@@ -1 +0,0 @@
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,CAAC,CAAC,CAAC;IACJ,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACrF,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,C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C5C,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;4BAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;4BACzE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;4BACvC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;gCAChC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;6BAC9B;4BACD,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;yBACzD;qBACF;iBACF;gBACD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO,CAAC,GAAG,CACT,2BACE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MACvD,kCAAkC,OAAO,GAAG,CAC7C,CAAC;gBACF,MAAM,CAAC,IAAI,EAAE,CAAC;aACf;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
package/dist/index.js DELETED
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env node
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';
9
- program
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');
16
- program.parse();
17
- const options = program.opts();
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`);
27
- }
28
- if (program.args[0] === 'build') {
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);
39
- }
40
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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,MAA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AAO,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"}
package/dist/serve.js DELETED
@@ -1,72 +0,0 @@
1
- import express from 'express';
2
- import cors from 'cors';
3
- import path from 'node:path';
4
- import MosaicCore from '@jpmorganchase/mosaic-core';
5
- const app = express();
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
- }
44
- }
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
package/dist/serve.js.map DELETED
@@ -1 +0,0 @@
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,MAAM,EAAE,IAAI,EAAE,KAAK;IACrD,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QACpB,OAAO,CAAC,GAAG,CACT,8BAA8B,IAAI,GAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAC9D,EAAE,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IAErB,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;IAErF,GAAG,CAAC,GAAG,CAAC,IAAI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G,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"}
@@ -1,39 +0,0 @@
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
@@ -1 +0,0 @@
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;AACrF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAAS,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,eAAe;IACxD,OAAO,IAAI,QAAQ,CAAC;QAClB,MAAM;QACN,WAAW,EAAE;YACX,WAAW;YACX,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAAC,SAAS;IACtD,MAAM,CACJ,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAC5B,qEAAqE,CACtE,CAAC;IACF,MAAM,CACJ,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAC5B,qEAAqE,CACtE,CAAC;IACF,MAAM,CACJ,OAAO,CAAC,GAAG,CAAC,uBAAuB,EACnC,4EAA4E,CAC7E,CAAC;IACF,MAAM,CACJ,OAAO,CAAC,GAAG,CAAC,2BAA2B,EACvC,gFAAgF,CACjF,CAAC;IACF,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACpD,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACpD,MAAM,WAAW,GAAW,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IAChE,MAAM,eAAe,GAAW,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;IAExE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAClE,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IACtC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAC,QAAQ,EAAC,EAAE;QAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,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"}
@@ -1,42 +0,0 @@
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
@@ -1 +0,0 @@
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,CAA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