@merkur/cli 0.36.4 → 0.37.0
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/bin/merkur.mjs +88 -20
- package/lib/server.cjs +4 -4
- package/lib/server.mjs +4 -4
- package/package.json +3 -2
- package/src/CLIConfig.mjs +3 -1
- package/src/buildConfig.mjs +14 -5
- package/src/commands/constant.mjs +1 -0
- package/src/commands/custom.mjs +63 -0
- package/src/commands/test.mjs +5 -5
- package/src/devServer.mjs +8 -4
- package/src/merkurConfig.mjs +35 -11
- package/src/plugins/aliasPlugin.mjs +26 -0
- package/src/plugins/devPlugin.mjs +8 -1
- package/src/plugins/excludeVendorsFromSourceMapPlugin.mjs +19 -0
- package/src/plugins/metaPlugin.mjs +4 -1
- package/src/runTask.mjs +20 -1
- package/src/taskConfig.mjs +2 -0
- package/src/templates/body.ejs +4 -16
- package/src/templates/footer.ejs +25 -0
- package/src/websocket.mjs +0 -1
- package/types.d.ts +6 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createLogger } from '../logger.mjs';
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export function aliasPlugin({ definition, cliConfig }) {
|
|
6
|
+
const { projectFolder } = cliConfig;
|
|
7
|
+
const logger = createLogger('aliasPlugin', cliConfig);
|
|
8
|
+
return {
|
|
9
|
+
name: 'aliasPlugin',
|
|
10
|
+
setup(build) {
|
|
11
|
+
logger.debug(`Setup plugin for "${chalk.cyan(definition.name)}" task.`);
|
|
12
|
+
|
|
13
|
+
build.onResolve({ filter: /^@\// }, async (args) => {
|
|
14
|
+
const result = await build.resolve(args.path.replace(/^@\//, `./`), {
|
|
15
|
+
kind: 'import-statement',
|
|
16
|
+
resolveDir: `${projectFolder}/src/`,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (result.errors.length > 0) {
|
|
20
|
+
return { errors: result.errors };
|
|
21
|
+
}
|
|
22
|
+
return { path: result.path };
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -72,7 +72,14 @@ export function devPlugin({ definition, merkurConfig, cliConfig }) {
|
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
client.on('open', function open() {
|
|
75
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
merkurConfig.HMR &&
|
|
77
|
+
!(
|
|
78
|
+
cliConfig.writeToDisk &&
|
|
79
|
+
changed.length === 0 &&
|
|
80
|
+
errors.length === 0
|
|
81
|
+
)
|
|
82
|
+
) {
|
|
76
83
|
client.send(
|
|
77
84
|
JSON.stringify({
|
|
78
85
|
to: 'browser',
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
export function excludeVendorsFromSourceMapPlugin() {
|
|
4
|
+
return {
|
|
5
|
+
name: 'excludeVendorsFromSourceMapPlugin',
|
|
6
|
+
setup(build) {
|
|
7
|
+
build.onLoad({ filter: /node_modules/ }, async (args) => {
|
|
8
|
+
const contents = await fs.readFile(args.path, { encoding: 'utf8' });
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
contents:
|
|
12
|
+
contents +
|
|
13
|
+
'\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
|
|
14
|
+
loader: 'default',
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
|
|
3
4
|
import { createLogger } from '../logger.mjs';
|
|
4
5
|
import { time } from '../utils.mjs';
|
|
@@ -31,7 +32,9 @@ export function metaPlugin({ definition, config, cliConfig }) {
|
|
|
31
32
|
|
|
32
33
|
metaInformation = await Promise.all(
|
|
33
34
|
generatedFiles.map(async (file) => {
|
|
34
|
-
const stat = await fs.stat(
|
|
35
|
+
const stat = await fs.stat(
|
|
36
|
+
path.resolve(`${projectFolder}/${file}`),
|
|
37
|
+
);
|
|
35
38
|
|
|
36
39
|
return { stat, file };
|
|
37
40
|
}),
|
package/src/runTask.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
|
|
1
3
|
import esbuild from 'esbuild';
|
|
4
|
+
import { createLogger } from './logger.mjs';
|
|
2
5
|
|
|
3
|
-
export async function runTask({ cliConfig, build }) {
|
|
6
|
+
export async function runTask({ cliConfig, build, config }) {
|
|
7
|
+
const logger = createLogger(undefined, cliConfig);
|
|
4
8
|
const { watch } = cliConfig;
|
|
5
9
|
|
|
6
10
|
//es6 === es2015, es9 === es2018, es11 === es2020 es13 ===es2022
|
|
@@ -9,6 +13,21 @@ export async function runTask({ cliConfig, build }) {
|
|
|
9
13
|
? esbuild.context(build)
|
|
10
14
|
: esbuild.build(build));
|
|
11
15
|
|
|
16
|
+
if (config.analyze && result.metafile) {
|
|
17
|
+
logger.log(
|
|
18
|
+
await esbuild.analyzeMetafile(result.metafile, {
|
|
19
|
+
verbose: cliConfig.verbose,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (build.outdir) {
|
|
24
|
+
await fs.writeFile(
|
|
25
|
+
`${build.outdir}/${build.entryNames ?? config.name}.meta.json`,
|
|
26
|
+
JSON.stringify(result.metafile),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
if (watch) {
|
|
13
32
|
await result.watch();
|
|
14
33
|
}
|
package/src/taskConfig.mjs
CHANGED
|
@@ -9,6 +9,8 @@ export async function createTaskConfig({
|
|
|
9
9
|
config: {
|
|
10
10
|
isServer: definition?.build?.platform === 'node',
|
|
11
11
|
writeToDisk: definition?.build?.write ?? cliConfig.writeToDisk,
|
|
12
|
+
sourcemap: definition?.build?.sourcemap ?? cliConfig.sourcemap,
|
|
13
|
+
analyze: definition?.build?.metafile ?? cliConfig.analyze,
|
|
12
14
|
...definition.config,
|
|
13
15
|
},
|
|
14
16
|
definition,
|
package/src/templates/body.ejs
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
<% if(widgetProperties?.slot?.headline?.html){ %>
|
|
2
|
-
<div class="
|
|
3
|
-
|
|
2
|
+
<div class="<%= (widgetProperties?.slot?.headline?.containerSelector ?? 'merkur-headline').replace('.', '') %>">
|
|
3
|
+
<%- widgetProperties?.slot?.headline?.html %>
|
|
4
|
+
</div>
|
|
4
5
|
<% } %>
|
|
5
|
-
<div class="merkur-
|
|
6
|
-
<script>
|
|
7
|
-
window.addEventListener('load', function () {
|
|
8
|
-
__merkur__.create(<%- escapeToJSON(widgetProperties) %>)
|
|
9
|
-
.then(function (widget) {
|
|
10
|
-
widget.containerSelector = '.merkur-view';
|
|
11
|
-
if (widget?.slot?.headline) {
|
|
12
|
-
widget.slot.headline.containerSelector = '.headline-view';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
widget.mount();
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
</script>
|
|
6
|
+
<div class="<%= (widgetProperties?.containerSelector ?? 'merkur-main').replace('.', '') %>"><%- html %></div>
|
package/src/templates/footer.ejs
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
window.addEventListener('load', function () {
|
|
3
|
+
__merkur__.create(<%- escapeToJSON(widgetProperties) %>)
|
|
4
|
+
.then(function (widget) {
|
|
5
|
+
widget.containerSelector = widget.containerSelector ?? '.merkur-main';
|
|
6
|
+
|
|
7
|
+
if (widget.slot && Object.keys(widget.slot).length > 0) {
|
|
8
|
+
Object.keys(widget.slot).forEach(function (slotName) {
|
|
9
|
+
widget.slot[slotName].containerSelector = widget.slot[slotName].containerSelector ?? '.merkur-' + slotName;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// support for router plugin
|
|
14
|
+
if (widget.router) {
|
|
15
|
+
widget.on('@merkur/plugin-router.redirect', function (_, url) {
|
|
16
|
+
var parsedUrl = new URL(url.url);
|
|
17
|
+
window.location = parsedUrl.href;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// mount widget to DOM
|
|
22
|
+
widget.mount();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
</script>
|
package/src/websocket.mjs
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
2
|
import type { Request, Response } from '@types/express';
|
|
3
|
+
import type { CorsOptions } from '@types/cors';
|
|
3
4
|
|
|
4
5
|
export interface CLIConfig {
|
|
5
6
|
environment: string;
|
|
@@ -30,6 +31,7 @@ export type Extend =
|
|
|
30
31
|
|
|
31
32
|
export interface Task {
|
|
32
33
|
name: 'es13' | 'es9' | 'node' | string;
|
|
34
|
+
folder: 'es13' | 'es9' | string;
|
|
33
35
|
build: BuildOptions;
|
|
34
36
|
[key: string]: any;
|
|
35
37
|
}
|
|
@@ -46,6 +48,7 @@ export interface DevServer {
|
|
|
46
48
|
export interface Playground {
|
|
47
49
|
template: string;
|
|
48
50
|
templateFolder: string;
|
|
51
|
+
serverTemplateFolder: string;
|
|
49
52
|
path: string;
|
|
50
53
|
widgetHandler(req: Request, res: Response): Record<string, unknown>;
|
|
51
54
|
widgetParams(req: Request): URLSearchParams;
|
|
@@ -66,6 +69,9 @@ export interface WidgetServer {
|
|
|
66
69
|
staticPath: string;
|
|
67
70
|
buildFolder: string;
|
|
68
71
|
clusters: number;
|
|
72
|
+
cors: {
|
|
73
|
+
options: CorsOptions;
|
|
74
|
+
};
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
export interface Constant {
|