@jointhedots/gear 1.1.12 → 1.1.14
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/esm/builder/build-app-bundle.js +11 -9
- package/esm/builder/build-application.js +6 -5
- package/esm/builder/build-library.js +11 -9
- package/esm/builder/build-target.js +7 -143
- package/esm/builder/helpers/emit-bundle-manifest.js +29 -0
- package/esm/builder/{esbuild-plugins.js → helpers/emit-esmodules.js} +71 -31
- package/esm/builder/helpers/emit-package-manifest.js +19 -0
- package/esm/builder/helpers/emit-static-assets.js +47 -0
- package/esm/builder/helpers/emit-typescript-definition.js +325 -0
- package/esm/builder/helpers/task.js +9 -0
- package/esm/model/helpers/create-manifests.js +43 -22
- package/esm/model/helpers/discover-workspace.js +39 -21
- package/esm/model/workspace.js +7 -9
- package/esm/utils/file.js +53 -29
- package/package.json +5 -4
- package/esm/builder/emit-dts.js +0 -388
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import Path from "node:path";
|
|
1
2
|
import { Bundle, Library } from "../model/workspace.js";
|
|
2
3
|
import { StorageFiles } from "../model/storage.js";
|
|
3
|
-
import { BuildTarget
|
|
4
|
-
import { TypescriptDefinitionTask } from "./emit-
|
|
5
|
-
import
|
|
4
|
+
import { BuildTarget } from "./build-target.js";
|
|
5
|
+
import { TypescriptDefinitionTask } from "./helpers/emit-typescript-definition.js";
|
|
6
|
+
import { PackageManifestTask } from "./helpers/emit-package-manifest.js";
|
|
6
7
|
import { PathQualifier } from "./helpers/path-helpers.js";
|
|
7
|
-
import {
|
|
8
|
-
import { DependencyDeduplicationPlugin, collectLibraryGraph } from "./
|
|
8
|
+
import { create_export_map } from "../model/helpers/create-manifests.js";
|
|
9
|
+
import { DependencyDeduplicationPlugin, collectLibraryGraph } from "./helpers/emit-esmodules.js";
|
|
10
|
+
import { BundleManifestTask } from "./helpers/emit-bundle-manifest.js";
|
|
9
11
|
export var PathStatus;
|
|
10
12
|
(function (PathStatus) {
|
|
11
13
|
PathStatus[PathStatus["Unknown"] = undefined] = "Unknown";
|
|
@@ -18,16 +20,16 @@ export function create_bundle_target(opts) {
|
|
|
18
20
|
const { bundle, library, storage } = opts;
|
|
19
21
|
const lib = library;
|
|
20
22
|
const target = new BuildTarget(bundle.id, storage, lib.workspace, opts.devmode == true, opts.watch == true, opts.clean == true);
|
|
21
|
-
const manifs = create_manifests(lib, bundle, opts.version);
|
|
22
23
|
// Prepare esm setup
|
|
23
24
|
target.esmodules.set_root(lib.path);
|
|
24
25
|
// Add bundle package.json
|
|
25
|
-
target.
|
|
26
|
+
target.tasks.push(new PackageManifestTask(target, lib, opts.version));
|
|
26
27
|
// Add bundle types.d.ts
|
|
27
28
|
target.tasks.push(new TypescriptDefinitionTask(target, lib));
|
|
28
29
|
// Add bundle exporteds
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const entries = create_export_map(lib, lib.bundle);
|
|
31
|
+
for (const exp_id in entries) {
|
|
32
|
+
const exp = entries[exp_id];
|
|
31
33
|
target.esmodules.add_entry(exp.basename, exp.source);
|
|
32
34
|
}
|
|
33
35
|
// Add bundle content
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Library, matchComponentSelection } from "../model/workspace.js";
|
|
2
|
-
import { StorageFiles } from "../model/storage.js";
|
|
3
|
-
import { BuildTarget, BuildTask, BundleManifestTask } from "./build-target.js";
|
|
4
1
|
import Path from "node:path";
|
|
5
|
-
import Fs from "node:fs";
|
|
6
2
|
import Sharp from "sharp";
|
|
7
3
|
import MIME from 'mime';
|
|
4
|
+
import { Library, matchComponentSelection } from "../model/workspace.js";
|
|
5
|
+
import { StorageFiles } from "../model/storage.js";
|
|
6
|
+
import { BuildTarget } from "./build-target.js";
|
|
8
7
|
import { build_app_composable_host } from "./build-app-host.js";
|
|
9
|
-
import { DependencyDeduplicationPlugin } from "./
|
|
8
|
+
import { DependencyDeduplicationPlugin } from "./helpers/emit-esmodules.js";
|
|
9
|
+
import { BundleManifestTask } from "./helpers/emit-bundle-manifest.js";
|
|
10
|
+
import { BuildTask } from "./helpers/task.js";
|
|
10
11
|
function collect_app_libraries(app) {
|
|
11
12
|
const libs = [app.library];
|
|
12
13
|
function collect_library_deps(lib) {
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import Path from "node:path";
|
|
2
|
+
import ChildProcess from "child_process";
|
|
1
3
|
import { Library } from "../model/workspace.js";
|
|
2
4
|
import { StorageFiles } from "../model/storage.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
5
|
+
import { BuildTarget } from "./build-target.js";
|
|
6
|
+
import { TypescriptDefinitionTask } from "./helpers/emit-typescript-definition.js";
|
|
7
|
+
import { PackageManifestTask } from "./helpers/emit-package-manifest.js";
|
|
8
|
+
import { create_export_map } from "../model/helpers/create-manifests.js";
|
|
9
|
+
import { BundleManifestTask } from "./helpers/emit-bundle-manifest.js";
|
|
8
10
|
export function create_library_target(opts) {
|
|
9
11
|
const lib = opts.library;
|
|
10
12
|
const target = new BuildTarget(lib.name, opts.storage, lib.workspace, opts.devmode == true, opts.watch == true, opts.clean == true);
|
|
11
|
-
const manifs = create_manifests(lib, lib.bundle, opts.version);
|
|
12
13
|
// Prepare esm setup
|
|
13
14
|
target.esmodules.set_root(lib.path);
|
|
14
15
|
// Add bundle exporteds
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const entries = create_export_map(lib, lib.bundle);
|
|
17
|
+
for (const exp_id in entries) {
|
|
18
|
+
const exp = entries[exp_id];
|
|
17
19
|
target.esmodules.add_entry(exp.basename, exp.source);
|
|
18
20
|
}
|
|
19
21
|
// Add library types.d.ts
|
|
20
22
|
target.tasks.push(new TypescriptDefinitionTask(target, lib));
|
|
21
23
|
// Add library package.json
|
|
22
|
-
target.
|
|
24
|
+
target.tasks.push(new PackageManifestTask(target, lib, opts.version));
|
|
23
25
|
// Add bundle content
|
|
24
26
|
const { bundle } = lib;
|
|
25
27
|
if (bundle) {
|
|
@@ -1,145 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { copyToStorageStream } from "../model/storage.js";
|
|
7
|
-
import * as esbuild from 'esbuild';
|
|
8
|
-
import { computeNameHashID } from "../utils/normalized-name.js";
|
|
9
|
-
export class BuildTask {
|
|
10
|
-
target;
|
|
11
|
-
constructor(target) {
|
|
12
|
-
this.target = target;
|
|
13
|
-
}
|
|
14
|
-
get log() { return this.target.log; }
|
|
15
|
-
async init() { }
|
|
16
|
-
}
|
|
17
|
-
export class BundleManifestTask extends BuildTask {
|
|
18
|
-
target;
|
|
19
|
-
bundle;
|
|
20
|
-
constructor(target, bundle) {
|
|
21
|
-
super(target);
|
|
22
|
-
this.target = target;
|
|
23
|
-
this.bundle = bundle;
|
|
24
|
-
}
|
|
25
|
-
async execute() {
|
|
26
|
-
const { target, bundle } = this;
|
|
27
|
-
const { manifest } = bundle;
|
|
28
|
-
const tx = this.target.edit();
|
|
29
|
-
// Emit static components manifest
|
|
30
|
-
const components = [];
|
|
31
|
-
for (const manif of target.components.values()) {
|
|
32
|
-
const pub = makeComponentPublication(manif);
|
|
33
|
-
pub.ref = await tx.commitContent(JSON.stringify(manif, null, 2), MIME.getType(".json"));
|
|
34
|
-
components.push(pub);
|
|
35
|
-
}
|
|
36
|
-
manifest.data.components = components;
|
|
37
|
-
// Emit bundle manifest
|
|
38
|
-
await tx.commitFile(`bundle.manifest.json`, JSON.stringify(manifest, null, 2));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export class AssetsTask extends BuildTask {
|
|
42
|
-
assets = [];
|
|
43
|
-
statics = {};
|
|
44
|
-
add_entry(entry, baseDir, library) {
|
|
45
|
-
let asset = null;
|
|
46
|
-
if (typeof entry === "string") {
|
|
47
|
-
const from = library.resolve_entry_path(entry, baseDir);
|
|
48
|
-
if (!from)
|
|
49
|
-
throw new Error(`In '${baseDir}', cannot found asset from: '${entry}'`);
|
|
50
|
-
asset = { from, to: Path.basename(entry) };
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const from = library.resolve_entry_path(entry.from, baseDir);
|
|
54
|
-
if (!from)
|
|
55
|
-
throw new Error(`In '${baseDir}', cannot found asset from: '${entry.from}'`);
|
|
56
|
-
asset = { from, to: entry.to };
|
|
57
|
-
}
|
|
58
|
-
this.log.info(`+ 📎 assets '${library.name}': ${asset.from} -> ${asset.to}`);
|
|
59
|
-
this.assets.push(asset);
|
|
60
|
-
}
|
|
61
|
-
add_static_text(name, data) {
|
|
62
|
-
this.statics[name] = data;
|
|
63
|
-
}
|
|
64
|
-
add_static_json(name, data) {
|
|
65
|
-
this.statics[name] = JSON.stringify(data, null, 2);
|
|
66
|
-
}
|
|
67
|
-
async execute() {
|
|
68
|
-
const tx = this.target.edit();
|
|
69
|
-
for (const key in this.statics) {
|
|
70
|
-
tx.commitFile(key, this.statics[key], MIME.getType(key));
|
|
71
|
-
}
|
|
72
|
-
for (const asset of this.assets) {
|
|
73
|
-
if (typeof asset === "string") {
|
|
74
|
-
copyToStorageStream(tx, asset, asset);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
copyToStorageStream(tx, asset.to, asset.from);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export class ESModulesTask extends BuildTask {
|
|
83
|
-
entries = {};
|
|
84
|
-
imports = {};
|
|
85
|
-
internals = new Map();
|
|
86
|
-
plugins = [];
|
|
87
|
-
context = null;
|
|
88
|
-
transaction = null;
|
|
89
|
-
polyfilled = true;
|
|
90
|
-
rootPath = null;
|
|
91
|
-
set_root(path) {
|
|
92
|
-
this.rootPath = path;
|
|
93
|
-
}
|
|
94
|
-
add_entry(name, path) {
|
|
95
|
-
this.entries[name] = path;
|
|
96
|
-
this.imports[path] = name;
|
|
97
|
-
}
|
|
98
|
-
add_entry_typescript(code, name) {
|
|
99
|
-
const id = computeNameHashID(code);
|
|
100
|
-
if (!name)
|
|
101
|
-
name = id;
|
|
102
|
-
this.internals.set(id, code);
|
|
103
|
-
this.add_entry(name, id);
|
|
104
|
-
return name;
|
|
105
|
-
}
|
|
106
|
-
add_resource_entry(resource, baseDir, library) {
|
|
107
|
-
if (typeof resource === "string") {
|
|
108
|
-
const parts = resource.split("#");
|
|
109
|
-
const file = library.resolve_entry_path(parts[0], baseDir);
|
|
110
|
-
if (file) {
|
|
111
|
-
let named = this.imports[file];
|
|
112
|
-
if (!named) {
|
|
113
|
-
named = library.make_file_id("lambda", file);
|
|
114
|
-
this.add_entry(named, file);
|
|
115
|
-
}
|
|
116
|
-
return `./${named}.js#${parts[1] || "default"}`;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
throw new Error(`${library.name}: Cannot resolve file: ${parts[0]}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return resource;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async execute() {
|
|
127
|
-
if (this.context) {
|
|
128
|
-
const prev_ctx = this.context;
|
|
129
|
-
this.context = null;
|
|
130
|
-
await prev_ctx.dispose();
|
|
131
|
-
}
|
|
132
|
-
const { target } = this;
|
|
133
|
-
this.context = await create_esbuild_context(this, target.devmode);
|
|
134
|
-
if (target.watch) {
|
|
135
|
-
await this.context.watch();
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
await this.context.rebuild();
|
|
139
|
-
await this.context.dispose();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
1
|
+
import {} from "../model/component.js";
|
|
2
|
+
import { Library, Workspace } from "../model/workspace.js";
|
|
3
|
+
import { ESModulesTask } from "./helpers/emit-esmodules.js";
|
|
4
|
+
import {} from "../model/storage.js";
|
|
5
|
+
import { AssetsTask } from "./helpers/emit-static-assets.js";
|
|
143
6
|
export class BuildTarget {
|
|
144
7
|
name;
|
|
145
8
|
storage;
|
|
@@ -203,7 +66,8 @@ export class BuildTarget {
|
|
|
203
66
|
const start = Date.now();
|
|
204
67
|
await task.execute();
|
|
205
68
|
const elapsed = (Date.now() - start) / 1000;
|
|
206
|
-
|
|
69
|
+
if (elapsed > 1.0)
|
|
70
|
+
this.log.info(`⏱ ${name} completed in ${elapsed.toFixed(2)}s`);
|
|
207
71
|
}
|
|
208
72
|
async build() {
|
|
209
73
|
const buildStartTime = Date.now();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { makeComponentPublication } from "../../model/component.js";
|
|
2
|
+
import { BuildTarget } from "../build-target.js";
|
|
3
|
+
import { BuildTask } from "./task.js";
|
|
4
|
+
import MIME from 'mime';
|
|
5
|
+
export class BundleManifestTask extends BuildTask {
|
|
6
|
+
target;
|
|
7
|
+
bundle;
|
|
8
|
+
constructor(target, bundle) {
|
|
9
|
+
super(target);
|
|
10
|
+
this.target = target;
|
|
11
|
+
this.bundle = bundle;
|
|
12
|
+
}
|
|
13
|
+
async execute() {
|
|
14
|
+
const { target, bundle } = this;
|
|
15
|
+
const { manifest } = bundle;
|
|
16
|
+
const tx = this.target.edit();
|
|
17
|
+
// Emit static components manifest
|
|
18
|
+
const components = [];
|
|
19
|
+
for (const manif of target.components.values()) {
|
|
20
|
+
const pub = makeComponentPublication(manif);
|
|
21
|
+
pub.ref = await tx.commitContent(JSON.stringify(manif, null, 2), MIME.getType(".json"));
|
|
22
|
+
components.push(pub);
|
|
23
|
+
}
|
|
24
|
+
manifest.data.components = components;
|
|
25
|
+
// Emit bundle manifest
|
|
26
|
+
await tx.commitFile(`bundle.manifest.json`, JSON.stringify(manifest, null, 2));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=emit-bundle-manifest.js.map
|
|
@@ -5,10 +5,11 @@ import MIME from 'mime';
|
|
|
5
5
|
import postcss from 'postcss';
|
|
6
6
|
import * as esbuild from 'esbuild';
|
|
7
7
|
import { sassPlugin } from 'esbuild-sass-plugin';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
8
|
+
import { PackageRootDir, resolve_normalized_suffixed_path } from "../../utils/file.js";
|
|
9
|
+
import { Library } from "../../model/workspace.js";
|
|
10
|
+
import { computeNameHashID } from "../../utils/normalized-name.js";
|
|
11
|
+
import { BuildTask } from "./task.js";
|
|
12
|
+
const VirtualOutDir = process.platform === 'win32' ? 'X:\\' : '/_/';
|
|
12
13
|
function getEsbuildLogLevel(mode) {
|
|
13
14
|
switch (mode) {
|
|
14
15
|
case "verbose":
|
|
@@ -486,30 +487,6 @@ export function ESModuleResolverPlugin(opts, tsconfigPaths) {
|
|
|
486
487
|
".ts": "ts", ".tsx": "tsx", ".js": "js", ".jsx": "jsx",
|
|
487
488
|
".json": "json", ".txt": "text", ".md": "text", ".css": "css",
|
|
488
489
|
};
|
|
489
|
-
const FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json'];
|
|
490
|
-
/** Resolve a file path with extension probing */
|
|
491
|
-
function resolveFilePath(importPath, baseDir) {
|
|
492
|
-
const resolved = Path.resolve(baseDir, importPath);
|
|
493
|
-
// Check if exact path exists
|
|
494
|
-
if (Fs.existsSync(resolved) && Fs.statSync(resolved).isFile()) {
|
|
495
|
-
return resolved;
|
|
496
|
-
}
|
|
497
|
-
// Try with common extensions
|
|
498
|
-
for (const ext of FILE_EXTENSIONS) {
|
|
499
|
-
const withExt = resolved + ext;
|
|
500
|
-
if (Fs.existsSync(withExt))
|
|
501
|
-
return withExt;
|
|
502
|
-
}
|
|
503
|
-
// Try index files in directory
|
|
504
|
-
if (Fs.existsSync(resolved) && Fs.statSync(resolved).isDirectory()) {
|
|
505
|
-
for (const ext of FILE_EXTENSIONS) {
|
|
506
|
-
const indexPath = Path.join(resolved, `index${ext}`);
|
|
507
|
-
if (Fs.existsSync(indexPath))
|
|
508
|
-
return indexPath;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return null;
|
|
512
|
-
}
|
|
513
490
|
return {
|
|
514
491
|
name: 'esm-resolver',
|
|
515
492
|
setup(build) {
|
|
@@ -546,14 +523,16 @@ export function ESModuleResolverPlugin(opts, tsconfigPaths) {
|
|
|
546
523
|
// 3. Handle relative/absolute file paths (entry points and local imports)
|
|
547
524
|
if (args.path.startsWith(".") || args.path.startsWith("/") || Path.isAbsolute(args.path)) {
|
|
548
525
|
const baseDir = args.resolveDir || workspaceRoot;
|
|
549
|
-
const resolved =
|
|
526
|
+
const resolved = resolve_normalized_suffixed_path(baseDir, args.path);
|
|
550
527
|
if (resolved) {
|
|
551
528
|
return { path: resolved, namespace: "file" };
|
|
552
529
|
}
|
|
553
530
|
}
|
|
554
531
|
// 4. Resolve tsconfig path aliases (e.g. @app/* -> ./src/*)
|
|
555
532
|
if (tsconfigPaths?.hasAliases) {
|
|
556
|
-
const resolved = tsconfigPaths.resolve(args.path,
|
|
533
|
+
const resolved = tsconfigPaths.resolve(args.path, (importPath, baseDir) => {
|
|
534
|
+
return resolve_normalized_suffixed_path(baseDir, importPath);
|
|
535
|
+
});
|
|
557
536
|
if (resolved) {
|
|
558
537
|
return { path: resolved, namespace: "file" };
|
|
559
538
|
}
|
|
@@ -572,4 +551,65 @@ export function ESModuleResolverPlugin(opts, tsconfigPaths) {
|
|
|
572
551
|
},
|
|
573
552
|
};
|
|
574
553
|
}
|
|
575
|
-
|
|
554
|
+
export class ESModulesTask extends BuildTask {
|
|
555
|
+
entries = {};
|
|
556
|
+
imports = {};
|
|
557
|
+
internals = new Map();
|
|
558
|
+
plugins = [];
|
|
559
|
+
context = null;
|
|
560
|
+
transaction = null;
|
|
561
|
+
polyfilled = true;
|
|
562
|
+
rootPath = null;
|
|
563
|
+
set_root(path) {
|
|
564
|
+
this.rootPath = path;
|
|
565
|
+
}
|
|
566
|
+
add_entry(name, path) {
|
|
567
|
+
this.entries[name] = path;
|
|
568
|
+
this.imports[path] = name;
|
|
569
|
+
}
|
|
570
|
+
add_entry_typescript(code, name) {
|
|
571
|
+
const id = computeNameHashID(code);
|
|
572
|
+
if (!name)
|
|
573
|
+
name = id;
|
|
574
|
+
this.internals.set(id, code);
|
|
575
|
+
this.add_entry(name, id);
|
|
576
|
+
return name;
|
|
577
|
+
}
|
|
578
|
+
add_resource_entry(resource, baseDir, library) {
|
|
579
|
+
if (typeof resource === "string") {
|
|
580
|
+
const parts = resource.split("#");
|
|
581
|
+
const file = library.resolve_entry_path(parts[0], baseDir);
|
|
582
|
+
if (file) {
|
|
583
|
+
let named = this.imports[file];
|
|
584
|
+
if (!named) {
|
|
585
|
+
named = library.make_file_id("lambda", file);
|
|
586
|
+
this.add_entry(named, file);
|
|
587
|
+
}
|
|
588
|
+
return `./${named}.js#${parts[1] || "default"}`;
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
throw new Error(`${library.name}: Cannot resolve file: ${parts[0]}`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
return resource;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
async execute() {
|
|
599
|
+
if (this.context) {
|
|
600
|
+
const prev_ctx = this.context;
|
|
601
|
+
this.context = null;
|
|
602
|
+
await prev_ctx.dispose();
|
|
603
|
+
}
|
|
604
|
+
const { target } = this;
|
|
605
|
+
this.context = await create_esbuild_context(this, target.devmode);
|
|
606
|
+
if (target.watch) {
|
|
607
|
+
await this.context.watch();
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
await this.context.rebuild();
|
|
611
|
+
await this.context.dispose();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
//# sourceMappingURL=emit-esmodules.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BuildTask } from "./task.js";
|
|
2
|
+
import { create_export_map, create_package_manifest } from "../../model/helpers/create-manifests.js";
|
|
3
|
+
import { console } from "node:inspector";
|
|
4
|
+
export class PackageManifestTask extends BuildTask {
|
|
5
|
+
library;
|
|
6
|
+
version;
|
|
7
|
+
constructor(target, library, version) {
|
|
8
|
+
super(target);
|
|
9
|
+
this.library = library;
|
|
10
|
+
this.version = version;
|
|
11
|
+
}
|
|
12
|
+
async execute() {
|
|
13
|
+
const { library, version } = this;
|
|
14
|
+
const pkg = create_package_manifest(library, library.bundle, version);
|
|
15
|
+
const tx = this.target.edit();
|
|
16
|
+
tx.commitFile("package.json", JSON.stringify(pkg, null, 2));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=emit-package-manifest.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Path from "node:path";
|
|
2
|
+
import MIME from 'mime';
|
|
3
|
+
import { Library } from "../../model/workspace.js";
|
|
4
|
+
import { copyToStorageStream } from "../../model/storage.js";
|
|
5
|
+
import { BuildTask } from "./task.js";
|
|
6
|
+
export class AssetsTask extends BuildTask {
|
|
7
|
+
assets = [];
|
|
8
|
+
statics = {};
|
|
9
|
+
add_entry(entry, baseDir, library) {
|
|
10
|
+
let asset = null;
|
|
11
|
+
if (typeof entry === "string") {
|
|
12
|
+
const from = library.resolve_entry_path(entry, baseDir);
|
|
13
|
+
if (!from)
|
|
14
|
+
throw new Error(`In '${baseDir}', cannot found asset from: '${entry}'`);
|
|
15
|
+
asset = { from, to: Path.basename(entry) };
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const from = library.resolve_entry_path(entry.from, baseDir);
|
|
19
|
+
if (!from)
|
|
20
|
+
throw new Error(`In '${baseDir}', cannot found asset from: '${entry.from}'`);
|
|
21
|
+
asset = { from, to: entry.to };
|
|
22
|
+
}
|
|
23
|
+
this.log.info(`+ 📎 assets '${library.name}': ${asset.from} -> ${asset.to}`);
|
|
24
|
+
this.assets.push(asset);
|
|
25
|
+
}
|
|
26
|
+
add_static_text(name, data) {
|
|
27
|
+
this.statics[name] = data;
|
|
28
|
+
}
|
|
29
|
+
add_static_json(name, data) {
|
|
30
|
+
this.statics[name] = JSON.stringify(data, null, 2);
|
|
31
|
+
}
|
|
32
|
+
async execute() {
|
|
33
|
+
const tx = this.target.edit();
|
|
34
|
+
for (const key in this.statics) {
|
|
35
|
+
tx.commitFile(key, this.statics[key], MIME.getType(key));
|
|
36
|
+
}
|
|
37
|
+
for (const asset of this.assets) {
|
|
38
|
+
if (typeof asset === "string") {
|
|
39
|
+
copyToStorageStream(tx, asset, asset);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
copyToStorageStream(tx, asset.to, asset.from);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=emit-static-assets.js.map
|