@lakutata/cli 2.17.0 → 3.0.0-beta.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.
Files changed (101) hide show
  1. package/README.md +455 -28
  2. package/dist/esm/CLIApp.js +6 -0
  3. package/dist/esm/Config.js +53 -0
  4. package/dist/esm/controllers/CommandLineController.js +180 -0
  5. package/dist/esm/controllers/I18nController.js +67 -0
  6. package/dist/esm/controllers/MigrationController.js +66 -0
  7. package/dist/esm/controllers/NativeController.js +41 -0
  8. package/dist/esm/controllers/PackController.js +88 -0
  9. package/dist/esm/controllers/WorkspaceController.js +91 -0
  10. package/dist/esm/dtos/AddPackageDTO.js +25 -0
  11. package/dist/esm/dtos/BundleDTO.js +29 -0
  12. package/dist/esm/dtos/CleanDTO.js +17 -0
  13. package/dist/esm/dtos/CreateProjectDTO.js +61 -0
  14. package/dist/esm/dtos/ExecutableDTO.js +37 -0
  15. package/dist/esm/dtos/I18nDTO.js +41 -0
  16. package/dist/esm/dtos/InstallerDTO.js +33 -0
  17. package/dist/{options/ListTemplatesOptions.js → esm/dtos/ListTemplatesDTO.js} +5 -14
  18. package/dist/esm/dtos/MigrationDTO.js +45 -0
  19. package/dist/esm/dtos/NativeDTO.js +41 -0
  20. package/dist/esm/dtos/RunScriptDTO.js +33 -0
  21. package/dist/esm/dtos/VersionDTO.js +29 -0
  22. package/dist/esm/lib/AddPackage.js +487 -0
  23. package/dist/esm/lib/Builder.js +21 -0
  24. package/dist/esm/lib/Clean.js +146 -0
  25. package/dist/esm/lib/Environment.js +11 -0
  26. package/dist/esm/lib/I18n.js +67 -0
  27. package/dist/esm/lib/Language.js +24 -0
  28. package/dist/esm/lib/Migration.js +94 -0
  29. package/dist/esm/lib/Output.js +40 -0
  30. package/dist/esm/lib/Processes.js +54 -0
  31. package/dist/esm/lib/ProjectCreator.js +191 -0
  32. package/dist/esm/lib/Registry.js +152 -0
  33. package/dist/esm/lib/Settings.js +25 -0
  34. package/dist/esm/lib/Tar.js +145 -0
  35. package/dist/esm/lib/TemplateCatalog.js +195 -0
  36. package/dist/esm/lib/TemplateFeatures.js +141 -0
  37. package/dist/esm/lib/Versions.js +58 -0
  38. package/dist/esm/lib/native/CMake.js +357 -0
  39. package/dist/esm/lib/native/Gyp.js +398 -0
  40. package/dist/esm/lib/native/NativeProject.js +370 -0
  41. package/dist/esm/lib/native/TextEdits.js +68 -0
  42. package/dist/esm/lib/native/Toml.js +325 -0
  43. package/dist/esm/lib/workspace/Run.js +111 -0
  44. package/dist/esm/lib/workspace/Version.js +144 -0
  45. package/dist/esm/lib/workspace/Workspace.js +231 -0
  46. package/dist/esm/locales/zh-CN.json +194 -0
  47. package/dist/esm/locales/zh-TW.json +194 -0
  48. package/dist/esm/types/ProcessResult.js +1 -0
  49. package/package.json +32 -43
  50. package/CHANGELOG.md +0 -452
  51. package/dist/CLIApp.d.ts +0 -3
  52. package/dist/CLIApp.d.ts.map +0 -1
  53. package/dist/CLIApp.js +0 -45
  54. package/dist/config/Config.d.ts +0 -3
  55. package/dist/config/Config.d.ts.map +0 -1
  56. package/dist/config/Config.js +0 -63
  57. package/dist/config/SetupCLIEntrypoint.d.ts +0 -3
  58. package/dist/config/SetupCLIEntrypoint.d.ts.map +0 -1
  59. package/dist/config/SetupCLIEntrypoint.js +0 -31
  60. package/dist/controllers/CommandLineController.d.ts +0 -25
  61. package/dist/controllers/CommandLineController.d.ts.map +0 -1
  62. package/dist/controllers/CommandLineController.js +0 -78
  63. package/dist/lib/ConvertDTO2Inquirer.d.ts +0 -3
  64. package/dist/lib/ConvertDTO2Inquirer.d.ts.map +0 -1
  65. package/dist/lib/ConvertDTO2Inquirer.js +0 -61
  66. package/dist/lib/GetDataDirectory.d.ts +0 -2
  67. package/dist/lib/GetDataDirectory.d.ts.map +0 -1
  68. package/dist/lib/GetDataDirectory.js +0 -11
  69. package/dist/lib/GetLocalDataFilename.d.ts +0 -2
  70. package/dist/lib/GetLocalDataFilename.d.ts.map +0 -1
  71. package/dist/lib/GetLocalDataFilename.js +0 -12
  72. package/dist/lib/ListTemplateNames.d.ts +0 -2
  73. package/dist/lib/ListTemplateNames.d.ts.map +0 -1
  74. package/dist/lib/ListTemplateNames.js +0 -44
  75. package/dist/lib/SpecialChar.d.ts +0 -9
  76. package/dist/lib/SpecialChar.d.ts.map +0 -1
  77. package/dist/lib/SpecialChar.js +0 -11
  78. package/dist/lib/components/DeGitPuller.d.ts +0 -19
  79. package/dist/lib/components/DeGitPuller.d.ts.map +0 -1
  80. package/dist/lib/components/DeGitPuller.js +0 -65
  81. package/dist/lib/components/Spinner.d.ts +0 -23
  82. package/dist/lib/components/Spinner.d.ts.map +0 -1
  83. package/dist/lib/components/Spinner.js +0 -61
  84. package/dist/lib/providers/Creator.d.ts +0 -46
  85. package/dist/lib/providers/Creator.d.ts.map +0 -1
  86. package/dist/lib/providers/Creator.js +0 -179
  87. package/dist/lib/providers/Information.d.ts +0 -91
  88. package/dist/lib/providers/Information.d.ts.map +0 -1
  89. package/dist/lib/providers/Information.js +0 -225
  90. package/dist/lib/providers/OnlineLatestVersion.d.ts +0 -14
  91. package/dist/lib/providers/OnlineLatestVersion.d.ts.map +0 -1
  92. package/dist/lib/providers/OnlineLatestVersion.js +0 -47
  93. package/dist/lib/providers/TemplateManager.d.ts +0 -36
  94. package/dist/lib/providers/TemplateManager.d.ts.map +0 -1
  95. package/dist/lib/providers/TemplateManager.js +0 -164
  96. package/dist/options/CreateProjectOptions.d.ts +0 -15
  97. package/dist/options/CreateProjectOptions.d.ts.map +0 -1
  98. package/dist/options/CreateProjectOptions.js +0 -94
  99. package/dist/options/ListTemplatesOptions.d.ts +0 -5
  100. package/dist/options/ListTemplatesOptions.d.ts.map +0 -1
  101. package/tsconfig.json +0 -7
