@lakutata/cli 3.1.4 → 3.1.6

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.
@@ -0,0 +1,128 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { spawn } from 'node:child_process';
11
+ import { readFileSync, writeFileSync } from 'node:fs';
12
+ import path from 'node:path';
13
+ import { Controller } from 'lakutata/com/entrypoint';
14
+ import { CLIAction } from 'lakutata/decorator/ctrl';
15
+ import { NwjsRunDTO } from '../dtos/NwjsRunDTO.js';
16
+ import { NwjsUseDTO } from '../dtos/NwjsUseDTO.js';
17
+ import { NwjsVersionsDTO } from '../dtos/NwjsVersionsDTO.js';
18
+ import { loadBuilder } from '../lib/Builder.js';
19
+ import { done, step } from '../lib/Output.js';
20
+ /**
21
+ * The last release of NW.js running on Windows 7, 8 and 8.1 (Chromium 109)
22
+ */
23
+ const WINDOWS_7 = '0.72.0';
24
+ /**
25
+ * Whether a version of NW.js is at most another one
26
+ * @param version
27
+ * @param other
28
+ */
29
+ function atMost(version, other) {
30
+ const parts = (value) => value.split('.').map((part) => parseInt(part, 10) || 0);
31
+ const [a, b] = [parts(version), parts(other)];
32
+ for (let index = 0; index < 3; index++)
33
+ if (a[index] !== b[index])
34
+ return (a[index] ?? 0) < (b[index] ?? 0);
35
+ return true;
36
+ }
37
+ /**
38
+ * The systems a release of NW.js runs on, as its users see them
39
+ * @param release
40
+ */
41
+ function systemsOf(release) {
42
+ const windows = atMost(release.version, WINDOWS_7) ? 'Windows 7 or later' : 'Windows 10 or later';
43
+ const mac = release.platforms.includes('osx-arm64') ? 'macOS (Intel, Apple silicon)' : 'macOS (Intel; Apple silicon through Rosetta)';
44
+ const linux = `Linux (${release.platforms.filter((platform) => platform.startsWith('linux-')).map((platform) => platform.slice(6)).join(', ')})`;
45
+ return `${windows}, ${mac}, ${linux}`;
46
+ }
47
+ /**
48
+ * The commands of the applications of NW.js: its releases, the one of the application, the run of the development
49
+ */
50
+ export class NwjsController extends Controller {
51
+ async versions(input) {
52
+ const { nwjsReleases } = await loadBuilder(process.cwd());
53
+ const releases = (await nwjsReleases()).filter((release) => !atMost(release.node, '18.9.99'));
54
+ const shown = input.all ? releases : releases.filter((release, index) => index < 10 || release.version === WINDOWS_7);
55
+ for (const release of shown) {
56
+ const marks = [release === releases[0] ? 'latest' : '', release.version === WINDOWS_7 ? 'win7: the last one running on Windows 7, 8 and 8.1' : ''].filter(Boolean).join(', ');
57
+ step(`${release.version.padEnd(9)} ${release.date.padEnd(11)} Node.js ${release.node.padEnd(8)} Chromium ${release.chromium.split('.')[0]} ${release.platforms.join(' ')}${marks ? ` (${marks})` : ''}`);
58
+ }
59
+ return undefined;
60
+ }
61
+ async use(input) {
62
+ const { nwjsRelease, downloadNwjs } = await loadBuilder(process.cwd());
63
+ const release = await nwjsRelease(input.version);
64
+ const file = path.join(process.cwd(), 'package.json');
65
+ const manifest = JSON.parse(readFileSync(file, 'utf8'));
66
+ manifest.lakutata = { ...manifest.lakutata, nwjs: { ...manifest.lakutata?.nwjs, version: release.version } };
67
+ writeFileSync(file, `${JSON.stringify(manifest, null, 2)}\n`);
68
+ //What the builds of the user interface and of the application are made for
69
+ writeFileSync(path.join(process.cwd(), 'nwjs.json'), `${JSON.stringify({ version: release.version, node: release.node, chromium: release.chromium }, null, 2)}\n`);
70
+ done(`NW.js ${release.version}: Node.js ${release.node}, Chromium ${release.chromium}`);
71
+ step(`Runs on ${systemsOf(release)}`);
72
+ if (input.download) {
73
+ const runtime = await downloadNwjs({ version: release.version, flavor: 'sdk', progress: (line) => step(`Downloading ${line}`) });
74
+ done(`Downloaded NW.js ${runtime.version} (sdk, ${runtime.platform})`);
75
+ }
76
+ return undefined;
77
+ }
78
+ async run(input) {
79
+ const { stageNwjsApp, downloadNwjs } = await loadBuilder(process.cwd());
80
+ const stage = await stageNwjsApp({ project: process.cwd(), outdir: path.join('.nwjs', 'app'), version: input.release });
81
+ if (stage.addons.rebuilt.length)
82
+ step(`Native addons built for NW.js ${stage.release.version} (${stage.platform}): ${stage.addons.rebuilt.join(', ')}`);
83
+ if (stage.addons.renamed.length)
84
+ step(`Native addons loading the Node.js of NW.js (node.dll): ${stage.addons.renamed.join(', ')}`);
85
+ const runtime = await downloadNwjs({ version: stage.release.version, flavor: input.flavor, progress: (line) => step(`Downloading ${line}`) });
86
+ step(`NW.js ${runtime.version} (${runtime.flavor}, ${runtime.platform}): Node.js ${runtime.node}, Chromium ${runtime.chromium.split('.')[0]}`);
87
+ const code = await new Promise((resolve, reject) => {
88
+ const child = spawn(runtime.executable, [stage.directory, ...input.args ?? []], { stdio: 'inherit' });
89
+ //NW.js ends with the command: at once when the command is stopped by a signal sent to it only (a runner of the
90
+ //scripts), the run then done
91
+ const stop = () => {
92
+ if (child.exitCode === null && child.signalCode === null)
93
+ child.kill();
94
+ };
95
+ const events = ['exit', 'SIGINT', 'SIGTERM', 'SIGHUP'];
96
+ for (const event of events)
97
+ process.once(event, stop);
98
+ child.once('error', reject);
99
+ //Stopped by a signal (Ctrl-C in the terminal): a normal end of the run
100
+ child.once('exit', (exitCode, signal) => {
101
+ for (const event of events)
102
+ process.off(event, stop);
103
+ resolve(signal ? 0 : exitCode ?? 1);
104
+ });
105
+ });
106
+ if (code !== 0)
107
+ throw new Error(`NW.js exited with ${code}`);
108
+ return undefined;
109
+ }
110
+ }
111
+ __decorate([
112
+ CLIAction('nwjs versions', NwjsVersionsDTO, { description: 'List the releases of NW.js lakutata runs on: their Node.js, their Chromium, their systems' }),
113
+ __metadata("design:type", Function),
114
+ __metadata("design:paramtypes", [NwjsVersionsDTO]),
115
+ __metadata("design:returntype", Promise)
116
+ ], NwjsController.prototype, "versions", null);
117
+ __decorate([
118
+ CLIAction('nwjs use <version>', NwjsUseDTO, { description: 'Give the application of the current directory its version of NW.js (lakutata.nwjs), and write its Node.js and its Chromium into nwjs.json' }),
119
+ __metadata("design:type", Function),
120
+ __metadata("design:paramtypes", [NwjsUseDTO]),
121
+ __metadata("design:returntype", Promise)
122
+ ], NwjsController.prototype, "use", null);
123
+ __decorate([
124
+ CLIAction('nwjs run [args...]', NwjsRunDTO, { description: 'Run the compiled application of the current directory in NW.js (the build with its developer tools, by default)' }),
125
+ __metadata("design:type", Function),
126
+ __metadata("design:paramtypes", [NwjsRunDTO]),
127
+ __metadata("design:returntype", Promise)
128
+ ], NwjsController.prototype, "run", null);
@@ -29,7 +29,7 @@ function megabytes(size) {
29
29
  export class PackController extends Controller {
30
30
  async bundle(input) {
31
31
  const { bundleProject } = await loadBuilder(process.cwd());
32
- const result = await bundleProject({ project: process.cwd(), entry: input.entry, outfile: input.outfile, minify: input.minify, external: input.external });
32
+ const result = await bundleProject({ project: process.cwd(), entry: input.entry, outfile: input.outfile, minify: input.minify, external: input.external, node: input.node });
33
33
  done(`${path.relative(process.cwd(), result.outfile)} (${megabytes(result.size)}): node ${path.relative(process.cwd(), result.outfile)}`);
34
34
  //The native addons and the scripts of the workers are next to the bundle, which is distributed with them
35
35
  if (result.nativeDirectory) {
@@ -49,7 +49,7 @@ export class PackController extends Controller {
49
49
  }
50
50
  async executable(input) {
51
51
  const { buildExecutable } = await loadBuilder(process.cwd());
52
- const result = await buildExecutable({ project: process.cwd(), entry: input.entry, outdir: input.outdir, minify: input.minify, external: input.external, runtime: input.runtime, layout: input.layout });
52
+ const result = await buildExecutable({ project: process.cwd(), entry: input.entry, outdir: input.outdir, minify: input.minify, external: input.external, runtime: input.runtime, layout: input.layout, nodeProgram: input.nodeProgram });
53
53
  step(`${result.runtime} embedded`);
54
54
  if (result.native.length)
55
55
  step(result.directory ? `Native addons next to the executable: ${result.native.join(', ')}` : `Native addons embedded, extracted at the first run: ${result.native.join(', ')}`);
@@ -68,12 +68,21 @@ export class PackController extends Controller {
68
68
  }
69
69
  async installer(input) {
70
70
  const { buildInstaller } = await loadBuilder(process.cwd());
71
- const result = await buildInstaller({ project: process.cwd(), targets: input.target, outdir: input.outdir, entry: input.entry, minify: input.minify, external: input.external });
72
- step(`${result.executable.runtime} embedded`);
73
- if (result.executable.native.length)
74
- step(`Native addons: ${result.executable.native.join(', ')}`);
75
- if (result.executable.resources.length)
76
- step(`Resources: ${result.executable.resources.join(', ')}`);
71
+ const result = await buildInstaller({ project: process.cwd(), targets: input.target, outdir: input.outdir, entry: input.entry, minify: input.minify, external: input.external, nodeProgram: input.nodeProgram, arch: input.arch, progress: (line) => step(`Downloading ${line}`) });
72
+ if (result.nwjs) {
73
+ step(`NW.js ${result.nwjs.runtime.version} (${result.nwjs.runtime.platform}): ${path.basename(result.nwjs.directory)}`);
74
+ if (result.nwjs.stage.addons.rebuilt.length)
75
+ step(`Native addons built for NW.js: ${result.nwjs.stage.addons.rebuilt.join(', ')}`);
76
+ if (result.nwjs.stage.addons.renamed.length)
77
+ step(`Native addons loading the Node.js of NW.js (node.dll): ${result.nwjs.stage.addons.renamed.join(', ')}`);
78
+ }
79
+ if (result.executable) {
80
+ step(`${result.executable.runtime} embedded`);
81
+ if (result.executable.native.length)
82
+ step(`Native addons: ${result.executable.native.join(', ')}`);
83
+ if (result.executable.resources.length)
84
+ step(`Resources: ${result.executable.resources.join(', ')}`);
85
+ }
77
86
  for (const warning of result.warnings)
78
87
  warn(warning);
79
88
  for (const file of result.files)
@@ -27,3 +27,7 @@ __decorate([
27
27
  Expect(DTO.Array(DTO.String()).optional().description('The modules left out of the bundle, loaded at run time from a node_modules next to it (the native addons are handled)')),
28
28
  __metadata("design:type", Array)
29
29
  ], BundleDTO.prototype, "external", void 0);
30
+ __decorate([
31
+ Expect(DTO.String().pattern(/^v?\d+(\.\d+){0,2}$/).optional().description('The version of Node.js running the bundle, whose syntax it is written in (18.10 for NW.js 0.70; the version running the command by default)')),
32
+ __metadata("design:type", String)
33
+ ], BundleDTO.prototype, "node", void 0);
@@ -19,6 +19,10 @@ __decorate([
19
19
  Expect(DTO.String().optional().pattern(/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/).description('The ID of the application (a package name), its name in lower case by default')),
20
20
  __metadata("design:type", String)
21
21
  ], CreateProjectDTO.prototype, "id", void 0);
22
+ __decorate([
23
+ Expect(DTO.String().optional().pattern(/^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$/).description('The id of the application on the mobile systems (reverse domain name: com.acme.shop), for the mobile templates: com.example.<name> by default, which the stores refuse')),
24
+ __metadata("design:type", String)
25
+ ], CreateProjectDTO.prototype, "bundleId", void 0);
22
26
  __decorate([
23
27
  Expect(DTO.String().optional().default('default').description('The template: the name of an official template (lakutata templates lists them), npm:<package>, github:<owner>/<repo> or a directory')),
24
28
  __metadata("design:type", String)
@@ -35,3 +35,7 @@ __decorate([
35
35
  Expect(DTO.String().valid('file', 'directory').optional().default('file').description('One file, its native addons and its resources embedded (file, by default), or a directory: the executable and its native addons and resources next to it (directory)')),
36
36
  __metadata("design:type", String)
37
37
  ], ExecutableDTO.prototype, "layout", void 0);
38
+ __decorate([
39
+ Expect(DTO.String().optional().description('The node program embedded in the executable (Node.js 20.12, 21.7 or later): another Node.js than the one running the command, to make the executable from an older Node.js (the bundle is written in the syntax of the node program)')),
40
+ __metadata("design:type", String)
41
+ ], ExecutableDTO.prototype, "nodeProgram", void 0);
@@ -12,7 +12,7 @@ import { Expect } from 'lakutata/decorator/dto';
12
12
  export class InstallerDTO extends DTO {
13
13
  }
14
14
  __decorate([
15
- Expect(DTO.Array(DTO.String()).optional().description('The installers made: deb, rpm, apk, archlinux, tar.gz on Linux, pkg, tar.gz on macOS, nsis, msi, zip on Windows (the lakutata.installer of the package.json by default)')),
15
+ Expect(DTO.Array(DTO.String()).optional().description('The installers made: deb, rpm, apk, archlinux, tar.gz on Linux, pkg, dmg (the applications of NW.js), tar.gz on macOS, nsis, msi, zip on Windows (the lakutata.installer of the package.json by default)')),
16
16
  __metadata("design:type", Array)
17
17
  ], InstallerDTO.prototype, "target", void 0);
18
18
  __decorate([
@@ -31,3 +31,11 @@ __decorate([
31
31
  Expect(DTO.Array(DTO.String()).optional().description('The modules left out of the bundle')),
32
32
  __metadata("design:type", Array)
33
33
  ], InstallerDTO.prototype, "external", void 0);
34
+ __decorate([
35
+ Expect(DTO.String().optional().description('The node program embedded in the executable (Node.js 20.12, 21.7 or later): another Node.js than the one running the command, to make the executable from an older Node.js (the bundle is written in the syntax of the node program)')),
36
+ __metadata("design:type", String)
37
+ ], InstallerDTO.prototype, "nodeProgram", void 0);
38
+ __decorate([
39
+ Expect(DTO.String().valid('x64', 'ia32', 'arm64').optional().description('The architecture of an application of NW.js (the one of this machine by default): ia32 for the 32-bit systems of Windows (Windows 7)')),
40
+ __metadata("design:type", String)
41
+ ], InstallerDTO.prototype, "arch", void 0);
@@ -0,0 +1,25 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class MobileDeployDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().valid('android', 'ios', 'harmony').required().description('The system: android (an emulator or a device, the debug build of the application), ios (a simulator) or harmony (an emulator or a device, the debug build of the application)')),
16
+ __metadata("design:type", String)
17
+ ], MobileDeployDTO.prototype, "platform", void 0);
18
+ __decorate([
19
+ Expect(DTO.String().optional().description('The emulator or the device of Android (its serial, adb devices) or of HarmonyOS (its target, hdc list targets), the simulator of iOS (its UDID or its name, xcrun simctl list); the one running by default')),
20
+ __metadata("design:type", String)
21
+ ], MobileDeployDTO.prototype, "device", void 0);
22
+ __decorate([
23
+ Expect(DTO.Boolean().optional().default(false).description('Watch the files of the application: when they change, run its build script (npm run build) and deploy it again, until Ctrl+C')),
24
+ __metadata("design:type", Boolean)
25
+ ], MobileDeployDTO.prototype, "watch", void 0);
@@ -0,0 +1,21 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class MobileNodeDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().valid('android', 'ios', 'harmony').required().description('The system the libnode is downloaded for: android, ios or harmony')),
16
+ __metadata("design:type", String)
17
+ ], MobileNodeDTO.prototype, "platform", void 0);
18
+ __decorate([
19
+ Expect(DTO.String().optional().description('The architectures of Android downloaded for, separated by commas (arm64-v8a,armeabi-v7a,x86_64); arm64-v8a,x86_64 by default')),
20
+ __metadata("design:type", String)
21
+ ], MobileNodeDTO.prototype, "abis", void 0);
@@ -0,0 +1,21 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class MobileRunDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().valid('android', 'ios', 'harmony').required().description('The system: android (an emulator or a device), ios (a simulator) or harmony (an emulator or a device)')),
16
+ __metadata("design:type", String)
17
+ ], MobileRunDTO.prototype, "platform", void 0);
18
+ __decorate([
19
+ Expect(DTO.String().optional().description('The emulator or the device of Android (its serial, adb devices) or of HarmonyOS (its target, hdc list targets), the simulator of iOS (its UDID or its name, xcrun simctl list devices); the one running by default, else the newest iPhone for iOS')),
20
+ __metadata("design:type", String)
21
+ ], MobileRunDTO.prototype, "device", void 0);
@@ -0,0 +1,25 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class MobileStageDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().valid('android', 'ios', 'harmony').required().description('The system the Node.js project is made for: android, ios or harmony')),
16
+ __metadata("design:type", String)
17
+ ], MobileStageDTO.prototype, "platform", void 0);
18
+ __decorate([
19
+ Expect(DTO.Boolean().optional().default(true).description('Minify the bundle (true by default)')),
20
+ __metadata("design:type", Boolean)
21
+ ], MobileStageDTO.prototype, "minify", void 0);
22
+ __decorate([
23
+ Expect(DTO.String().optional().description('The architectures of Android the native addons are built for, separated by commas (arm64-v8a,x86_64); those of the libnode by default')),
24
+ __metadata("design:type", String)
25
+ ], MobileStageDTO.prototype, "abis", void 0);
@@ -0,0 +1,25 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class NwjsRunDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.Array(DTO.String()).optional().description('The arguments given to the application, after -- (lakutata nwjs run -- --ui=http://localhost:5173)')),
16
+ __metadata("design:type", Array)
17
+ ], NwjsRunDTO.prototype, "args", void 0);
18
+ __decorate([
19
+ Expect(DTO.String().optional().description('The release of NW.js run: a version, latest or win7 (the version of lakutata.nwjs by default)')),
20
+ __metadata("design:type", String)
21
+ ], NwjsRunDTO.prototype, "release", void 0);
22
+ __decorate([
23
+ Expect(DTO.String().valid('sdk', 'normal').optional().default('sdk').description('The flavor of NW.js: sdk (with its developer tools, by default) or normal (the one shipped to the users)')),
24
+ __metadata("design:type", String)
25
+ ], NwjsRunDTO.prototype, "flavor", void 0);
@@ -0,0 +1,21 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class NwjsUseDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().required().description('The version of NW.js: a version (0.119.2), latest, or win7 (0.72.0, the last one running on Windows 7, 8 and 8.1)')),
16
+ __metadata("design:type", String)
17
+ ], NwjsUseDTO.prototype, "version", void 0);
18
+ __decorate([
19
+ Expect(DTO.Boolean().optional().default(false).description('Download the development build of NW.js (with its developer tools) for this machine now')),
20
+ __metadata("design:type", Boolean)
21
+ ], NwjsUseDTO.prototype, "download", void 0);
@@ -0,0 +1,17 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from 'lakutata';
11
+ import { Expect } from 'lakutata/decorator/dto';
12
+ export class NwjsVersionsDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.Boolean().optional().default(false).description('List every release lakutata runs on (the latest ten and the one of Windows 7 by default)')),
16
+ __metadata("design:type", Boolean)
17
+ ], NwjsVersionsDTO.prototype, "all", void 0);
@@ -383,7 +383,9 @@ function nativeFiles(name, version, build, packageManager) {
383
383
  name: name,
384
384
  version: version,
385
385
  private: true,
386
- type: 'module',
386
+ //CommonJS: the bundles of the applications are CommonJS and require it, which loads an ES module only on
387
+ //Node.js 20.19, 22.12 and later
388
+ type: 'commonjs',
387
389
  main: 'dist/index.js',
388
390
  types: 'dist/index.d.ts',
389
391
  exports: { '.': { types: './dist/index.d.ts', default: './dist/index.js' } },
@@ -406,7 +408,6 @@ function nativeFiles(name, version, build, packageManager) {
406
408
  ...chosen.files,
407
409
  'src/index.ts': `import {createRequire} from 'node:module'
408
410
  import path from 'node:path'
409
- import {fileURLToPath} from 'node:url'
410
411
 
411
412
  /**
412
413
  * The functions of the addon
@@ -418,7 +419,7 @@ type Binding = {
418
419
  /**
419
420
  * The addon built into build/Release, loaded from the directory of the package
420
421
  */
421
- const binding: Binding = createRequire(import.meta.url)('node-gyp-build')(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'))
422
+ const binding: Binding = createRequire(__filename)('node-gyp-build')(path.resolve(__dirname, '..'))
422
423
 
423
424
  /**
424
425
  * Greet someone, in ${build === 'rust' ? 'Rust' : 'C++'}
@@ -1,11 +1,20 @@
1
- import { styleText } from 'node:util';
1
+ import util from 'node:util';
2
+ /**
3
+ * The styles of the output, and their codes of the terminals (where util.styleText is missing: before Node.js 20.12)
4
+ */
5
+ const STYLES = { bold: [1, 22], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39] };
2
6
  /**
3
7
  * A text in a style, when the output is a terminal
4
8
  * @param style
5
9
  * @param text
6
10
  */
7
11
  export function styled(style, text) {
8
- return process.stdout.isTTY && !process.env.NO_COLOR ? styleText(style, text) : text;
12
+ if (!process.stdout.isTTY || process.env.NO_COLOR)
13
+ return text;
14
+ //node-compat: util.styleText
15
+ if (typeof util.styleText === 'function')
16
+ return util.styleText(style, text);
17
+ return `\u001b[${STYLES[style][0]}m${text}\u001b[${STYLES[style][1]}m`;
9
18
  }
10
19
  /**
11
20
  * Print a step done
@@ -119,6 +119,23 @@ let ProjectCreator = class ProjectCreator extends Component {
119
119
  await writeFile(target, filled);
120
120
  }
121
121
  }
122
+ /**
123
+ * Whether a template (its files, those of its features) holds a field ({$APP_BUNDLE_ID}…)
124
+ * @param template
125
+ * @param field
126
+ */
127
+ async uses(template, field) {
128
+ for (const root of [template.root, template.featuresDirectory]) {
129
+ if (!root || !existsSync(root))
130
+ continue;
131
+ for (const file of await listFiles(root)) {
132
+ const content = await readFile(path.join(root, file));
133
+ if (isText(content) && content.toString('utf8').includes(field))
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ }
122
139
  /**
123
140
  * Get the files of a template
124
141
  * @param source
@@ -151,6 +168,7 @@ let ProjectCreator = class ProjectCreator extends Component {
151
168
  await this.fill(plan.directory, files, {
152
169
  $APP_NAME: plan.name,
153
170
  $APP_ID: plan.id,
171
+ $APP_BUNDLE_ID: plan.bundleId,
154
172
  $APP_DESC: plan.description,
155
173
  $APP_AUTHOR: plan.author,
156
174
  $APP_LICENSE: plan.license,
@@ -32,7 +32,10 @@ export const BUILTIN_TEMPLATES = [
32
32
  { name: 'web-vue', description: 'An HTTP API serving a Vue single-page application (Vite)', package: '@lakutata/template-web-vue', features: ['i18n', 'installer'] },
33
33
  { name: 'web-nuxt', description: 'An HTTP API serving a Nuxt application from the same process', package: '@lakutata/template-web-nuxt', features: ['i18n', 'installer'] },
34
34
  { name: 'electron-react', description: 'A desktop application: Electron, its main process serving a React renderer over IPC', package: '@lakutata/template-electron-react', features: ['i18n'] },
35
- { name: 'electron-vue', description: 'A desktop application: Electron, its main process serving a Vue renderer over IPC', package: '@lakutata/template-electron-vue', features: ['i18n'] }
35
+ { name: 'electron-vue', description: 'A desktop application: Electron, its main process serving a Vue renderer over IPC', package: '@lakutata/template-electron-vue', features: ['i18n'] },
36
+ { name: 'nwjs-react', description: 'A desktop application: NW.js, its background script serving a React user interface isolated in a webview', package: '@lakutata/template-nwjs-react', features: ['i18n', 'win7'] },
37
+ { name: 'nwjs-vue', description: 'A desktop application: NW.js, its background script serving a Vue user interface isolated in a webview', package: '@lakutata/template-nwjs-vue', features: ['i18n', 'win7'] },
38
+ { name: 'mobile-react', description: 'A mobile application (Android, iOS, HarmonyOS): React Native, the Node.js of the application serving its user interface', package: '@lakutata/template-mobile-react', features: ['i18n'] }
36
39
  ];
37
40
  /**
38
41
  * How long the catalog is kept, 1 day
@@ -66,7 +66,8 @@ export async function runScript(workspace, script, options = {}) {
66
66
  dependencies.delete(name);
67
67
  return [pkg.name, dependencies];
68
68
  }));
69
- const concurrency = options.parallel ? Math.max(1, selected.length) : Math.max(1, options.concurrency ?? os.availableParallelism());
69
+ //node-compat: os.availableParallelism
70
+ const concurrency = options.parallel ? Math.max(1, selected.length) : Math.max(1, options.concurrency ?? (typeof os.availableParallelism === 'function' ? os.availableParallelism() : os.cpus().length));
70
71
  const width = Math.max(0, ...selected.map((pkg) => pkg.name.length));
71
72
  const done = new Set();
72
73
  //The packages depending on a failed package, not run