@merkur/cli 0.43.0 → 0.44.0-rc.2
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/README.md +30 -0
- package/bin/merkur.mjs +61 -27
- package/lib/index.cjs +6 -6
- package/lib/index.mjs +6 -6
- package/package.json +2 -2
- package/src/CLIConfig.mjs +15 -12
- package/src/clearBuildFolder.mjs +6 -2
- package/src/commands/buildPlayground.mjs +169 -0
- package/src/commands/constant.mjs +1 -0
- package/src/handleExit.mjs +24 -20
- package/src/logger.mjs +15 -3
- package/src/widgetServer.mjs +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,36 @@ Contribute to this project via [Pull-Requests](https://github.com/mjancarik/merk
|
|
|
40
40
|
|
|
41
41
|
We are following [Conventional Commits Specification](https://www.conventionalcommits.org/en/v1.0.0/#summary). To simplify the commit process, you can use `npm run commit` command. It opens an interactive interface, which should help you with commit message composition.
|
|
42
42
|
|
|
43
|
+
### Release
|
|
44
|
+
|
|
45
|
+
To release a version you must have the right permissions, please contact one of the repo maintainers.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#### Regular version release
|
|
49
|
+
|
|
50
|
+
To do a regular release, in the root of the monorepo run:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
npm run release
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### RC (preversion) release
|
|
57
|
+
|
|
58
|
+
1. From the specific package directory, use this `lerna version` command to bump package versions:
|
|
59
|
+
```
|
|
60
|
+
npx lerna version <preminor | prepatch | prerelease> --no-git-tag-version --no-push
|
|
61
|
+
// prerelease increments the pre* version's last number, e.g. v0.44.0-rc.0 => v0.44.0-rc.1
|
|
62
|
+
```
|
|
63
|
+
2. restore all files not related to the package you intend to release (the whole lerna repo, `@merkur/create-widget`, other dependent packages).
|
|
64
|
+
3. Commit the changes.
|
|
65
|
+
4. Tag the commit with the version (e.g. `v0.44.0-rc.0`).
|
|
66
|
+
5. Push the commit to the repo.
|
|
67
|
+
6. Push the tag to the repo: `git push origin tag <tagname>` (e.g. `git push origin tag v0.44.0-rc.0`).
|
|
68
|
+
|
|
69
|
+
The packages are released from a GitHub Action that is triggered when a new version tag is pushed to the repository.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
43
73
|
Thank you to all the people who already contributed to Merkur!
|
|
44
74
|
|
|
45
75
|
<a href="https://github.com/mjancarik/merkur/graphs/contributors">
|
package/bin/merkur.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Command, Option, Argument } from 'commander';
|
|
3
3
|
import { dev } from '../src/commands/dev.mjs';
|
|
4
4
|
import { build } from '../src/commands/build.mjs';
|
|
5
|
+
import { buildPlayground } from '../src/commands/buildPlayground.mjs';
|
|
5
6
|
import { start } from '../src/commands/start.mjs';
|
|
6
7
|
import { test } from '../src/commands/test.mjs';
|
|
7
8
|
import { custom, CUSTOM_PART } from '../src/commands/custom.mjs';
|
|
@@ -16,21 +17,24 @@ import packageFile from '../package.json' with { type: 'json' };
|
|
|
16
17
|
|
|
17
18
|
const program = new Command();
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const analyzeOption = new Option('--analyze', 'Analyze bundle.');
|
|
21
|
+
const buildFolderOption = new Option('--buildFolder <string>', 'Build folder.');
|
|
22
|
+
const devServerPortOption = new Option('--devServerPort <number>', 'Dev server port.');
|
|
23
|
+
const hasRunDevServerOption = new Option('--hasRunDevServer', 'Flag for starting dev server');
|
|
24
|
+
const hasRunWidgetServerOption = new Option('--hasRunWidgetServer', 'Flag for starting widget server');
|
|
25
|
+
const inspectOption = new Option('--inspect', 'Debugging widget server');
|
|
22
26
|
const outputFilesOption = new Option('--outFile <string>', 'Server out file configuration in es-build.');
|
|
23
27
|
const portOption = new Option('--port <number>', 'Widget server port.');
|
|
24
|
-
const devServerPortOption = new Option('--devServerPort <number>', 'Dev server port.');
|
|
25
28
|
const projectFolderOption = new Option('--projectFolder <string>', 'Project folder.');
|
|
26
|
-
const
|
|
29
|
+
const quietOption = new Option('--quiet', 'Hide all logs except errors.');
|
|
30
|
+
const runTasksOption = new Option('--runTasks [runTasks...]', 'Run only defined tasks.');
|
|
31
|
+
const silentOption = new Option('--silent', 'Hide all logs.');
|
|
32
|
+
const sourcemapOption = new Option('--sourcemap', 'Generate sourcemap.');
|
|
27
33
|
const staticFolderOption = new Option('--staticFolder <string>', 'Static folder.');
|
|
28
34
|
const staticPathOption = new Option('--staticPath <string>', 'The static path for dev server and widget server.');
|
|
29
|
-
const
|
|
30
|
-
const hasRunWidgetServerOption = new Option('--hasRunWidgetServer', 'Flag for starting widget server');
|
|
31
|
-
const inspectOption = new Option('--inspect', 'Debugging widget server');
|
|
35
|
+
const staticPlaygroundOption = new Option('--staticPlayground <string>', 'Static playground folder.');
|
|
32
36
|
const verboseOption = new Option('--verbose', 'Verbose mode which show debug information.');
|
|
33
|
-
const
|
|
37
|
+
const writeToDiskOption = new Option('--writeToDisk', 'Write built files to disk.');
|
|
34
38
|
|
|
35
39
|
program
|
|
36
40
|
.name('merkur')
|
|
@@ -39,20 +43,22 @@ program
|
|
|
39
43
|
|
|
40
44
|
program.command(COMMAND_NAME.DEV)
|
|
41
45
|
.description('Dev command')
|
|
42
|
-
.addOption(
|
|
43
|
-
.addOption(
|
|
44
|
-
.addOption(
|
|
46
|
+
.addOption(buildFolderOption)
|
|
47
|
+
.addOption(devServerPortOption)
|
|
48
|
+
.addOption(hasRunDevServerOption)
|
|
49
|
+
.addOption(hasRunWidgetServerOption)
|
|
50
|
+
.addOption(inspectOption)
|
|
45
51
|
.addOption(outputFilesOption)
|
|
46
52
|
.addOption(portOption)
|
|
47
|
-
.addOption(devServerPortOption)
|
|
48
53
|
.addOption(projectFolderOption)
|
|
49
|
-
.addOption(
|
|
54
|
+
.addOption(quietOption)
|
|
55
|
+
.addOption(runTasksOption)
|
|
56
|
+
.addOption(silentOption)
|
|
57
|
+
.addOption(sourcemapOption)
|
|
50
58
|
.addOption(staticFolderOption)
|
|
51
59
|
.addOption(staticPathOption)
|
|
52
|
-
.addOption(hasRunDevServerOption)
|
|
53
|
-
.addOption(hasRunWidgetServerOption)
|
|
54
|
-
.addOption(inspectOption)
|
|
55
60
|
.addOption(verboseOption)
|
|
61
|
+
.addOption(writeToDiskOption)
|
|
56
62
|
.action(async (options, cmd) => {
|
|
57
63
|
const args = {
|
|
58
64
|
...{
|
|
@@ -73,15 +79,17 @@ program.command(COMMAND_NAME.DEV)
|
|
|
73
79
|
program
|
|
74
80
|
.command(COMMAND_NAME.BUILD)
|
|
75
81
|
.description('Build command')
|
|
76
|
-
.addOption(
|
|
77
|
-
.addOption(
|
|
78
|
-
.addOption(runTasksOption)
|
|
82
|
+
.addOption(analyzeOption)
|
|
83
|
+
.addOption(buildFolderOption)
|
|
79
84
|
.addOption(outputFilesOption)
|
|
80
85
|
.addOption(projectFolderOption)
|
|
81
|
-
.addOption(
|
|
86
|
+
.addOption(quietOption)
|
|
87
|
+
.addOption(runTasksOption)
|
|
88
|
+
.addOption(silentOption)
|
|
89
|
+
.addOption(sourcemapOption)
|
|
82
90
|
.addOption(staticFolderOption)
|
|
83
|
-
.addOption(analyzeOption)
|
|
84
91
|
.addOption(verboseOption)
|
|
92
|
+
.addOption(writeToDiskOption)
|
|
85
93
|
.action(async (options, cmd) => {
|
|
86
94
|
const args = {
|
|
87
95
|
...{ writeToDisk: true, watch: false, forceLegacy: true }, ...cmd.optsWithGlobals(), ...options
|
|
@@ -91,18 +99,40 @@ program
|
|
|
91
99
|
await build({ args, command: COMMAND_NAME.BUILD });
|
|
92
100
|
});
|
|
93
101
|
|
|
102
|
+
program
|
|
103
|
+
.command(COMMAND_NAME.BUILD_PLAYGROUND)
|
|
104
|
+
.addOption(buildFolderOption)
|
|
105
|
+
.addOption(hasRunWidgetServerOption)
|
|
106
|
+
.addOption(quietOption)
|
|
107
|
+
.addOption(silentOption)
|
|
108
|
+
.addOption(staticPlaygroundOption)
|
|
109
|
+
.addOption(verboseOption)
|
|
110
|
+
.description('Build a static version of the widget playground')
|
|
111
|
+
.action(async (options, cmd) => {
|
|
112
|
+
const args = {
|
|
113
|
+
...{ writeToDisk: true, watch: false, hasRunWidgetServer: true, hasRunDevServer: true },
|
|
114
|
+
...cmd.optsWithGlobals(),
|
|
115
|
+
...options,
|
|
116
|
+
};
|
|
117
|
+
process.env.NODE_ENV = process.env.NODE_ENV ?? 'production';
|
|
118
|
+
|
|
119
|
+
await buildPlayground({ args, command: COMMAND_NAME.BUILD_PLAYGROUND });
|
|
120
|
+
});
|
|
121
|
+
|
|
94
122
|
program
|
|
95
123
|
.command(COMMAND_NAME.START)
|
|
96
124
|
.description('Start widget server')
|
|
97
|
-
.addOption(portOption)
|
|
98
|
-
.addOption(devServerPortOption)
|
|
99
|
-
.addOption(projectFolderOption)
|
|
100
125
|
.addOption(buildFolderOption)
|
|
101
|
-
.addOption(
|
|
102
|
-
.addOption(staticPathOption)
|
|
126
|
+
.addOption(devServerPortOption)
|
|
103
127
|
.addOption(hasRunDevServerOption)
|
|
104
128
|
.addOption(hasRunWidgetServerOption)
|
|
105
129
|
.addOption(inspectOption)
|
|
130
|
+
.addOption(portOption)
|
|
131
|
+
.addOption(projectFolderOption)
|
|
132
|
+
.addOption(quietOption)
|
|
133
|
+
.addOption(silentOption)
|
|
134
|
+
.addOption(staticFolderOption)
|
|
135
|
+
.addOption(staticPathOption)
|
|
106
136
|
.addOption(verboseOption)
|
|
107
137
|
.action(async (options, cmd) => {
|
|
108
138
|
const args = {
|
|
@@ -116,6 +146,8 @@ program
|
|
|
116
146
|
program
|
|
117
147
|
.command(COMMAND_NAME.TEST)
|
|
118
148
|
.description('Test widget')
|
|
149
|
+
.addOption(quietOption)
|
|
150
|
+
.addOption(silentOption)
|
|
119
151
|
.allowUnknownOption()
|
|
120
152
|
.allowExcessArguments()
|
|
121
153
|
.action(async (options, cmd) => {
|
|
@@ -132,6 +164,8 @@ program
|
|
|
132
164
|
.command(COMMAND_NAME.CUSTOM)
|
|
133
165
|
.description('Customize template')
|
|
134
166
|
.addArgument(new Argument('<part>', 'custom part').choices(Object.values(CUSTOM_PART)))
|
|
167
|
+
.addOption(quietOption)
|
|
168
|
+
.addOption(silentOption)
|
|
135
169
|
.addOption(verboseOption)
|
|
136
170
|
.allowUnknownOption()
|
|
137
171
|
.allowExcessArguments()
|
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Y=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of U(e))!K.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(o=D(e,n))||o.enumerable});return r};var R=(r,e,t)=>(t=r!=null?Y(V(r)):{},B(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),
|
|
1
|
+
"use strict";var Y=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of U(e))!K.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(o=D(e,n))||o.enumerable});return r};var R=(r,e,t)=>(t=r!=null?Y(V(r)):{},B(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),q=r=>B(m({},"__esModule",{value:!0}),r);var ce={};W(ce,{addServerConfig:()=>k,createLogger:()=>G});module.exports=q(ce);var M=(r=0)=>e=>`\x1B[${e+r}m`,I=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,S=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},ae=Object.keys(i.modifier),H=Object.keys(i.color),z=Object.keys(i.bgColor),fe=[...H,...z];function J(){let r=new Map;for(let[e,t]of Object.entries(i)){for(let[o,n]of Object.entries(t))i[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=i[o],r.set(n[0],n[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="\x1B[39m",i.bgColor.close="\x1B[49m",i.color.ansi=M(),i.color.ansi256=I(),i.color.ansi16m=S(),i.bgColor.ansi=M(10),i.bgColor.ansi256=I(10),i.bgColor.ansi16m=S(10),Object.defineProperties(i,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(l=>l+l).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>i.rgbToAnsi256(...i.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,o,n;if(e>=232)t=((e-232)*10+8)/255,o=t,n=t;else{e-=16;let N=e%36;t=Math.floor(e/36)/5,o=Math.floor(N/6)/5,n=N%6/5}let l=Math.max(t,o,n)*2;if(l===0)return 30;let c=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(t));return l===2&&(c+=60),c},enumerable:!1},rgbToAnsi:{value:(e,t,o)=>i.ansi256ToAnsi(i.rgbToAnsi256(e,t,o)),enumerable:!1},hexToAnsi:{value:e=>i.ansi256ToAnsi(i.hexToAnsi256(e)),enumerable:!1}}),i}var Q=J(),a=Q;var O=R(require("node:process"),1),F=R(require("node:os"),1),y=R(require("node:tty"),1);function u(r,e=globalThis.Deno?globalThis.Deno.args:O.default.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",o=e.indexOf(t+r),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}var{env:s}=O.default,g;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?g=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(g=1);function X(){if("FORCE_COLOR"in s)return s.FORCE_COLOR==="true"?1:s.FORCE_COLOR==="false"?0:s.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(s.FORCE_COLOR,10),3)}function Z(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function ee(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let o=X();o!==void 0&&(g=o);let n=t?g:o;if(n===0)return 0;if(t){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in s&&"AGENT_NAME"in s)return 1;if(r&&!e&&n===void 0)return 0;let l=n||0;if(s.TERM==="dumb")return l;if(O.default.platform==="win32"){let c=F.default.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in s)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in s)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in s)||s.CI_NAME==="codeship"?1:l;if("TEAMCITY_VERSION"in s)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(s.TEAMCITY_VERSION)?1:0;if(s.COLORTERM==="truecolor"||s.TERM==="xterm-kitty"||s.TERM==="xterm-ghostty"||s.TERM==="wezterm")return 3;if("TERM_PROGRAM"in s){let c=Number.parseInt((s.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(s.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(s.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(s.TERM)||"COLORTERM"in s?1:l}function v(r,e={}){let t=ee(r,{streamIsTTY:r&&r.isTTY,...e});return Z(t)}var re={stdout:v({isTTY:y.default.isatty(1)}),stderr:v({isTTY:y.default.isatty(2)})},_=re;function w(r,e,t){let o=r.indexOf(e);if(o===-1)return r;let n=e.length,l=0,c="";do c+=r.slice(l,o)+e+t,l=o+n,o=r.indexOf(e,l);while(o!==-1);return c+=r.slice(l),c}function j(r,e,t,o){let n=0,l="";do{let c=r[o-1]==="\r";l+=r.slice(n,c?o-1:o)+e+(c?`\r
|
|
2
2
|
`:`
|
|
3
3
|
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
-
`,n)}while(o!==-1);return
|
|
5
|
-
`);return
|
|
6
|
-
`)}info(e,t){this.#e("info",f.bold.cyan,e,t)}log(e,t){this.#e(null,f.bold.cyan,e,t)}debug(e,t){this.#
|
|
7
|
-
`)??"";this.#
|
|
4
|
+
`,n)}while(o!==-1);return l+=r.slice(n),l}var{stdout:L,stderr:$}=_,C=Symbol("GENERATOR"),h=Symbol("STYLER"),d=Symbol("IS_EMPTY"),P=["ansi","ansi","ansi256","ansi16m"],b=Object.create(null),te=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=L?L.level:0;r.level=e.level===void 0?t:e.level};var oe=r=>{let e=(...t)=>t.join(" ");return te(e,r),Object.setPrototypeOf(e,p.prototype),e};function p(r){return oe(r)}Object.setPrototypeOf(p.prototype,Function.prototype);for(let[r,e]of Object.entries(a))b[r]={get(){let t=T(this,E(e.open,e.close,this[h]),this[d]);return Object.defineProperty(this,r,{value:t}),t}};b.visible={get(){let r=T(this,this[h],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var A=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?a[t].ansi16m(...o):e==="ansi256"?a[t].ansi256(a.rgbToAnsi256(...o)):a[t].ansi(a.rgbToAnsi(...o)):r==="hex"?A("rgb",e,t,...a.hexToRgb(...o)):a[t][r](...o),ne=["rgb","hex","ansi256"];for(let r of ne){b[r]={get(){let{level:t}=this;return function(...o){let n=E(A(r,P[t],"color",...o),a.color.close,this[h]);return T(this,n,this[d])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);b[e]={get(){let{level:t}=this;return function(...o){let n=E(A(r,P[t],"bgColor",...o),a.bgColor.close,this[h]);return T(this,n,this[d])}}}}var ie=Object.defineProperties(()=>{},{...b,level:{enumerable:!0,get(){return this[C].level},set(r){this[C].level=r}}}),E=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},T=(r,e,t)=>{let o=(...n)=>se(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,ie),o[C]=r,o[h]=e,o[d]=t,o},se=(r,e)=>{if(r.level<=0||!e)return r[d]?"":e;let t=r[h];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=w(e,t.close,t.open),t=t.parent;let l=e.indexOf(`
|
|
5
|
+
`);return l!==-1&&(e=j(e,n,o,l)),o+e+n};Object.defineProperties(p.prototype,b);var le=p(),Oe=p({level:$?$.level:0});var f=le;var x=class{#t=null;#e=null;constructor(e,t){this.#t=e,this.#e=t}#r(e,t,o){e&&process.stdout.write(t(`${e}: ${this.#t?`(${this.#t}) `:""}`));try{o=o??typeof o,process.stdout.write(o)}catch(n){console.error(n)}process.stdout.write(`
|
|
6
|
+
`)}info(e,t){this.#e?.quiet||this.#e?.silent||this.#r("info",f.bold.cyan,e,t)}log(e,t){this.#e?.quiet||this.#e?.silent||this.#r(null,f.bold.cyan,e,t)}debug(e,t){this.#e?.verbose&&this.#r("debug",f.bold.cyan,e,t)}warn(e,t){this.#e?.quiet||this.#e?.silent||this.#r("warn",f.bold.yellow,e,t)}error(e,t){if(!this.#e?.silent)if(e instanceof Error){let[o,...n]=e.stack?.split(`
|
|
7
|
+
`)??"";this.#r("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,t),process.stdout.write(`
|
|
8
8
|
${f.gray(n.join(`
|
|
9
9
|
`))}
|
|
10
|
-
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#
|
|
10
|
+
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#r("error",f.bold.red,e,t)}};function G(r,e={}){return new x(r,e)}function k(r,{protocol:e,hostname:t,port:o}){e&&(r.protocol=e),o&&(r.port=o);let n=t??(o?r.host?.split(":")[0]:null);return n&&(r.host=`${n}:${r.port}`),r.protocol&&r.host&&(r.origin=new URL(`${r.protocol}//${r.host}`).origin),r}0&&(module.exports={addServerConfig,createLogger});
|
package/lib/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var E=(r=0)=>e=>`\x1B[${e+r}m`,x=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,N=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},X=Object.keys(i.modifier),j=Object.keys(i.color),L=Object.keys(i.bgColor),Z=[...j,...L];function $(){let r=new Map;for(let[e,t]of Object.entries(i)){for(let[o,n]of Object.entries(t))i[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=i[o],r.set(n[0],n[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="\x1B[39m",i.bgColor.close="\x1B[49m",i.color.ansi=E(),i.color.ansi256=x(),i.color.ansi16m=N(),i.bgColor.ansi=E(10),i.bgColor.ansi256=x(10),i.bgColor.ansi16m=N(10),Object.defineProperties(i,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(
|
|
1
|
+
var E=(r=0)=>e=>`\x1B[${e+r}m`,x=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,N=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},X=Object.keys(i.modifier),j=Object.keys(i.color),L=Object.keys(i.bgColor),Z=[...j,...L];function $(){let r=new Map;for(let[e,t]of Object.entries(i)){for(let[o,n]of Object.entries(t))i[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=i[o],r.set(n[0],n[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="\x1B[39m",i.bgColor.close="\x1B[49m",i.color.ansi=E(),i.color.ansi256=x(),i.color.ansi16m=N(),i.bgColor.ansi=E(10),i.bgColor.ansi256=x(10),i.bgColor.ansi16m=N(10),Object.defineProperties(i,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(l=>l+l).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>i.rgbToAnsi256(...i.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,o,n;if(e>=232)t=((e-232)*10+8)/255,o=t,n=t;else{e-=16;let A=e%36;t=Math.floor(e/36)/5,o=Math.floor(A/6)/5,n=A%6/5}let l=Math.max(t,o,n)*2;if(l===0)return 30;let c=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(t));return l===2&&(c+=60),c},enumerable:!1},rgbToAnsi:{value:(e,t,o)=>i.ansi256ToAnsi(i.rgbToAnsi256(e,t,o)),enumerable:!1},hexToAnsi:{value:e=>i.ansi256ToAnsi(i.hexToAnsi256(e)),enumerable:!1}}),i}var P=$(),a=P;import O from"node:process";import G from"node:os";import B from"node:tty";function u(r,e=globalThis.Deno?globalThis.Deno.args:O.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",o=e.indexOf(t+r),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}var{env:s}=O,m;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?m=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(m=1);function k(){if("FORCE_COLOR"in s)return s.FORCE_COLOR==="true"?1:s.FORCE_COLOR==="false"?0:s.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(s.FORCE_COLOR,10),3)}function Y(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function D(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let o=k();o!==void 0&&(m=o);let n=t?m:o;if(n===0)return 0;if(t){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in s&&"AGENT_NAME"in s)return 1;if(r&&!e&&n===void 0)return 0;let l=n||0;if(s.TERM==="dumb")return l;if(O.platform==="win32"){let c=G.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in s)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in s)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in s)||s.CI_NAME==="codeship"?1:l;if("TEAMCITY_VERSION"in s)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(s.TEAMCITY_VERSION)?1:0;if(s.COLORTERM==="truecolor"||s.TERM==="xterm-kitty"||s.TERM==="xterm-ghostty"||s.TERM==="wezterm")return 3;if("TERM_PROGRAM"in s){let c=Number.parseInt((s.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(s.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(s.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(s.TERM)||"COLORTERM"in s?1:l}function M(r,e={}){let t=D(r,{streamIsTTY:r&&r.isTTY,...e});return Y(t)}var U={stdout:M({isTTY:B.isatty(1)}),stderr:M({isTTY:B.isatty(2)})},I=U;function S(r,e,t){let o=r.indexOf(e);if(o===-1)return r;let n=e.length,l=0,c="";do c+=r.slice(l,o)+e+t,l=o+n,o=r.indexOf(e,l);while(o!==-1);return c+=r.slice(l),c}function v(r,e,t,o){let n=0,l="";do{let c=r[o-1]==="\r";l+=r.slice(n,c?o-1:o)+e+(c?`\r
|
|
2
2
|
`:`
|
|
3
3
|
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
-
`,n)}while(o!==-1);return
|
|
5
|
-
`);return
|
|
6
|
-
`)}info(e,t){this.#e("info",f.bold.cyan,e,t)}log(e,t){this.#e(null,f.bold.cyan,e,t)}debug(e,t){this.#
|
|
7
|
-
`)??"";this.#
|
|
4
|
+
`,n)}while(o!==-1);return l+=r.slice(n),l}var{stdout:F,stderr:_}=I,T=Symbol("GENERATOR"),h=Symbol("STYLER"),d=Symbol("IS_EMPTY"),w=["ansi","ansi","ansi256","ansi16m"],b=Object.create(null),V=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=F?F.level:0;r.level=e.level===void 0?t:e.level};var K=r=>{let e=(...t)=>t.join(" ");return V(e,r),Object.setPrototypeOf(e,p.prototype),e};function p(r){return K(r)}Object.setPrototypeOf(p.prototype,Function.prototype);for(let[r,e]of Object.entries(a))b[r]={get(){let t=g(this,y(e.open,e.close,this[h]),this[d]);return Object.defineProperty(this,r,{value:t}),t}};b.visible={get(){let r=g(this,this[h],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var R=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?a[t].ansi16m(...o):e==="ansi256"?a[t].ansi256(a.rgbToAnsi256(...o)):a[t].ansi(a.rgbToAnsi(...o)):r==="hex"?R("rgb",e,t,...a.hexToRgb(...o)):a[t][r](...o),W=["rgb","hex","ansi256"];for(let r of W){b[r]={get(){let{level:t}=this;return function(...o){let n=y(R(r,w[t],"color",...o),a.color.close,this[h]);return g(this,n,this[d])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);b[e]={get(){let{level:t}=this;return function(...o){let n=y(R(r,w[t],"bgColor",...o),a.bgColor.close,this[h]);return g(this,n,this[d])}}}}var q=Object.defineProperties(()=>{},{...b,level:{enumerable:!0,get(){return this[T].level},set(r){this[T].level=r}}}),y=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},g=(r,e,t)=>{let o=(...n)=>H(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,q),o[T]=r,o[h]=e,o[d]=t,o},H=(r,e)=>{if(r.level<=0||!e)return r[d]?"":e;let t=r[h];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=S(e,t.close,t.open),t=t.parent;let l=e.indexOf(`
|
|
5
|
+
`);return l!==-1&&(e=v(e,n,o,l)),o+e+n};Object.defineProperties(p.prototype,b);var z=p(),ue=p({level:_?_.level:0});var f=z;var C=class{#t=null;#e=null;constructor(e,t){this.#t=e,this.#e=t}#r(e,t,o){e&&process.stdout.write(t(`${e}: ${this.#t?`(${this.#t}) `:""}`));try{o=o??typeof o,process.stdout.write(o)}catch(n){console.error(n)}process.stdout.write(`
|
|
6
|
+
`)}info(e,t){this.#e?.quiet||this.#e?.silent||this.#r("info",f.bold.cyan,e,t)}log(e,t){this.#e?.quiet||this.#e?.silent||this.#r(null,f.bold.cyan,e,t)}debug(e,t){this.#e?.verbose&&this.#r("debug",f.bold.cyan,e,t)}warn(e,t){this.#e?.quiet||this.#e?.silent||this.#r("warn",f.bold.yellow,e,t)}error(e,t){if(!this.#e?.silent)if(e instanceof Error){let[o,...n]=e.stack?.split(`
|
|
7
|
+
`)??"";this.#r("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,t),process.stdout.write(`
|
|
8
8
|
${f.gray(n.join(`
|
|
9
9
|
`))}
|
|
10
|
-
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#
|
|
10
|
+
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#r("error",f.bold.red,e,t)}};function J(r,e={}){return new C(r,e)}function Q(r,{protocol:e,hostname:t,port:o}){e&&(r.protocol=e),o&&(r.port=o);let n=t??(o?r.host?.split(":")[0]:null);return n&&(r.host=`${n}:${r.port}`),r.protocol&&r.host&&(r.origin=new URL(`${r.protocol}//${r.host}`).origin),r}export{Q as addServerConfig,J as createLogger};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0-rc.2",
|
|
4
4
|
"description": "Merkur is tiny and extensible library for creating front-end microservices.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"merkur": "./bin/merkur.mjs"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": ">=20"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "f17c30471460f9d6281604580b915030f5a9e916"
|
|
69
69
|
}
|
package/src/CLIConfig.mjs
CHANGED
|
@@ -5,26 +5,29 @@ export async function createCLIConfig({ args, command } = {}) {
|
|
|
5
5
|
const isProduction = environment === 'production';
|
|
6
6
|
|
|
7
7
|
return {
|
|
8
|
+
analyze: args.analyze ?? false,
|
|
9
|
+
buildFolder: args?.buildFolder ?? './build',
|
|
10
|
+
cliFolder: import.meta.dirname,
|
|
11
|
+
command: command ?? 'unknown',
|
|
12
|
+
devServerPort: args?.devServerPort ?? 4445,
|
|
8
13
|
environment,
|
|
14
|
+
hasRunDevServer: args?.hasRunDevServer ?? false,
|
|
15
|
+
hasRunWidgetServer: args?.hasRunWidgetServer ?? false,
|
|
16
|
+
inspect: args.inspect ?? false,
|
|
9
17
|
isProduction,
|
|
10
|
-
command: command ?? 'unknown',
|
|
11
|
-
watch: args?.watch ?? !isProduction,
|
|
12
|
-
writeToDisk: args?.writeToDisk ?? isProduction,
|
|
13
|
-
sourcemap: args?.sourcemap ?? !isProduction,
|
|
14
18
|
outFile: args?.outFile ?? './build/widget.cjs',
|
|
15
19
|
port: args?.port ?? 4444,
|
|
16
|
-
runTasks: args?.runTasks ?? [],
|
|
17
|
-
devServerPort: args?.devServerPort ?? 4445,
|
|
18
20
|
projectFolder: args?.projectFolder ?? process.cwd(),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
quiet: args?.quiet ?? false,
|
|
22
|
+
runTasks: args?.runTasks ?? [],
|
|
23
|
+
silent: args?.silent ?? false,
|
|
24
|
+
sourcemap: args?.sourcemap ?? !isProduction,
|
|
21
25
|
staticFolder: args?.staticFolder ?? './build/static',
|
|
22
26
|
staticPath: args?.staticPath ?? '/static',
|
|
23
|
-
|
|
24
|
-
hasRunWidgetServer: args?.hasRunWidgetServer ?? false,
|
|
25
|
-
inspect: args.inspect ?? false,
|
|
26
|
-
analyze: args.analyze ?? false,
|
|
27
|
+
staticPlayground: args?.staticPlayground ?? './build-playground',
|
|
27
28
|
verbose: args.verbose ?? false,
|
|
29
|
+
watch: args?.watch ?? !isProduction,
|
|
30
|
+
writeToDisk: args?.writeToDisk ?? isProduction,
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
|
package/src/clearBuildFolder.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
export async function
|
|
3
|
+
export async function clearFolder(folderPath) {
|
|
4
4
|
try {
|
|
5
|
-
await rm(
|
|
5
|
+
await rm(folderPath, {
|
|
6
6
|
recursive: true,
|
|
7
7
|
force: true,
|
|
8
8
|
});
|
|
9
9
|
} catch {} //eslint-disable-line no-empty
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export async function clearBuildFolder({ merkurConfig }) {
|
|
13
|
+
await clearFolder(merkurConfig.widgetServer.buildFolder);
|
|
14
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createCommandConfig } from '../commandConfig.mjs';
|
|
2
|
+
import { runDevServer } from '../devServer.mjs';
|
|
3
|
+
import { runTask } from '../runTask.mjs';
|
|
4
|
+
import { runSocketServer } from '../websocket.mjs';
|
|
5
|
+
import { runWidgetServer } from '../widgetServer.mjs';
|
|
6
|
+
import { handleExit, killProcesses } from '../handleExit.mjs';
|
|
7
|
+
import { clearFolder, clearBuildFolder } from '../clearBuildFolder.mjs';
|
|
8
|
+
import { time } from '../utils.mjs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import fs from 'node:fs/promises';
|
|
12
|
+
import process from 'node:process';
|
|
13
|
+
import { createLogger } from '../logger.mjs';
|
|
14
|
+
|
|
15
|
+
function createServerTimer({ logger, cliConfig }) {
|
|
16
|
+
return function waitForServerReady(url, timeout = 10000, interval = 500) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
if (!url) {
|
|
19
|
+
reject('URL is required.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let fetchError;
|
|
23
|
+
const runTime = time();
|
|
24
|
+
logger.log(`Waiting for server at ${chalk.yellow(url)} to be ready...`);
|
|
25
|
+
|
|
26
|
+
const intervalId = setInterval(async () => {
|
|
27
|
+
const elapsed = runTime();
|
|
28
|
+
if (elapsed > timeout) {
|
|
29
|
+
clearInterval(intervalId);
|
|
30
|
+
const failureReason =
|
|
31
|
+
fetchError || '(unknown, possibly fetch timeout)';
|
|
32
|
+
reject(
|
|
33
|
+
`Timeout waiting for server at ${url}. Last fetch error: ${failureReason}`,
|
|
34
|
+
);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(url);
|
|
40
|
+
if (response.ok) {
|
|
41
|
+
clearInterval(intervalId);
|
|
42
|
+
resolve(true);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fetchError = cliConfig.verbose
|
|
46
|
+
? await response.text()
|
|
47
|
+
: `${response.status} ${response.statusText}`;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
fetchError = toString(err);
|
|
50
|
+
}
|
|
51
|
+
}, interval);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function buildPlayground({ args, command }) {
|
|
57
|
+
const { context, cliConfig, merkurConfig } = await createCommandConfig({
|
|
58
|
+
args,
|
|
59
|
+
command,
|
|
60
|
+
});
|
|
61
|
+
const logger = createLogger(null, cliConfig);
|
|
62
|
+
const waitForServerReady = createServerTimer({ logger, cliConfig });
|
|
63
|
+
|
|
64
|
+
const { staticPlayground, staticFolder } = cliConfig;
|
|
65
|
+
|
|
66
|
+
const childProcessCliConfig = { ...cliConfig, silent: !cliConfig.verbose };
|
|
67
|
+
|
|
68
|
+
// TODO maybe skip building tasks, to be used in CI where there's a separate build step?
|
|
69
|
+
|
|
70
|
+
await clearFolder(cliConfig.staticPlayground);
|
|
71
|
+
await clearBuildFolder({ merkurConfig, cliConfig: childProcessCliConfig });
|
|
72
|
+
|
|
73
|
+
logger.info(`Running build tasks`);
|
|
74
|
+
const task = await runTask({
|
|
75
|
+
merkurConfig,
|
|
76
|
+
cliConfig: childProcessCliConfig,
|
|
77
|
+
context,
|
|
78
|
+
});
|
|
79
|
+
await Promise.all(Object.values(task));
|
|
80
|
+
|
|
81
|
+
await handleExit({ context });
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
devServer: { origin: devServerOrigin },
|
|
85
|
+
playground: { path: playgroundPath },
|
|
86
|
+
widgetServer: { origin: widgetServerOrigin },
|
|
87
|
+
} = merkurConfig;
|
|
88
|
+
|
|
89
|
+
logger.info(`Starting servers`);
|
|
90
|
+
|
|
91
|
+
if (cliConfig.hasRunWidgetServer) {
|
|
92
|
+
await runWidgetServer({
|
|
93
|
+
merkurConfig,
|
|
94
|
+
cliConfig: childProcessCliConfig,
|
|
95
|
+
context,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const widgetServerUrl = path.join(widgetServerOrigin, '/widget');
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await waitForServerReady(widgetServerUrl);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
logger.error(chalk.red.bold(`x Widget server failed to start:`));
|
|
104
|
+
logger.error(chalk.red(err));
|
|
105
|
+
killProcesses({ context });
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await Promise.all([
|
|
111
|
+
runDevServer({ merkurConfig, cliConfig: childProcessCliConfig, context }),
|
|
112
|
+
runSocketServer({
|
|
113
|
+
merkurConfig,
|
|
114
|
+
cliConfig: childProcessCliConfig,
|
|
115
|
+
context,
|
|
116
|
+
}),
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
await waitForServerReady(devServerOrigin);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
logger.error(chalk.red.bold('x Dev server failed to start:'));
|
|
123
|
+
logger.error(chalk.red(err));
|
|
124
|
+
killProcesses({ context });
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const playgroundUrl = path.join(devServerOrigin, playgroundPath);
|
|
129
|
+
|
|
130
|
+
logger.info(`Building playground`);
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const response = await fetch(playgroundUrl);
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
throw new Error('Failed to fetch playground', response.body);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let playgroundHtml = await response.text();
|
|
139
|
+
|
|
140
|
+
playgroundHtml = playgroundHtml.replaceAll(devServerOrigin, '.');
|
|
141
|
+
playgroundHtml = playgroundHtml.replaceAll(widgetServerOrigin, `.`);
|
|
142
|
+
|
|
143
|
+
const absStaticFolderPath = path.resolve(process.cwd(), staticFolder);
|
|
144
|
+
const playgroundFolderPath = path.resolve(process.cwd(), staticPlayground);
|
|
145
|
+
|
|
146
|
+
await fs.mkdir(playgroundFolderPath, { recursive: true });
|
|
147
|
+
await Promise.all([
|
|
148
|
+
fs.writeFile(
|
|
149
|
+
path.join(playgroundFolderPath, 'index.html'),
|
|
150
|
+
playgroundHtml,
|
|
151
|
+
),
|
|
152
|
+
fs.cp(absStaticFolderPath, path.join(playgroundFolderPath, 'static'), {
|
|
153
|
+
recursive: true,
|
|
154
|
+
}),
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
logger.log(
|
|
158
|
+
chalk.green.bold('Playground built successfully in: ') +
|
|
159
|
+
chalk.green(playgroundFolderPath),
|
|
160
|
+
);
|
|
161
|
+
killProcesses({ context });
|
|
162
|
+
process.exit(0);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
logger.error(chalk.red.bold('x Failed to build static playground:'));
|
|
165
|
+
logger.error(chalk.red(err));
|
|
166
|
+
killProcesses({ context });
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/handleExit.mjs
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
|
|
3
|
-
export async function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
3
|
+
export async function killProcesses({ context }) {
|
|
4
|
+
Object.values(context.process).forEach((childProcess) => {
|
|
5
|
+
childProcess.kill('SIGTERM');
|
|
6
|
+
});
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
Object.values(context.task).forEach((task) => {
|
|
9
|
+
task.dispose();
|
|
10
|
+
});
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
12
|
+
await Promise.all(
|
|
13
|
+
Object.values(context.server).map((server) => {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
resolve();
|
|
17
|
+
}, 100);
|
|
18
|
+
server.close(() => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
resolve();
|
|
23
21
|
});
|
|
24
|
-
})
|
|
25
|
-
)
|
|
22
|
+
});
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function handleExit({ context }) {
|
|
28
|
+
const handleExit = async () => {
|
|
29
|
+
await killProcesses({ context });
|
|
26
30
|
|
|
27
31
|
process.exit(0);
|
|
28
32
|
};
|
package/src/logger.mjs
CHANGED
|
@@ -27,14 +27,18 @@ export class Logger {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
info(message, options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (this.#cliConfig?.quiet || this.#cliConfig?.silent) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
this.#log('info', chalk.bold.cyan, message, options);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
log(message, options) {
|
|
38
|
+
if (this.#cliConfig?.quiet || this.#cliConfig?.silent) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
this.#log(null, chalk.bold.cyan, message, options);
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -47,10 +51,18 @@ export class Logger {
|
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
warn(message, options) {
|
|
54
|
+
if (this.#cliConfig?.quiet || this.#cliConfig?.silent) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
this.#log('warn', chalk.bold.yellow, message, options);
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
error(message, options) {
|
|
62
|
+
if (this.#cliConfig?.silent) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
if (message instanceof Error) {
|
|
55
67
|
const [_, ...stackLines] = message.stack?.split('\n') ?? ''; //eslint-disable-line
|
|
56
68
|
|
package/src/widgetServer.mjs
CHANGED
|
@@ -32,7 +32,7 @@ export async function runWidgetServer({ merkurConfig, cliConfig, context }) {
|
|
|
32
32
|
MERKUR_CONFIG: JSON.stringify(merkurConfig),
|
|
33
33
|
CLI_CONFIG: JSON.stringify(cliConfig),
|
|
34
34
|
},
|
|
35
|
-
stdio: 'inherit',
|
|
35
|
+
stdio: cliConfig.silent || cliConfig.quiet ? 'pipe' : 'inherit',
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
server.on('spawn', () => {
|