@@ -0,0 +1,180 @@
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 path from 'node:path';
11
+ import { Controller } from 'lakutata/com/entrypoint';
12
+ import { CLIAction } from 'lakutata/decorator/ctrl';
13
+ import { Inject } from 'lakutata/decorator/di';
14
+ import { Translator } from 'lakutata/com/i18n';
15
+ import { CreateProjectDTO } from '../dtos/CreateProjectDTO.js';
16
+ import { ListTemplatesDTO } from '../dtos/ListTemplatesDTO.js';
17
+ import { CleanDTO } from '../dtos/CleanDTO.js';
18
+ import { clean, outputDirectories } from '../lib/Clean.js';
19
+ import { TemplateCatalog } from '../lib/TemplateCatalog.js';
20
+ import { ProjectCreator } from '../lib/ProjectCreator.js';
21
+ import { detectPackageManager } from '../lib/Processes.js';
22
+ import { done, styled, table } from '../lib/Output.js';
23
+ import { frameworkVersion, latestVersion, projectFrameworkVersion, toolPackage } from '../lib/Versions.js';
24
+ import { localize } from '../lib/Language.js';
25
+ /**
26
+ * Whether the tool runs in a terminal, where it asks the questions
27
+ */
28
+ function interactive() {
29
+ return !!process.stdin.isTTY && !!process.stdout.isTTY;
30
+ }
31
+ export class CommandLineController extends Controller {
32
+ async create(input) {
33
+ const template = await this.catalog.resolve(input.template);
34
+ const directory = input.init ? path.resolve(input.path) : path.resolve(input.path, input.name);
35
+ await this.creator.checkDirectory(directory, input.init);
36
+ const prepared = await this.creator.prepare(template);
37
+ try {
38
+ return await this.createFrom(input, template, prepared, directory);
39
+ }
40
+ finally {
41
+ await prepared.cleanup();
42
+ }
43
+ }
44
+ /**
45
+ * The features of the template enabled: the ones of --with, or the ones chosen in a terminal
46
+ * @param input
47
+ * @param template
48
+ */
49
+ async features(input, template) {
50
+ const available = Object.keys(template.features);
51
+ if (input.with !== undefined) {
52
+ const features = [...new Set(input.with.split(',').map((feature) => feature.trim()).filter(Boolean))];
53
+ const unknown = features.filter((feature) => !available.includes(feature));
54
+ if (unknown.length)
55
+ throw new Error(`The template has no feature ${unknown.join(', ')} (${available.length ? `its features: ${available.join(', ')}` : 'it has no feature'})`);
56
+ return features;
57
+ }
58
+ if (!available.length || !interactive() || input.yes)
59
+ return [];
60
+ const { checkbox } = await import('@inquirer/prompts');
61
+ return await checkbox({
62
+ message: localize(this.i18n, 'prompts.features', 'The features of the project'),
63
+ choices: available.map((feature) => ({ name: `${feature}: ${template.features[feature]}`, value: feature }))
64
+ });
65
+ }
66
+ /**
67
+ * Create a project from its template
68
+ * @param input
69
+ * @param template
70
+ * @param prepared
71
+ * @param directory
72
+ */
73
+ async createFrom(input, template, prepared, directory) {
74
+ const features = await this.features(input, prepared);
75
+ const plan = {
76
+ name: input.name,
77
+ id: input.id ?? input.name.toLowerCase(),
78
+ description: input.description,
79
+ author: input.author,
80
+ license: input.license,
81
+ template: template,
82
+ directory: directory,
83
+ init: input.init,
84
+ packageManager: input.packageManager ?? detectPackageManager(),
85
+ git: input.git,
86
+ features: features
87
+ };
88
+ const say = (key, text, params) => localize(this.i18n, key, text, params);
89
+ process.stdout.write(table([
90
+ [say('plan.name', 'Name'), plan.name],
91
+ [say('plan.id', 'ID'), plan.id],
92
+ [say('plan.description', 'Description'), plan.description || '-'],
93
+ [say('plan.author', 'Author'), plan.author || '-'],
94
+ [say('plan.license', 'License'), plan.license],
95
+ [say('plan.template', 'Template'), input.template],
96
+ ...(Object.keys(prepared.features).length ? [[say('plan.features', 'Features'), features.length ? features.join(', ') : say('plan.none', 'none')]] : []),
97
+ [say('plan.directory', 'Directory'), directory],
98
+ [say('plan.dependencies', 'Dependencies'), plan.packageManager === 'none' ? say('plan.notInstalled', 'not installed') : say('plan.installed', 'installed with {manager}', { manager: plan.packageManager })],
99
+ [say('plan.git', 'Git'), plan.git ? say('plan.initialized', 'initialized') : say('plan.notInitialized', 'not initialized')]
100
+ ], say('plan.title', 'The project')));
101
+ if (interactive() && !input.yes) {
102
+ const { confirm } = await import('@inquirer/prompts');
103
+ if (!await confirm({ message: say('prompts.create', 'Create the project?'), default: true }))
104
+ return say('prompts.notCreated', 'The project is not created');
105
+ }
106
+ await this.creator.create(plan, prepared);
107
+ //The path of the project from the current directory, or its absolute path when it is elsewhere
108
+ const relative = path.relative(process.cwd(), directory);
109
+ const location = !relative || relative.startsWith('..') ? directory : relative;
110
+ return `\n${styled('green', 'The project is created')} in ${directory}\n${relative ? `\n cd ${location}\n` : ''}`;
111
+ }
112
+ async templates(input) {
113
+ const templates = await this.catalog.list(input.refresh);
114
+ return `${table(templates.map((template) => [template.name, `${template.description}${template.features?.length ? ` (features: ${template.features.join(', ')})` : ''}`]), 'The templates (lakutata create --template <name>)')}
115
+ Other templates: --template npm:<package>, github:<owner>/<repo>, or a directory
116
+ The features of a template are enabled by lakutata create --with <features>
117
+ `;
118
+ }
119
+ async clean(input) {
120
+ const directory = process.cwd();
121
+ const paths = input.paths?.length ? input.paths : await outputDirectories(directory);
122
+ const result = await clean(directory, paths);
123
+ done(result.removed.length ? `Removed ${result.removed.join(', ')}` : `Nothing to remove (${result.missing.join(', ')})`);
124
+ return undefined;
125
+ }
126
+ async info() {
127
+ const tool = toolPackage();
128
+ const [latestTool, latestFramework] = await Promise.all([latestVersion(tool.name), latestVersion('lakutata')]);
129
+ const project = await projectFrameworkVersion(process.cwd());
130
+ const latest = (version) => version ? ` (latest ${version})` : '';
131
+ const rows = [
132
+ ['Tool', `${tool.name} ${tool.version}${latest(latestTool)}`],
133
+ ['Framework', `lakutata ${frameworkVersion()}${latest(latestFramework)}`],
134
+ ['Node.js', `${process.version} (${process.platform} ${process.arch})`]
135
+ ];
136
+ if (project)
137
+ rows.push(['Project', `${project.project}: lakutata ${project.installed ?? 'not installed'} (${project.declared})`]);
138
+ return table(rows);
139
+ }
140
+ }
141
+ __decorate([
142
+ Inject(TemplateCatalog),
143
+ __metadata("design:type", TemplateCatalog)
144
+ ], CommandLineController.prototype, "catalog", void 0);
145
+ __decorate([
146
+ Inject(ProjectCreator),
147
+ __metadata("design:type", ProjectCreator
148
+ /**
149
+ * The prompts in the language of the user
150
+ */
151
+ )
152
+ ], CommandLineController.prototype, "creator", void 0);
153
+ __decorate([
154
+ Inject(Translator),
155
+ __metadata("design:type", Translator)
156
+ ], CommandLineController.prototype, "i18n", void 0);
157
+ __decorate([
158
+ CLIAction('create', CreateProjectDTO, { description: 'Create a lakutata project from a template' }),
159
+ __metadata("design:type", Function),
160
+ __metadata("design:paramtypes", [CreateProjectDTO]),
161
+ __metadata("design:returntype", Promise)
162
+ ], CommandLineController.prototype, "create", null);
163
+ __decorate([
164
+ CLIAction('templates', ListTemplatesDTO, { description: 'List the project templates' }),
165
+ __metadata("design:type", Function),
166
+ __metadata("design:paramtypes", [ListTemplatesDTO]),
167
+ __metadata("design:returntype", Promise)
168
+ ], CommandLineController.prototype, "templates", null);
169
+ __decorate([
170
+ CLIAction('clean [paths...]', CleanDTO, { description: 'Remove paths of the package of the current directory, on every platform (the outDir of its tsconfig.json by default)' }),
171
+ __metadata("design:type", Function),
172
+ __metadata("design:paramtypes", [CleanDTO]),
173
+ __metadata("design:returntype", Promise)
174
+ ], CommandLineController.prototype, "clean", null);
175
+ __decorate([
176
+ CLIAction('info', { description: 'Show the versions of the tool and of the framework' }),
177
+ __metadata("design:type", Function),
178
+ __metadata("design:paramtypes", []),
179
+ __metadata("design:returntype", Promise)
180
+ ], CommandLineController.prototype, "info", null);
@@ -0,0 +1,67 @@
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 { mkdir, writeFile } from 'node:fs/promises';
11
+ import path from 'node:path';
12
+ import { Controller } from 'lakutata/com/entrypoint';
13
+ import { CLIAction } from 'lakutata/decorator/ctrl';
14
+ import { checkCatalogs, generateMessageTypes, loadCatalogs } from 'lakutata/com/i18n';
15
+ import { I18nDTO } from '../dtos/I18nDTO.js';
16
+ import { done, styled, warn } from '../lib/Output.js';
17
+ import { addLocale } from '../lib/I18n.js';
18
+ /**
19
+ * The commands of the messages of the languages (lakutata/com/i18n)
20
+ */
21
+ export class I18nController extends Controller {
22
+ async i18n(input) {
23
+ const directories = input.dir.split(',').map((directory) => path.resolve(directory.trim())).filter(Boolean);
24
+ const relative = (file) => path.relative(process.cwd(), file) || '.';
25
+ switch (input.action) {
26
+ case 'check': {
27
+ const catalogs = await loadCatalogs(directories);
28
+ const issues = checkCatalogs(catalogs, input.default);
29
+ for (const issue of issues) {
30
+ const where = issue.key ? `${issue.locale} ${issue.key}` : issue.locale;
31
+ process.stdout.write(`${issue.level === 'error' ? styled('red', '✖') : styled('yellow', '!')} ${styled('bold', where)}: ${issue.message}\n`);
32
+ }
33
+ const errors = issues.filter((issue) => issue.level === 'error').length;
34
+ const warnings = issues.length - errors;
35
+ const summary = `${catalogs.size} language${catalogs.size === 1 ? '' : 's'} (${[...catalogs.keys()].sort().join(', ')}), ${errors} error${errors === 1 ? '' : 's'}, ${warnings} warning${warnings === 1 ? '' : 's'}`;
36
+ if (errors || (input.strict && warnings))
37
+ throw new Error(`The messages have problems: ${summary}`);
38
+ done(`Messages checked: ${summary}`);
39
+ return undefined;
40
+ }
41
+ case 'types': {
42
+ const declaration = generateMessageTypes(await loadCatalogs(directories), input.default, input.module);
43
+ const file = path.resolve(input.out);
44
+ await mkdir(path.dirname(file), { recursive: true });
45
+ await writeFile(file, declaration);
46
+ done(`Types of the messages of ${input.default} declared: ${relative(file)}`);
47
+ return undefined;
48
+ }
49
+ case 'add': {
50
+ if (!input.locale)
51
+ throw new Error('The language is required: lakutata i18n add <locale>');
52
+ if (directories.length !== 1)
53
+ throw new Error('A language is added to one directory (--dir)');
54
+ const files = await addLocale(directories[0], input.locale, input.default);
55
+ done(`Messages of ${input.locale} added: ${files.map(relative).join(', ')}`);
56
+ warn(`They are the messages of ${input.default}: translate them (lakutata i18n check tells the ones which are not)`);
57
+ return undefined;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ __decorate([
63
+ CLIAction('i18n <action> [locale]', I18nDTO, { description: 'Check the messages of the languages, declare the types of their keys, or add a language' }),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [I18nDTO]),
66
+ __metadata("design:returntype", Promise)
67
+ ], I18nController.prototype, "i18n", null);
@@ -0,0 +1,66 @@
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 path from 'node:path';
11
+ import { Controller } from 'lakutata/com/entrypoint';
12
+ import { CLIAction } from 'lakutata/decorator/ctrl';
13
+ import { MigrationDTO } from '../dtos/MigrationDTO.js';
14
+ import { done } from '../lib/Output.js';
15
+ import { createMigration, executeMigrations, generateMigrations } from '../lib/Migration.js';
16
+ import { Workspace } from '../lib/workspace/Workspace.js';
17
+ /**
18
+ * The commands of the migrations of the databases of the application
19
+ */
20
+ export class MigrationController extends Controller {
21
+ async migration(input) {
22
+ let directory = process.cwd();
23
+ if (input.package) {
24
+ const workspace = await Workspace.find();
25
+ const pkg = workspace.packages.find((candidate) => candidate.name === input.package);
26
+ if (!pkg)
27
+ throw new Error(`The workspace has no package ${input.package} (${workspace.packages.map((candidate) => candidate.name).join(', ')})`);
28
+ directory = pkg.directory;
29
+ }
30
+ const relative = (file) => path.relative(process.cwd(), path.join(directory, file));
31
+ switch (input.action) {
32
+ case 'create': {
33
+ if (!input.name)
34
+ throw new Error('The name of the migration is required: lakutata migration create <name>');
35
+ const file = await createMigration({ directory: directory, dir: input.dir, name: input.name });
36
+ done(`Migration created: ${relative(file)} (given to the migrations of the options of its database)`);
37
+ return undefined;
38
+ }
39
+ case 'generate': {
40
+ const result = await generateMigrations({ directory: directory, dir: input.dir, script: input.script, database: input.database });
41
+ if (result.files.length) {
42
+ done(`Migrations generated: ${result.files.map(relative).join(', ')}`);
43
+ return undefined;
44
+ }
45
+ //The application tells why (no change of the schema, the failure)
46
+ if (result.code !== 0)
47
+ throw new Error(`No migration generated (the application exited with the code ${result.code})`);
48
+ done('No migration generated: the application has no Database component or provider');
49
+ return undefined;
50
+ }
51
+ default: {
52
+ //The application tells what it did
53
+ const code = await executeMigrations({ directory: directory, script: input.script, database: input.database, action: input.action, transaction: input.transaction, fake: input.fake });
54
+ if (code !== 0)
55
+ throw new Error(`The command ${input.action} of the migrations failed (the application exited with the code ${code})`);
56
+ return undefined;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ __decorate([
62
+ CLIAction('migration <action> [name]', MigrationDTO, { description: 'Generate, create, run, revert or show the migrations of the databases of the application' }),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [MigrationDTO]),
65
+ __metadata("design:returntype", Promise)
66
+ ], MigrationController.prototype, "migration", null);
@@ -0,0 +1,41 @@
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 { Controller } from 'lakutata/com/entrypoint';
11
+ import { CLIAction } from 'lakutata/decorator/ctrl';
12
+ import { NativeDTO } from '../dtos/NativeDTO.js';
13
+ import { done, warn } from '../lib/Output.js';
14
+ import { changeNative } from '../lib/native/NativeProject.js';
15
+ /**
16
+ * The commands of the native addons: the libraries, the headers and the macros of their builds
17
+ */
18
+ export class NativeController extends Controller {
19
+ async native(input) {
20
+ const result = await changeNative(process.cwd(), {
21
+ action: input.action,
22
+ value: input.value,
23
+ platform: input.platform,
24
+ pkgConfig: input.pkgConfig,
25
+ framework: input.framework,
26
+ crate: input.crate,
27
+ target: input.target
28
+ });
29
+ const what = { link: 'Linked', include: 'Included', define: 'Defined' }[input.action];
30
+ done(result.files.length ? `${what} ${input.value} (${result.build}): ${result.files.join(', ')}` : `${input.value} is already in the build (${result.build}): nothing changed`);
31
+ for (const note of result.notes)
32
+ warn(note);
33
+ return undefined;
34
+ }
35
+ }
36
+ __decorate([
37
+ CLIAction('native <action> <value>', NativeDTO, { description: 'Change the build of the native addon of the current directory (binding.gyp, CMakeLists.txt, Cargo.toml): link a library, include headers, define a macro' }),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", [NativeDTO]),
40
+ __metadata("design:returntype", Promise)
41
+ ], NativeController.prototype, "native", null);
@@ -0,0 +1,88 @@
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 path from 'node:path';
11
+ import { Controller } from 'lakutata/com/entrypoint';
12
+ import { CLIAction } from 'lakutata/decorator/ctrl';
13
+ import { BundleDTO } from '../dtos/BundleDTO.js';
14
+ import { ExecutableDTO } from '../dtos/ExecutableDTO.js';
15
+ import { InstallerDTO } from '../dtos/InstallerDTO.js';
16
+ import { loadBuilder } from '../lib/Builder.js';
17
+ import { done, step, warn } from '../lib/Output.js';
18
+ /**
19
+ * A size in megabytes
20
+ * @param size
21
+ */
22
+ function megabytes(size) {
23
+ return `${(size / 1024 / 1024).toFixed(1)} MB`;
24
+ }
25
+ /**
26
+ * The commands packing the application of the current directory (lakutata package): into one JavaScript file, into an
27
+ * executable, or into its installers
28
+ */
29
+ export class PackController extends Controller {
30
+ async bundle(input) {
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 });
33
+ done(`${path.relative(process.cwd(), result.outfile)} (${megabytes(result.size)}): node ${path.relative(process.cwd(), result.outfile)}`);
34
+ //The native addons are next to the bundle, which is distributed with them
35
+ if (result.nativeDirectory)
36
+ done(`${path.relative(process.cwd(), result.nativeDirectory)}: the native addons (${result.native.modules.join(', ') || 'of the application'}), distributed with the bundle`);
37
+ if (result.resourcesDirectory)
38
+ done(`${path.relative(process.cwd(), result.resourcesDirectory)}: the resources (${result.resources.join(', ')}), distributed with the bundle`);
39
+ return undefined;
40
+ }
41
+ async executable(input) {
42
+ const { buildExecutable } = await loadBuilder(process.cwd());
43
+ 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 });
44
+ step(`${result.runtime} embedded`);
45
+ if (result.native.length)
46
+ step(result.directory ? `Native addons next to the executable: ${result.native.join(', ')}` : `Native addons embedded, extracted at the first run: ${result.native.join(', ')}`);
47
+ if (result.resources.length)
48
+ step(result.directory ? `Resources next to the executable: ${result.resources.join(', ')}` : `Resources embedded, extracted at the first run: ${result.resources.join(', ')}`);
49
+ for (const warning of result.warnings)
50
+ warn(warning);
51
+ if (result.directory)
52
+ done(`${path.relative(process.cwd(), result.directory)}: the executable and what it loads, distributed together`);
53
+ done(`${path.relative(process.cwd(), result.file)} (${result.platform}, ${megabytes(result.size)})`);
54
+ return undefined;
55
+ }
56
+ async installer(input) {
57
+ const { buildInstaller } = await loadBuilder(process.cwd());
58
+ const result = await buildInstaller({ project: process.cwd(), targets: input.target, outdir: input.outdir, entry: input.entry, minify: input.minify, external: input.external });
59
+ step(`${result.executable.runtime} embedded`);
60
+ if (result.executable.native.length)
61
+ step(`Native addons: ${result.executable.native.join(', ')}`);
62
+ if (result.executable.resources.length)
63
+ step(`Resources: ${result.executable.resources.join(', ')}`);
64
+ for (const warning of result.warnings)
65
+ warn(warning);
66
+ for (const file of result.files)
67
+ done(`${path.relative(process.cwd(), file.file)} (${file.target}, ${megabytes(file.size)})`);
68
+ return undefined;
69
+ }
70
+ }
71
+ __decorate([
72
+ CLIAction('package bundle', BundleDTO, { description: 'Bundle the compiled application and its dependencies into one file run by node' }),
73
+ __metadata("design:type", Function),
74
+ __metadata("design:paramtypes", [BundleDTO]),
75
+ __metadata("design:returntype", Promise)
76
+ ], PackController.prototype, "bundle", null);
77
+ __decorate([
78
+ CLIAction('package exe', ExecutableDTO, { description: 'Make the executable of the compiled application for this platform, which runs without Node.js installed' }),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [ExecutableDTO]),
81
+ __metadata("design:returntype", Promise)
82
+ ], PackController.prototype, "executable", null);
83
+ __decorate([
84
+ CLIAction('package installer', InstallerDTO, { description: 'Make the installers of the compiled application for this platform: its executable, its native addons and its resources installed, its program in the PATH, its service registered' }),
85
+ __metadata("design:type", Function),
86
+ __metadata("design:paramtypes", [InstallerDTO]),
87
+ __metadata("design:returntype", Promise)
88
+ ], PackController.prototype, "installer", null);
@@ -0,0 +1,91 @@
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 path from 'node:path';
11
+ import { Controller } from 'lakutata/com/entrypoint';
12
+ import { CLIAction } from 'lakutata/decorator/ctrl';
13
+ import { RunScriptDTO } from '../dtos/RunScriptDTO.js';
14
+ import { VersionDTO } from '../dtos/VersionDTO.js';
15
+ import { AddPackageDTO } from '../dtos/AddPackageDTO.js';
16
+ import { addPackage } from '../lib/AddPackage.js';
17
+ import { done, styled, table } from '../lib/Output.js';
18
+ import { Workspace } from '../lib/workspace/Workspace.js';
19
+ import { runScript } from '../lib/workspace/Run.js';
20
+ import { applyVersion, planVersion } from '../lib/workspace/Version.js';
21
+ import { Inject } from 'lakutata/decorator/di';
22
+ import { Translator } from 'lakutata/com/i18n';
23
+ import { localize } from '../lib/Language.js';
24
+ /**
25
+ * The commands of the workspaces: the packages of a project (app, ui, proxy…) built in the order of their dependencies, and given a same version
26
+ */
27
+ export class WorkspaceController extends Controller {
28
+ async run(input) {
29
+ const workspace = await Workspace.find();
30
+ const result = await runScript(workspace, input.script, { concurrency: input.concurrency, bail: input.bail, parallel: input.parallel, scope: input.scope });
31
+ if (!result.ran.length)
32
+ return `No package has the script ${input.script}`;
33
+ done(`${input.script} ran in ${result.ran.join(', ')}`);
34
+ return undefined;
35
+ }
36
+ async version(input) {
37
+ const workspace = await Workspace.find();
38
+ const plan = planVersion(workspace, input.bump, input.preid);
39
+ process.stdout.write(table(plan.packages.map(({ name, from }) => [name, `${from ?? '-'} → ${plan.to}`]), localize(this.i18n, 'plan.version', 'Version {from} → {to}', { from: plan.from, to: styled('green', plan.to) })));
40
+ if (process.stdin.isTTY && process.stdout.isTTY && !input.yes) {
41
+ const { confirm } = await import('@inquirer/prompts');
42
+ if (!await confirm({ message: localize(this.i18n, 'prompts.version', 'Give this version?'), default: true }))
43
+ return localize(this.i18n, 'prompts.notVersioned', 'The version is not changed');
44
+ }
45
+ const files = await applyVersion(workspace, plan, { preid: input.preid, git: input.git });
46
+ done(`Version ${plan.to} given (${files.map((file) => path.relative(workspace.root, file)).join(', ')})${input.git ? `, committed and tagged v${plan.to}` : ''}`);
47
+ return undefined;
48
+ }
49
+ async add(input) {
50
+ const native = input.native === true ? 'gyp' : input.native || undefined;
51
+ const result = await addPackage({ name: input.name, native: native, to: input.to });
52
+ done(`${native ? `Native addon (${native})` : 'Package'} ${input.name} ${result.version} added: ${path.relative(process.cwd(), result.directory) || '.'} (${result.files.join(', ')})${result.to ? `, a dependency of ${result.to}` : ''}`);
53
+ process.stdout.write(`Next: npm install (links the package${native ? ', builds the addon' : ''}), then npm run rebuild -w ${input.name}\n`);
54
+ return undefined;
55
+ }
56
+ async list() {
57
+ const workspace = await Workspace.find();
58
+ return table(workspace.packages.map((pkg) => [
59
+ pkg.name,
60
+ `${pkg.version ?? '-'}${pkg.private ? ' (private)' : ''} ${path.relative(workspace.root, pkg.directory)}${pkg.dependencies.length ? ` → ${pkg.dependencies.join(', ')}` : ''}`
61
+ ]), `${workspace.packages.length} packages, version ${workspace.version ?? '-'}`);
62
+ }
63
+ }
64
+ __decorate([
65
+ Inject(Translator),
66
+ __metadata("design:type", Translator)
67
+ ], WorkspaceController.prototype, "i18n", void 0);
68
+ __decorate([
69
+ CLIAction('run <script>', RunScriptDTO, { description: 'Run a script in the packages of the workspace, in the order of their dependencies' }),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [RunScriptDTO]),
72
+ __metadata("design:returntype", Promise)
73
+ ], WorkspaceController.prototype, "run", null);
74
+ __decorate([
75
+ CLIAction('version <bump>', VersionDTO, { description: 'Give the packages of the workspace their next version, and update the dependencies between them' }),
76
+ __metadata("design:type", Function),
77
+ __metadata("design:paramtypes", [VersionDTO]),
78
+ __metadata("design:returntype", Promise)
79
+ ], WorkspaceController.prototype, "version", null);
80
+ __decorate([
81
+ CLIAction('add <name>', AddPackageDTO, { description: 'Add a package to the workspace (packages/<name>): TypeScript, or a native addon with --native [gyp|cmake|rust]' }),
82
+ __metadata("design:type", Function),
83
+ __metadata("design:paramtypes", [AddPackageDTO]),
84
+ __metadata("design:returntype", Promise)
85
+ ], WorkspaceController.prototype, "add", null);
86
+ __decorate([
87
+ CLIAction('list', { description: 'List the packages of the workspace' }),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", []),
90
+ __metadata("design:returntype", Promise)
91
+ ], WorkspaceController.prototype, "list", null);
@@ -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 AddPackageDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().required().description('The name of the package (packages/<name> of the workspace)')),
16
+ __metadata("design:type", String)
17
+ ], AddPackageDTO.prototype, "name", void 0);
18
+ __decorate([
19
+ Expect(DTO.Alternatives(DTO.Boolean(), DTO.String().valid('gyp', 'cmake', 'rust')).optional().default(false).description('A native addon, by its build system: gyp (C++, node-gyp, by default), cmake (C++, cmake-js) or rust (napi-rs)')),
20
+ __metadata("design:type", Object)
21
+ ], AddPackageDTO.prototype, "native", void 0);
22
+ __decorate([
23
+ Expect(DTO.String().optional().description('The package of the workspace depending on it')),
24
+ __metadata("design:type", String)
25
+ ], AddPackageDTO.prototype, "to", void 0);
@@ -0,0 +1,29 @@
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 BundleDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.String().optional().description('The compiled entry of the application (the "main" of the package.json by default)')),
16
+ __metadata("design:type", String)
17
+ ], BundleDTO.prototype, "entry", void 0);
18
+ __decorate([
19
+ Expect(DTO.String().optional().description('The bundle (dist/<name>.cjs by default)')),
20
+ __metadata("design:type", String)
21
+ ], BundleDTO.prototype, "outfile", void 0);
22
+ __decorate([
23
+ Expect(DTO.Boolean().optional().default(true).description('Minify the bundle')),
24
+ __metadata("design:type", Boolean)
25
+ ], BundleDTO.prototype, "minify", void 0);
26
+ __decorate([
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
+ __metadata("design:type", Array)
29
+ ], BundleDTO.prototype, "external", 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 CleanDTO extends DTO {
13
+ }
14
+ __decorate([
15
+ Expect(DTO.Array(DTO.String()).optional().description('The paths removed, relative to the package (the outDir and the declarationDir of its tsconfig.json by default)')),
16
+ __metadata("design:type", Array)
17
+ ], CleanDTO.prototype, "paths", void 0);