@jpmorganchase/mosaic-cli 0.1.0-beta.4 → 0.1.0-beta.41
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.d.ts +1 -0
- package/dist/build.mjs +1 -0
- package/dist/chunk-AY5WSHSM.mjs +1 -0
- package/dist/chunk-J73DKLHI.mjs +3 -0
- package/dist/chunk-P3RXN7HU.mjs +1 -0
- package/dist/chunk-UD5ZA5MY.mjs +1 -0
- package/dist/chunk-VIYGD5XX.mjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/serve.d.ts +1 -0
- package/dist/serve.mjs +1 -0
- package/dist/upload-s3-snapshot.d.ts +1 -0
- package/dist/upload-s3-snapshot.mjs +1 -0
- package/dist/vercel-snapshot.d.ts +10 -0
- package/dist/vercel-snapshot.mjs +1 -0
- package/package.json +40 -11
- package/CHANGELOG.md +0 -31
- package/dist/build.js +0 -84
- package/dist/index.js +0 -28
- package/dist/serve.js +0 -51
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function build(config: any, targetDir: any, options: any): Promise<void>;
|
package/dist/build.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-J73DKLHI.mjs";import"./chunk-AY5WSHSM.mjs";export{a as default};
|
|
@@ -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,3 @@
|
|
|
1
|
+
import{a as d,b as w}from"./chunk-AY5WSHSM.mjs";import n from"fs";import e from"path";import k from"deepmerge";import h from"fs-extra";import b from"@jpmorganchase/mosaic-core";async function F(r,y,u){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 p=u.scope&&u.scope.split(","),l=new b(r),s=e.posix.join(y,u.name??new Date().toISOString());await h.emptyDir(s),await l.start();let f=Array.isArray(p)?l.filesystem.scope(p):l.filesystem,g=0;l.onSourceUpdate(async()=>{try{if(++g===r.sources.length){let i=f.symlinksToJSON(),S=await f.promises.glob("**",{cwd:"/",onlyFiles:!0});for(let t of S){let o=await f.promises.readFile(String(t),{includeConflicts:!0}),c=o[0];if(o.length>1)if(e.posix.extname(String(t))===".json"){console.warn(`'${t}' returned multiple files at the same location. Since the files were JSON dot files, they were merged using \`deepmerge\`.`);let a=o.map(m=>JSON.parse(String(m)));c=Buffer.from(JSON.stringify(k(a[0],a[1])))}else throw new Error(`'${t}' 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 n.promises.mkdir(e.dirname(e.join(s,String(t))),{recursive:!0}),await n.promises.writeFile(e.join(s,String(t)),c)}let x=process.cwd();for(let t in i)if(!t.startsWith("/.tags")){for(let{target:o}of i[t])if(!o.startsWith("/.tags")){await h.ensureDir(e.join(s,e.dirname(t)));try{!!await n.promises.stat(e.join(s,t))&&(console.error(new Error(`Symlink at '${e.join(s,t)}' already exists. Aborting build.`)),process.exit(1))}catch{let c=e.join(s,o),a=e.join(s,t),m=e.basename(a),j=e.relative(e.dirname(a),c);process.chdir(e.dirname(a)),n.existsSync(m)&&n.unlinkSync(m),await n.promises.symlink(j,m)}}}process.chdir(x),console.log(`[Mosaic] filesystem for ${Array.isArray(p)?p.length:r.sources.length} source(s) written to disk at '${s}'`),l.stop()}}catch(i){console.error(i),process.exit(1)}})}export{F as a};
|
|
@@ -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.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as e}from"./chunk-J73DKLHI.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.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function serve(config: any, port: any, scope: any): Promise<void>;
|
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
|
+
export default function uploadS3Snapshot(targetDir: any): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-P3RXN7HU.mjs";import"./chunk-AY5WSHSM.mjs";export{a as default};
|
|
@@ -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 @@
|
|
|
1
|
+
import{a}from"./chunk-VIYGD5XX.mjs";import"./chunk-AY5WSHSM.mjs";export{a as updateTraceFile};
|
package/package.json
CHANGED
|
@@ -1,30 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.41",
|
|
4
4
|
"author": "",
|
|
5
5
|
"description": "Mosaic command line scripts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"main": "./dist/index.
|
|
7
|
+
"main": "./dist/index.mjs",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"node": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
8
16
|
"engines": {
|
|
9
|
-
"node": ">=
|
|
17
|
+
"node": ">=16.10.0 || >=18.0.0"
|
|
10
18
|
},
|
|
11
19
|
"bin": {
|
|
12
|
-
"mosaic": "./dist/index.
|
|
20
|
+
"mosaic": "./dist/index.mjs"
|
|
13
21
|
},
|
|
14
22
|
"files": [
|
|
15
23
|
"dist"
|
|
16
24
|
],
|
|
17
25
|
"scripts": {
|
|
18
|
-
"build": "
|
|
19
|
-
"
|
|
26
|
+
"build": "npm-run-all --parallel build:*",
|
|
27
|
+
"build:types": "tsc",
|
|
28
|
+
"build:cli": "node ./scripts/bundle.js",
|
|
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",
|
|
32
|
+
"lint": "eslint --ignore-pattern \"**/__tests__/**\""
|
|
20
33
|
},
|
|
21
34
|
"repository": {
|
|
22
35
|
"type": "git",
|
|
23
|
-
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
36
|
+
"url": "git@github.com:jpmorganchase/mosaic.git",
|
|
37
|
+
"directory": "packages/cli"
|
|
24
38
|
},
|
|
25
39
|
"devDependencies": {
|
|
26
|
-
"@jpmorganchase/mosaic-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
40
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.41",
|
|
41
|
+
"esbuild": "0.14.35",
|
|
42
|
+
"esbuild-node-externals": "^1.0.2",
|
|
43
|
+
"fast-glob": "^3.2.7"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@jpmorganchase/mosaic-core": "^0.1.0-beta.41",
|
|
47
|
+
"@jpmorganchase/mosaic-plugins": "^0.1.0-beta.41",
|
|
48
|
+
"@jpmorganchase/mosaic-standard-generator": "^0.1.0-beta.41",
|
|
49
|
+
"@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.41",
|
|
50
|
+
"@aws-sdk/client-s3": "^3.359.0",
|
|
51
|
+
"commander": "^9.4.1",
|
|
52
|
+
"cors": "^2.8.5",
|
|
53
|
+
"deepmerge": "^4.2.2",
|
|
54
|
+
"express": "^4.18.2",
|
|
55
|
+
"fs-extra": "^10.1.0",
|
|
56
|
+
"globby": "^13.1.3",
|
|
57
|
+
"mkdirp": "^1.0.4"
|
|
29
58
|
}
|
|
30
|
-
}
|
|
59
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# @jpmorganchase/mosaic-cli
|
|
2
|
-
|
|
3
|
-
## 0.1.0-beta.4
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- bd285df: added dist to package.json
|
|
8
|
-
|
|
9
|
-
## 0.1.0-beta.3
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- 457df5e: switch to public package
|
|
14
|
-
|
|
15
|
-
## 0.1.0-beta.2
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
20
|
-
|
|
21
|
-
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
|
22
|
-
|
|
23
|
-
- 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
|
|
24
|
-
|
|
25
|
-
## 0.1.0
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
30
|
-
|
|
31
|
-
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
package/dist/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/dist/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/dist/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
|
-
};
|