@mochabug/adapt-builder 0.1.0 → 0.1.1
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/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface PluginBuildOptions {
|
|
|
26
26
|
}
|
|
27
27
|
type OptionalPluginBuildOptions = DeepPartialExcept<PluginBuildOptions, BuildOptions>;
|
|
28
28
|
export declare function build(opts?: OptionalPluginBuildOptions): Promise<void>;
|
|
29
|
+
export interface DevOptions {
|
|
30
|
+
port?: number;
|
|
31
|
+
src?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function dev(opts?: DevOptions): Promise<void>;
|
|
29
34
|
export declare function validateLoadServiceDefinition(basePath: string, srv: ServiceDefinition): Promise<void>;
|
|
30
35
|
export declare function buildServer(manifest: Manifest, vpathLookup: Record<string, string>, opts: PluginBuildOptions): Promise<void>;
|
|
31
36
|
export { CDN_URL_DEFAULT };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAA6B,MAAM,SAAS,CAAC;AAKlE,OAAO,EACL,eAAe,EAchB,MAAM,YAAY,CAAC;AAIpB,OAAO,EACL,QAAQ,EAET,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gEAAgE,CAAC;AAQnG,KAAK,iBAAiB,CAAC,CAAC,EAAE,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACpD,CAAC,GACD,CAAC,SAAS,QAAQ,GAClB,CAA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E,MAAM,CAAC,EACnC,IAAI,EAAE,kBAAkB,iBAuGzB;AAkTD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@craftamap/esbuild-plugin-html";
|
|
8
8
|
import Ajv from "ajv/dist/jtd.js";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
-
import { build as esbuild } from "esbuild";
|
|
10
|
+
import { context, build as esbuild } from "esbuild";
|
|
11
11
|
import { sync as glob } from "glob";
|
|
12
12
|
import fs4 from "node:fs";
|
|
13
13
|
import path4 from "node:path";
|
|
@@ -517,6 +517,167 @@ async function build(opts) {
|
|
|
517
517
|
await buildServer(manifest, pathLookup, initOpts);
|
|
518
518
|
console.log(chalk.bold.green("\n\u2728 Build completed successfully!\n"));
|
|
519
519
|
}
|
|
520
|
+
async function dev(opts) {
|
|
521
|
+
const port = opts?.port || 3e3;
|
|
522
|
+
const src = opts?.src || DEFAULT_SRC;
|
|
523
|
+
console.log(chalk.bold.cyan("\n\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"));
|
|
524
|
+
console.log(chalk.bold.cyan("\u2502 \u{1F525} Adapt Plugin Dev Server \u2502"));
|
|
525
|
+
console.log(chalk.bold.cyan("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n"));
|
|
526
|
+
const manifest = fromJsonString(
|
|
527
|
+
ManifestSchema,
|
|
528
|
+
fs4.readFileSync(MANIFEST_PATH, "utf8")
|
|
529
|
+
);
|
|
530
|
+
console.log(
|
|
531
|
+
chalk.dim("\u2502 ") + `Plugin: ${chalk.bold(
|
|
532
|
+
`${manifest.organization}/${manifest.name}`
|
|
533
|
+
)} ${chalk.dim(`v${manifest.version}`)}`
|
|
534
|
+
);
|
|
535
|
+
const pathLookup = {};
|
|
536
|
+
manifest.vertices = glob(path4.join(src, "**/vertex.json")).map((file) => {
|
|
537
|
+
const res = fromJsonString(VertexSchema, fs4.readFileSync(file, "utf8"));
|
|
538
|
+
pathLookup[res.name] = path4.dirname(file);
|
|
539
|
+
return res;
|
|
540
|
+
});
|
|
541
|
+
if (manifest.vertices.length === 0) {
|
|
542
|
+
console.log(chalk.yellow("\n\u26A0 No vertices found. Nothing to serve.\n"));
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const hasUI = (v) => fs4.existsSync(path4.join(pathLookup[v.name], "ui"));
|
|
546
|
+
const configVertices = manifest.vertices.filter(
|
|
547
|
+
(v) => Boolean(v.capabilities.find((c) => c === 3 /* CONFIGURATOR */)) && hasUI(v)
|
|
548
|
+
);
|
|
549
|
+
const browserVertices = manifest.vertices.filter(
|
|
550
|
+
(v) => Boolean(v.capabilities.find((c) => c === 4 /* BROWSER */)) && hasUI(v)
|
|
551
|
+
);
|
|
552
|
+
const totalUI = configVertices.length + browserVertices.length;
|
|
553
|
+
if (totalUI === 0) {
|
|
554
|
+
console.log(
|
|
555
|
+
chalk.yellow("\n\u26A0 No UI components found. Nothing to serve.\n")
|
|
556
|
+
);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
console.log(
|
|
560
|
+
chalk.dim("\u2502 ") + `Found ${chalk.bold(totalUI)} UI component${totalUI === 1 ? "" : "s"}
|
|
561
|
+
`
|
|
562
|
+
);
|
|
563
|
+
const configs = Object.fromEntries(
|
|
564
|
+
configVertices.map((v) => [v.name, pathLookup[v.name]])
|
|
565
|
+
);
|
|
566
|
+
const browsers = Object.fromEntries(
|
|
567
|
+
browserVertices.map((v) => [v.name, pathLookup[v.name]])
|
|
568
|
+
);
|
|
569
|
+
const configEntrypoints = findConfigEntrypoints(configs);
|
|
570
|
+
const browserEntrypoints = findBrowserEntrypoints(browsers);
|
|
571
|
+
const entrypointMap = {};
|
|
572
|
+
const ssgEntryPoints = [...configEntrypoints, ...browserEntrypoints].filter((ep) => ep.ssg !== void 0).map((ep) => {
|
|
573
|
+
entrypointMap[ep.ssg] = {
|
|
574
|
+
vertex: ep.name,
|
|
575
|
+
config: configEntrypoints.includes(ep)
|
|
576
|
+
};
|
|
577
|
+
return ep.ssg;
|
|
578
|
+
});
|
|
579
|
+
const execDefines = {};
|
|
580
|
+
const configDefines = {};
|
|
581
|
+
if (ssgEntryPoints.length > 0) {
|
|
582
|
+
const ssgSpinner = ora({
|
|
583
|
+
text: "Running SSG...",
|
|
584
|
+
prefixText: chalk.dim("\u2502")
|
|
585
|
+
}).start();
|
|
586
|
+
const ssgOutdir = path4.join("dist", "ssg-dev");
|
|
587
|
+
removeDirIfExists(ssgOutdir);
|
|
588
|
+
try {
|
|
589
|
+
const ssgResult = await esbuild({
|
|
590
|
+
...DEFAULT_SSG_OPTIONS,
|
|
591
|
+
outdir: ssgOutdir,
|
|
592
|
+
entryPoints: ssgEntryPoints
|
|
593
|
+
});
|
|
594
|
+
for (const [outputPath, outputMeta] of Object.entries(
|
|
595
|
+
ssgResult.metafile.outputs
|
|
596
|
+
)) {
|
|
597
|
+
if (!outputMeta.entryPoint) continue;
|
|
598
|
+
const mapInfo = entrypointMap[outputMeta.entryPoint];
|
|
599
|
+
if (!mapInfo) continue;
|
|
600
|
+
const { default: render } = await import(`file://${path4.resolve(outputPath)}`);
|
|
601
|
+
if (mapInfo.config) {
|
|
602
|
+
configDefines[mapInfo.vertex] = render.default();
|
|
603
|
+
} else {
|
|
604
|
+
execDefines[mapInfo.vertex] = render.default();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
ssgSpinner.succeed("SSG completed");
|
|
608
|
+
} catch (err) {
|
|
609
|
+
ssgSpinner.warn("SSG failed, continuing without static content");
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
const outdir = path4.join(DEFAULT_CDN, "browser");
|
|
613
|
+
removeDirIfExists(outdir);
|
|
614
|
+
const publicPath = `http://localhost:${port}/`;
|
|
615
|
+
const htmlFiles = [
|
|
616
|
+
...browserEntrypoints.map((b) => ({
|
|
617
|
+
entryPoints: [b.browser],
|
|
618
|
+
filename: path4.join(b.name, EXECUTOR_HTML),
|
|
619
|
+
htmlTemplate: fs4.readFileSync(b.html, "utf8"),
|
|
620
|
+
scriptLoading: "module",
|
|
621
|
+
define: {
|
|
622
|
+
...execDefines[b.name] ? { content: execDefines[b.name] } : {},
|
|
623
|
+
baseCdn: publicPath
|
|
624
|
+
}
|
|
625
|
+
})),
|
|
626
|
+
...configEntrypoints.map((c) => ({
|
|
627
|
+
entryPoints: [c.browser],
|
|
628
|
+
filename: path4.join(c.name, CONFIGURATOR_HTML),
|
|
629
|
+
htmlTemplate: fs4.readFileSync(c.html, "utf8"),
|
|
630
|
+
scriptLoading: "module",
|
|
631
|
+
define: {
|
|
632
|
+
...configDefines[c.name] ? { content: configDefines[c.name] } : {},
|
|
633
|
+
baseCdn: publicPath
|
|
634
|
+
}
|
|
635
|
+
}))
|
|
636
|
+
];
|
|
637
|
+
const buildSpinner = ora({
|
|
638
|
+
text: "Starting dev server...",
|
|
639
|
+
prefixText: chalk.dim("\u2502")
|
|
640
|
+
}).start();
|
|
641
|
+
const ctx = await context({
|
|
642
|
+
...DEFAULT_BROWSER_OPTIONS,
|
|
643
|
+
outdir,
|
|
644
|
+
publicPath,
|
|
645
|
+
minify: false,
|
|
646
|
+
sourcemap: true,
|
|
647
|
+
entryPoints: [
|
|
648
|
+
...configEntrypoints.map((c) => c.browser),
|
|
649
|
+
...browserEntrypoints.map((b) => b.browser)
|
|
650
|
+
],
|
|
651
|
+
banner: {
|
|
652
|
+
js: `new EventSource('/esbuild').addEventListener('change', () => location.reload());`
|
|
653
|
+
},
|
|
654
|
+
plugins: [htmlPlugin({ files: htmlFiles })]
|
|
655
|
+
});
|
|
656
|
+
await ctx.watch();
|
|
657
|
+
const { port: servePort } = await ctx.serve({
|
|
658
|
+
servedir: outdir,
|
|
659
|
+
port
|
|
660
|
+
});
|
|
661
|
+
buildSpinner.succeed("Dev server started");
|
|
662
|
+
console.log(chalk.bold.green("\n\u2728 Dev server running!\n"));
|
|
663
|
+
console.log(
|
|
664
|
+
chalk.dim("\u2502 ") + `Server: ${chalk.cyan(`http://localhost:${servePort}/`)}`
|
|
665
|
+
);
|
|
666
|
+
console.log(chalk.dim("\u2502"));
|
|
667
|
+
console.log(chalk.dim("\u2502 ") + chalk.bold("Available pages:"));
|
|
668
|
+
for (const b of browserEntrypoints) {
|
|
669
|
+
console.log(
|
|
670
|
+
chalk.dim("\u2502 ") + `${chalk.cyan(b.name)}: http://localhost:${servePort}/${b.name}/${EXECUTOR_HTML}`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
for (const c of configEntrypoints) {
|
|
674
|
+
console.log(
|
|
675
|
+
chalk.dim("\u2502 ") + `${chalk.magenta(c.name)} (config): http://localhost:${servePort}/${c.name}/${CONFIGURATOR_HTML}`
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
console.log(chalk.dim("\u2502"));
|
|
679
|
+
console.log(chalk.dim("\u2502 ") + chalk.gray("Press Ctrl+C to stop\n"));
|
|
680
|
+
}
|
|
520
681
|
async function validateLoadServiceDefinition(basePath, srv) {
|
|
521
682
|
switch (srv.type.case) {
|
|
522
683
|
case "variable": {
|
|
@@ -894,6 +1055,7 @@ export {
|
|
|
894
1055
|
CDN_URL_DEFAULT,
|
|
895
1056
|
build,
|
|
896
1057
|
buildServer,
|
|
1058
|
+
dev,
|
|
897
1059
|
validateLoadServiceDefinition
|
|
898
1060
|
};
|
|
899
1061
|
//# sourceMappingURL=index.js.map
|