@nu-art/build-and-install 0.204.92 → 0.204.93

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 (34) hide show
  1. package/build-and-install.js +0 -3
  2. package/package.json +1 -1
  3. package/v2/phase-runner/PhaseRunner.js +3 -3
  4. package/v2/unit/core/BaseUnit.d.ts +11 -4
  5. package/v2/unit/core/BaseUnit.js +53 -5
  6. package/v2/unit/core/Unit_Python.d.ts +0 -4
  7. package/v2/unit/core/Unit_Python.js +5 -19
  8. package/v2/unit/core/Unit_Typescript.js +3 -3
  9. package/v2/unit/core/Unit_TypescriptLib.js +13 -21
  10. package/v2/unit/core/Unit_TypescriptProject.js +16 -8
  11. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.js +17 -28
  12. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.js +13 -19
  13. package/v2/unit/tools/tools.d.ts +2 -0
  14. package/v2/unit/tools/tools.js +16 -0
  15. package/logic/ProjectManager.d.ts +0 -49
  16. package/logic/ProjectManager.js +0 -271
  17. package/logic/command-executors/CommandExecutor_FirebaseFunction.d.ts +0 -21
  18. package/logic/command-executors/CommandExecutor_FirebaseFunction.js +0 -71
  19. package/logic/command-executors/CommandExecutor_FirebaseHosting.d.ts +0 -13
  20. package/logic/command-executors/CommandExecutor_FirebaseHosting.js +0 -48
  21. package/logic/command-executors/CommandExecutor_Python.d.ts +0 -15
  22. package/logic/command-executors/CommandExecutor_Python.js +0 -53
  23. package/logic/command-executors/index.d.ts +0 -2
  24. package/logic/command-executors/index.js +0 -18
  25. package/logic/map-project-packages.d.ts +0 -4
  26. package/logic/map-project-packages.js +0 -128
  27. package/phases/phases.d.ts +0 -24
  28. package/phases/phases.js +0 -775
  29. package/project-manager.d.ts +0 -4
  30. package/project-manager.js +0 -9
  31. package/screen/ProjectScreen.d.ts +0 -31
  32. package/screen/ProjectScreen.js +0 -140
  33. package/screen/RunningProcessLogs.d.ts +0 -17
  34. package/screen/RunningProcessLogs.js +0 -137
package/phases/phases.js DELETED
@@ -1,775 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Phase_DeployBackend = exports.Phase_DeployFrontend = exports.Phase_Launch = exports.Phase_CompileWatch = exports.Phase_Compile = exports.Phase_PreCompile = exports.Phase_PrepareCompile = exports.Phase_Debug = exports.Phase_Lint = exports.Phase_InstallPythonPackages = exports.Phase_InstallPackages = exports.Phase_InstallGlobals = exports.Phase_PackagePurge = exports.Phase_PrintEnv = exports.Phase_CheckCyclicImports = exports.Phase_PrintDependencyTree = exports.Phase_ResolvePackages = exports.Phase_ResolveEnv = exports.Phase_ResolveTemplate = exports.Phase_PrepareParams = exports.Phase_SetupProject = exports.Phase_SetWithThunderstorm = exports.Phase_PrintHelp = void 0;
27
- const ProjectManager_1 = require("../logic/ProjectManager");
28
- const map_project_packages_1 = require("../logic/map-project-packages");
29
- const fs = __importStar(require("fs"));
30
- const fs_1 = require("fs");
31
- const consts_1 = require("../core/consts");
32
- const tools_1 = require("@nu-art/commando/shell/tools");
33
- const ts_common_1 = require("@nu-art/ts-common");
34
- const types_1 = require("../core/types");
35
- const generate_1 = require("../core/package/generate");
36
- const nvm_1 = require("@nu-art/commando/cli/nvm");
37
- const params_1 = require("../core/params/params");
38
- const basic_1 = require("@nu-art/commando/cli/basic");
39
- const pnpm_1 = require("@nu-art/commando/cli/pnpm");
40
- const chokidar = __importStar(require("chokidar"));
41
- const consts_2 = require("../defaults/consts");
42
- const project_manager_1 = require("../project-manager");
43
- const ProjectScreen_1 = require("../screen/ProjectScreen");
44
- const RunningProcessLogs_1 = require("../screen/RunningProcessLogs");
45
- const command_executors_1 = require("../logic/command-executors");
46
- const CommandExecutor_Python_1 = require("../logic/command-executors/CommandExecutor_Python");
47
- const shell_1 = require("@nu-art/commando/shell");
48
- const CONST_ThunderstormVersionKey = 'THUNDERSTORM_SDK_VERSION';
49
- const CONST_ThunderstormDependencyKey = 'THUNDERSTORM_DEPENDENCY_VERSION';
50
- const CONST_ProjectVersionKey = 'APP_VERSION';
51
- const CONST_ProjectDependencyKey = 'APP_VERSION_DEPENDENCY';
52
- const CONST_TS_Config = `tsconfig.json`;
53
- const CONST_RunningRoot = process.cwd();
54
- const CONST_VersionApp = 'version-app.json';
55
- const pathToProjectTS_Config = (0, tools_1.convertToFullPath)(`./.config/${CONST_TS_Config}`);
56
- const pathToProjectEslint = (0, tools_1.convertToFullPath)('./.config/.eslintrc.js');
57
- const CommandoLibs = ['commando', 'build-and-install', 'ts-common'];
58
- exports.Phase_PrintHelp = {
59
- type: 'project',
60
- name: 'printHelp',
61
- terminatingPhase: true,
62
- filter: async () => params_1.RuntimeParams.help,
63
- action: async () => {
64
- const commando = nvm_1.NVM.createCommando(basic_1.Cli_Basic);
65
- commando.append('echo "Build and install parameters:"');
66
- //Resolve all params by group
67
- const paramsByGroup = (0, ts_common_1.reduceToMap)(params_1.AllBaiParams, param => { var _a; return (_a = param.group) !== null && _a !== void 0 ? _a : 'No Group'; }, (item, index, mapper) => {
68
- var _a, _b, _c, _d;
69
- mapper[(_a = item.group) !== null && _a !== void 0 ? _a : 'No Group'] = [...(_c = mapper[(_b = item.group) !== null && _b !== void 0 ? _b : 'No Group']) !== null && _c !== void 0 ? _c : [], item];
70
- return mapper[(_d = item.group) !== null && _d !== void 0 ? _d : 'No Group'];
71
- });
72
- (0, ts_common_1._keys)(paramsByGroup).map(paramGroup => {
73
- commando.append(`echo "${paramGroup}:" \n`);
74
- paramsByGroup[paramGroup].map(param => {
75
- commando.append(`echo "\n ${param.keys.join(' | ')} \n \t\t${param.description.trim().split('\n').join('\n\t\t')} \n"`);
76
- });
77
- });
78
- return commando.execute();
79
- }
80
- };
81
- exports.Phase_SetWithThunderstorm = {
82
- type: 'project',
83
- name: 'with-ts-home',
84
- isMandatory: true,
85
- action: async () => {
86
- var _a;
87
- // set value of the running with infra flag
88
- if (params_1.RuntimeParams.runWithThunderstorm)
89
- return;
90
- // Remove all the infra packages from the runtime project
91
- const packages = consts_1.MemKey_Packages.get();
92
- const filter = (pkg) => pkg.type !== types_1.PackageType_InfraLib || (params_1.RuntimeParams.withCommando && CommandoLibs.includes(pkg.name));
93
- packages.packages = packages.packages.filter(filter);
94
- packages.packagesDependency = (_a = packages.packagesDependency) === null || _a === void 0 ? void 0 : _a.map(_packageArray => _packageArray.filter(filter));
95
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
96
- if (!projectScreen.getPackageData().length) {
97
- packages.packagesDependency.map(packages => packages.map(pkg => projectScreen.updateOrCreatePackage(pkg.name, 'Initiated')));
98
- }
99
- }
100
- };
101
- exports.Phase_SetupProject = {
102
- type: 'project',
103
- name: 'setup-project',
104
- isMandatory: true,
105
- action: async () => {
106
- const thunderstormVersionJson = require((0, tools_1.convertToFullPath)('./version-thunderstorm.json'));
107
- const packages = consts_1.MemKey_Packages.get();
108
- packages.params[CONST_ThunderstormVersionKey] = thunderstormVersionJson.version;
109
- packages.params[CONST_ThunderstormDependencyKey] = `~${thunderstormVersionJson.version}`;
110
- const projectVersionJson = require((0, tools_1.convertToFullPath)('./version-app.json'));
111
- packages.params[CONST_ProjectVersionKey] = projectVersionJson.version;
112
- packages.params[CONST_ProjectDependencyKey] = projectVersionJson.version;
113
- }
114
- };
115
- exports.Phase_PrepareParams = {
116
- type: 'package',
117
- name: 'prepare-params',
118
- isMandatory: true,
119
- breakAfterPhase: true,
120
- mandatoryPhases: [exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
121
- filter: async (pkg) => pkg.type !== types_1.PackageType_Python,
122
- action: async (pkg) => {
123
- const packages = consts_1.MemKey_Packages.get();
124
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
125
- projectScreen.updateOrCreatePackage(pkg.name, 'Preparing Pramas');
126
- // with workspace: *
127
- const tempPackageJson = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
128
- const toRet = packages.params[key] ? 'workspace:*' : packages.params[value];
129
- return toRet;
130
- });
131
- // placed package name to version
132
- packages.params[tempPackageJson.name] = tempPackageJson.version;
133
- packages.params[`${tempPackageJson.name}_path`] = `file:.dependencies/${pkg.name}`;
134
- projectScreen.updateOrCreatePackage(pkg.name, 'Pramas Prepared');
135
- }
136
- };
137
- exports.Phase_ResolveTemplate = {
138
- type: 'package',
139
- name: 'resolve-template',
140
- isMandatory: true,
141
- mandatoryPhases: [exports.Phase_PrepareParams, exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
142
- action: async (pkg) => {
143
- if (pkg.type === types_1.PackageType_Python)
144
- return;
145
- const packages = consts_1.MemKey_Packages.get();
146
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
147
- projectScreen.updateOrCreatePackage(pkg.name, 'Resolving Templates');
148
- // with workspace: *
149
- pkg.packageJsonWorkspace = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
150
- const toRet = packages.params[key] ? 'workspace:*' : packages.params[value];
151
- return toRet;
152
- });
153
- // placed package name to version
154
- packages.params[pkg.packageJsonWorkspace.name] = pkg.packageJsonWorkspace.version;
155
- packages.params[`${pkg.packageJsonWorkspace.name}_path`] = `file:.dependencies/${pkg.name}`;
156
- // with versions for all packages, for be output: file:.dependencies/${pkg.name}
157
- pkg.packageJsonOutput = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
158
- var _a;
159
- const toRet = (_a = packages.params[key]) !== null && _a !== void 0 ? _a : packages.params[value];
160
- return toRet;
161
- });
162
- pkg.packageJsonRuntime = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
163
- var _a, _b;
164
- const toRet = (_b = (_a = packages.params[`${key}_path`]) !== null && _a !== void 0 ? _a : packages.params[key]) !== null && _b !== void 0 ? _b : packages.params[value];
165
- return toRet;
166
- });
167
- // write final package.json to package root folder
168
- await fs_1.promises.writeFile(`${pkg.path}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonWorkspace, null, 2), { encoding: 'utf-8' });
169
- // write final package.json to package output folder
170
- if (pkg.type === 'sourceless')
171
- return;
172
- if (!fs.existsSync(pkg.output))
173
- await fs_1.promises.mkdir(pkg.output);
174
- projectScreen.updateOrCreatePackage(pkg.name, 'Resolved Templates');
175
- }
176
- };
177
- exports.Phase_ResolveEnv = {
178
- type: 'package',
179
- name: 'resolve-env',
180
- isMandatory: true,
181
- mandatoryPhases: [exports.Phase_ResolveTemplate, exports.Phase_PrepareParams, exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
182
- filter: async (pkg) => pkg.type === 'firebase-functions-app' || pkg.type === 'firebase-hosting-app',
183
- action: async (pkg) => {
184
- const firebasePkg = pkg;
185
- await fs_1.promises.writeFile(`${firebasePkg.path}/${consts_1.CONST_FirebaseRC}`, JSON.stringify((0, generate_1.createFirebaseRC)(firebasePkg, params_1.RuntimeParams.environment), null, 2), { encoding: 'utf-8' });
186
- const defaultFiles = consts_2.MemKey_DefaultFiles.get();
187
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
188
- projectScreen.updateOrCreatePackage(pkg.name, 'Resolving Env');
189
- if (pkg.type === 'firebase-hosting-app') {
190
- await (0, generate_1.writeToFile_HostingFirebaseJSON)(firebasePkg, params_1.RuntimeParams.environment);
191
- await (0, generate_1.writeToFile_HostingFirebaseConfigJSON)(firebasePkg, params_1.RuntimeParams.environment);
192
- }
193
- if (pkg.type === 'firebase-functions-app') {
194
- const firebaseFunctionPkg = firebasePkg;
195
- const pathToFirebaseConfigFolder = `${firebaseFunctionPkg.path}/${firebaseFunctionPkg.envConfig.pathToFirebaseConfig}`;
196
- if (firebasePkg.envConfig.ssl)
197
- await (0, generate_1.generateProxyFile)(firebasePkg, `${firebaseFunctionPkg.path}/src/main/proxy.ts`);
198
- try {
199
- await fs_1.promises.access(pathToFirebaseConfigFolder);
200
- }
201
- catch (e) {
202
- await fs_1.promises.mkdir(pathToFirebaseConfigFolder, { recursive: true });
203
- }
204
- await Promise.all(consts_2.Const_FirebaseConfigKeys.map(async (firebaseConfigKey) => {
205
- var _a;
206
- const pathToConfigFile = `${pathToFirebaseConfigFolder}/${consts_2.Const_FirebaseDefaultsKeyToFile[firebaseConfigKey]}`;
207
- try {
208
- await fs_1.promises.access(pathToConfigFile);
209
- }
210
- catch (e) {
211
- const path = (_a = defaultFiles.firebaseConfig) === null || _a === void 0 ? void 0 : _a[firebaseConfigKey];
212
- if (!path)
213
- return;
214
- const defaultFileContent = await fs_1.promises.readFile(path, { encoding: 'utf-8' });
215
- await fs_1.promises.writeFile(pathToConfigFile, defaultFileContent, { encoding: 'utf-8' });
216
- }
217
- }));
218
- await (0, generate_1.writeToFile_functionFirebaseConfigJSON)(firebaseFunctionPkg, params_1.RuntimeParams.environment);
219
- await (0, generate_1.writeToFile_FunctionFirebaseJSON)(firebaseFunctionPkg, params_1.RuntimeParams.environment);
220
- }
221
- projectScreen.updateOrCreatePackage(pkg.name, 'Env Resolved');
222
- }
223
- };
224
- exports.Phase_ResolvePackages = {
225
- type: 'project',
226
- name: 'setup-packages',
227
- action: async () => {
228
- }
229
- };
230
- // export const Phase_InstallNvm: BuildPhase = {
231
- // type: 'project',
232
- // name: 'install-nvm',
233
- // mandatoryPhases: [Phase_ResolveEnv],
234
- // action: async () => {
235
- // const installed = await NVM.installRequiredVersionIfNeeded();
236
- // if (!installed)
237
- // return;
238
- //
239
- // }
240
- // };
241
- exports.Phase_PrintDependencyTree = {
242
- type: ProjectManager_1.PackageBuildPhaseType_Package,
243
- name: 'print-dependency-tree',
244
- terminatingPhase: true,
245
- mandatoryPhases: [exports.Phase_ResolveEnv],
246
- filter: async (pkg) => {
247
- return params_1.RuntimeParams.dependencyTree && (0, ts_common_1.exists)(pkg.packageJsonWorkspace);
248
- },
249
- action: async (pkg) => {
250
- return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
251
- .cd(pkg.path)
252
- .append(`mkdir -p ${CONST_RunningRoot}/.trash/dependencies`)
253
- .append(`pnpm list --depth 1000 > "${CONST_RunningRoot}/.trash/dependencies/${pkg.name}.txt"`)
254
- .execute();
255
- }
256
- };
257
- exports.Phase_CheckCyclicImports = {
258
- type: ProjectManager_1.PackageBuildPhaseType_PackageWithOutput,
259
- name: 'check-cyclic-imports',
260
- terminatingPhase: true,
261
- mandatoryPhases: [exports.Phase_ResolveEnv],
262
- filter: async (pkg) => params_1.RuntimeParams.checkCyclicImports,
263
- action: async (pkg) => {
264
- if (pkg.type === types_1.PackageType_Python)
265
- return;
266
- if (!pkg.output)
267
- return;
268
- return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
269
- .cd(pkg.path)
270
- .append(`npx madge --image "./imports-${pkg.name}.svg" --circular ${pkg.output}`)
271
- .execute();
272
- }
273
- };
274
- exports.Phase_PrintEnv = {
275
- type: 'project',
276
- name: 'print-env',
277
- terminatingPhase: true,
278
- mandatoryPhases: [exports.Phase_ResolveEnv],
279
- filter: async () => params_1.RuntimeParams.printEnv,
280
- action: async () => {
281
- return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
282
- .append('npm -g list typescript eslint firebase-tools sort-package-json --depth=0')
283
- .append('echo "npm version:"; npm -v')
284
- .append('echo "node version:"; node -v')
285
- .append('echo "base version:"; bash --version')
286
- .execute();
287
- }
288
- };
289
- exports.Phase_PackagePurge = {
290
- type: ProjectManager_1.PackageBuildPhaseType_PackageWithOutput,
291
- name: 'package-purge',
292
- mandatoryPhases: [exports.Phase_ResolveEnv],
293
- filter: async (pkg) => pkg.type !== types_1.PackageType_Python && fs.existsSync(pkg.output) && params_1.RuntimeParams.purge,
294
- action: async (pkg) => {
295
- if (pkg.type === types_1.PackageType_Python)
296
- return;
297
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
298
- //Update cli ui
299
- projectScreen.updateOrCreatePackage(pkg.name, 'Purging');
300
- //Perform the action
301
- await fs_1.promises.rm(pkg.output, { recursive: true, force: true });
302
- }
303
- };
304
- exports.Phase_InstallGlobals = {
305
- type: 'project',
306
- name: 'install-globals',
307
- mandatoryPhases: [exports.Phase_ResolveEnv],
308
- filter: async () => params_1.RuntimeParams.installGlobals,
309
- action: async () => {
310
- const globalPackages = 'firebase-tools@5.0.4 ts-node@latest typescript@latest eslint@^8.0.0';
311
- await nvm_1.NVM.createCommando().append(`npm i -g ${globalPackages}`).execute();
312
- }
313
- };
314
- // export const Phase_InstallPnpm: BuildPhase = {
315
- // type: 'project',
316
- // name: 'install-pnpm',
317
- // mandatoryPhases: [Phase_ResolveEnv],
318
- // action: async () => {
319
- // await PNPM.install(NVM.createCommando());
320
- // }
321
- // };
322
- exports.Phase_InstallPackages = {
323
- type: 'project',
324
- name: 'install-packages',
325
- mandatoryPhases: [exports.Phase_ResolveEnv],
326
- filter: async () => params_1.RuntimeParams.installPackages,
327
- action: async () => {
328
- const packages = consts_1.MemKey_Packages.get();
329
- const listOfLibs = packages.packages
330
- .map(pkg => pkg.path.replace(`${process.cwd()}/`, '').replace(process.cwd(), '.'));
331
- await pnpm_1.PNPM.createWorkspace(listOfLibs);
332
- await pnpm_1.PNPM.installPackages(nvm_1.NVM.createCommando());
333
- }
334
- };
335
- exports.Phase_InstallPythonPackages = {
336
- type: 'package',
337
- name: 'install-python-packages',
338
- filter: async (pkg) => (params_1.RuntimeParams.encounterManager || params_1.RuntimeParams.encounterManagerListen) && (params_1.RuntimeParams.installPackages || params_1.RuntimeParams.install) && pkg.type === types_1.PackageType_Python,
339
- action: async (pkg) => {
340
- if (pkg.type !== types_1.PackageType_Python)
341
- return;
342
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
343
- .cd((0, tools_1.convertToFullPath)(pkg.path))
344
- .append('echo installing python')
345
- .append('python3 -m venv venv')
346
- .append('source venv/bin/activate')
347
- .append('pip3 install -r requirements.txt')
348
- .execute();
349
- }
350
- };
351
- exports.Phase_Lint = {
352
- type: 'package',
353
- name: 'lint',
354
- mandatoryPhases: [exports.Phase_ResolveEnv],
355
- filter: async (pkg) => params_1.RuntimeParams.lint && pkg.type !== 'sourceless',
356
- action: async (pkg) => {
357
- if (pkg.type === types_1.PackageType_Python)
358
- return;
359
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
360
- projectScreen.updateOrCreatePackage(pkg.name, 'Linting');
361
- const folder = 'main';
362
- const sourceFolder = `${pkg.path}/src/${folder}`;
363
- return nvm_1.NVM.createCommando().append(`eslint --config ${pathToProjectEslint} --ext .ts --ext .tsx "${sourceFolder}"`).execute();
364
- }
365
- };
366
- exports.Phase_Debug = {
367
- type: 'project',
368
- name: 'debug',
369
- mandatoryPhases: [exports.Phase_ResolveEnv],
370
- filter: async () => params_1.RuntimeParams.debug,
371
- action: async () => {
372
- const packages = consts_1.MemKey_Packages.get();
373
- ts_common_1.StaticLogger.logInfo(JSON.stringify(packages, null, 2));
374
- }
375
- };
376
- const sourcesPaths = [];
377
- const suffixes = [
378
- 'ts',
379
- 'tsx',
380
- 'scss',
381
- 'json',
382
- 'svg',
383
- ];
384
- const compileActions = {};
385
- exports.Phase_PrepareCompile = {
386
- type: 'package',
387
- name: 'prepare-compile',
388
- isMandatory: true,
389
- mandatoryPhases: [exports.Phase_ResolveEnv],
390
- filter: async (pkg) => pkg.type !== 'sourceless' && pkg.type !== types_1.PackageType_Python && !params_1.RuntimeParams.noBuild,
391
- action: async (pkg) => {
392
- if (pkg.type === 'sourceless' || pkg.type === types_1.PackageType_Python)
393
- return;
394
- const folder = 'main';
395
- const sourceFolder = `${pkg.path}/src/${folder}`;
396
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
397
- suffixes.forEach(suffix => {
398
- sourcesPaths.push(`${sourceFolder}/**/*.${suffix}`);
399
- });
400
- // --- HERE ---
401
- compileActions[sourceFolder] = async () => {
402
- const pathToLocalTsConfig = `${sourceFolder}/${CONST_TS_Config}`;
403
- projectScreen.updateOrCreatePackage(pkg.name, 'Compiling');
404
- const counter = timeCounter();
405
- const commando = nvm_1.NVM.createCommando(basic_1.Cli_Basic);
406
- if (pkg.type === 'firebase-hosting-app') {
407
- commando
408
- .cd(pkg.path)
409
- .append(`ENV=${params_1.RuntimeParams.environment} npm run build`);
410
- }
411
- else {
412
- try {
413
- const otherFiles = [
414
- 'json',
415
- 'scss',
416
- 'svg',
417
- 'png',
418
- 'jpg',
419
- 'jpeg',
420
- 'rules',
421
- '_ts',
422
- ];
423
- const command = `find . \\( -name ${otherFiles.map(suffix => `'*.${suffix}'`).join(' -o -name ')} \\) | cpio -pdm "${pkg.output}" > /dev/null`;
424
- await shell_1.Commando.create(basic_1.Cli_Basic)
425
- .cd(`${pkg.path}/src/main`)
426
- .append(command)
427
- .execute();
428
- }
429
- catch (e) {
430
- //
431
- }
432
- commando
433
- .append(`tsc -p "${pathToLocalTsConfig}" --rootDir "${sourceFolder}" --outDir "${pkg.output}"`);
434
- }
435
- await commando.execute();
436
- projectScreen.updateOrCreatePackage(pkg.name, `Compiled (${counter.format('mm:ss.zzz')})`);
437
- };
438
- }
439
- };
440
- exports.Phase_PreCompile = {
441
- type: 'package',
442
- name: 'pre-compile',
443
- isMandatory: true,
444
- mandatoryPhases: [exports.Phase_ResolveEnv],
445
- filter: async (pkg) => {
446
- if (pkg.type === 'sourceless')
447
- return false;
448
- if (params_1.RuntimeParams.noBuild)
449
- return false;
450
- return fs.existsSync(`${pkg.path}/prebuild.sh`);
451
- },
452
- action: async (pkg) => {
453
- if (pkg.type === types_1.PackageType_Python)
454
- return;
455
- return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
456
- .cd(pkg.path)
457
- .append(`bash ${pkg.path}/prebuild.sh`).execute();
458
- }
459
- };
460
- exports.Phase_Compile = {
461
- type: 'package',
462
- name: 'compile',
463
- mandatoryPhases: [exports.Phase_PrepareCompile],
464
- filter: async (pkg) => pkg.type !== 'sourceless' && !params_1.RuntimeParams.noBuild,
465
- action: async (pkg) => {
466
- var _a;
467
- const packages = consts_1.MemKey_Packages.get();
468
- if (pkg.type === 'sourceless' || pkg.type === types_1.PackageType_Python)
469
- return;
470
- if (params_1.RuntimeParams.clean && fs.existsSync(pkg.output)) {
471
- await fs_1.promises.rm(pkg.output, { recursive: true, force: true });
472
- await fs_1.promises.mkdir(pkg.output, { recursive: true });
473
- }
474
- const folder = 'main';
475
- const sourceFolder = `${pkg.path}/src/${folder}`;
476
- const pathToLocalTsConfig = `${sourceFolder}/${CONST_TS_Config}`;
477
- const pathToVersionAppJSON = `${CONST_RunningRoot}/${CONST_VersionApp}`;
478
- //copy version-app.json file
479
- const versionAppJSON = await fs_1.promises.readFile(pathToVersionAppJSON, { encoding: 'utf-8' });
480
- // only read if exists
481
- let inPackageTsConfig = '';
482
- if (fs.existsSync(pathToLocalTsConfig))
483
- inPackageTsConfig = await fs_1.promises.readFile(pathToLocalTsConfig, { encoding: 'utf-8' });
484
- const defaultPackageTsConfig = await fs_1.promises.readFile(pathToProjectTS_Config, { encoding: 'utf-8' });
485
- ts_common_1.StaticLogger.logInfo(`Copying tsconfig: ${pathToProjectTS_Config} => ${pathToLocalTsConfig}`);
486
- if (!pkg.customTsConfig && inPackageTsConfig !== defaultPackageTsConfig) {
487
- await fs_1.promises.copyFile(pathToProjectTS_Config, pathToLocalTsConfig);
488
- }
489
- // --- HERE ---
490
- await fs_1.promises.writeFile(`${pkg.output}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonOutput, null, 2), { encoding: 'utf-8' });
491
- if (pkg.type === types_1.PackageType_FirebaseFunctionsApp || pkg.type === types_1.PackageType_FirebaseHostingApp)
492
- await fs_1.promises.writeFile(`${sourceFolder}/${CONST_VersionApp}`, versionAppJSON, { encoding: 'utf-8' });
493
- if (pkg.type === 'firebase-functions-app') {
494
- pkg.packageJsonRuntime.main = pkg.packageJsonRuntime.main.replace('dist/', '');
495
- pkg.packageJsonRuntime.types = pkg.packageJsonRuntime.types.replace('dist/', '');
496
- await fs_1.promises.writeFile(`${pkg.output}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonRuntime, null, 2), { encoding: 'utf-8' });
497
- const runTimePackages = (0, ts_common_1.filterDuplicates)((_a = packages.packagesDependency) === null || _a === void 0 ? void 0 : _a.flat().filter(_pkg => {
498
- var _a, _b, _c;
499
- if (_pkg.name === pkg.name)
500
- return false;
501
- if (_pkg.type === types_1.PackageType_Python)
502
- return false;
503
- if (((_a = pkg.packageJsonOutput) === null || _a === void 0 ? void 0 : _a.dependencies) && !(0, ts_common_1._keys)((_b = pkg.packageJsonOutput) === null || _b === void 0 ? void 0 : _b.dependencies).includes((_c = _pkg.packageJsonTemplate) === null || _c === void 0 ? void 0 : _c.name))
504
- return false;
505
- return _pkg.type !== 'sourceless';
506
- }), __pkg => __pkg.name);
507
- if (runTimePackages) {
508
- for (const rtPack of runTimePackages) {
509
- if (rtPack.type === types_1.PackageType_Python)
510
- return;
511
- // @ts-ignore
512
- if (!rtPack.output)
513
- continue;
514
- const pkgOutputFolderAsDependency = `${pkg.output}/.dependencies/${rtPack.name}/`;
515
- await nvm_1.NVM.createCommando()
516
- .append(`mkdir -p ${pkgOutputFolderAsDependency}`)
517
- // @ts-ignore
518
- .append(`rsync -a --delete ${rtPack.output}/ ${pkg.output}/.dependencies/${rtPack.name}/`)
519
- .execute();
520
- await fs_1.promises.writeFile(`${pkgOutputFolderAsDependency}/${consts_1.CONST_PackageJSON}`, JSON.stringify(rtPack.packageJsonRuntime, null, 2), { encoding: 'utf-8' });
521
- }
522
- }
523
- }
524
- return compileActions[sourceFolder]();
525
- }
526
- };
527
- exports.Phase_CompileWatch = {
528
- type: 'project',
529
- name: 'compile-watch',
530
- terminatingPhase: true,
531
- mandatoryPhases: [exports.Phase_PrepareCompile],
532
- filter: async () => params_1.RuntimeParams.watch,
533
- action: async () => {
534
- const watcher = chokidar.watch(sourcesPaths);
535
- const projectManager = project_manager_1.MemKey_ProjectManager.get();
536
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
537
- const packages = consts_1.MemKey_Packages.get();
538
- await project_manager_1.MemKey_ProjectManager.get().updateRunningStatus({
539
- 'phaseKey': 'compile-watch',
540
- 'packageDependencyIndex': 0
541
- });
542
- let controller;
543
- let prevController;
544
- const watchListener = async (path, deleteDist) => {
545
- const libPath = (0, ts_common_1._keys)(compileActions).find(libPath => path.startsWith(libPath));
546
- if (!libPath)
547
- return console.error(`couldn't find lib to run for path: ${libPath}...\nListening on: ${(0, ts_common_1.__stringify)(sourcesPaths, true)}`);
548
- const rtPackages = consts_1.MemKey_Packages.get();
549
- const pkg = (0, ts_common_1.flatArray)(rtPackages.packagesDependency).find(pkg => {
550
- return path.startsWith(pkg.path) && pkg.type !== 'sourceless' && pkg.type !== types_1.PackageType_Python;
551
- });
552
- if (deleteDist && pkg && 'output' in pkg)
553
- await fs_1.promises.rmdir(pkg.output);
554
- const packageIndex = rtPackages.packagesDependency.findIndex(packages => {
555
- return packages.some(pkg => path.startsWith(pkg.path) && pkg.type !== 'sourceless' && pkg.type !== types_1.PackageType_Python);
556
- });
557
- try {
558
- if (controller)
559
- controller.abort();
560
- prevController = controller;
561
- controller = new AbortController();
562
- await projectManager.executePhase('compile', {
563
- phaseKey: 'compile',
564
- packageDependencyIndex: packageIndex
565
- }, controller.signal);
566
- if (!(prevController === null || prevController === void 0 ? void 0 : prevController.signal.aborted)) {
567
- // reset all packages back to watching
568
- packages.packages.map(pkg => projectScreen.updateOrCreatePackage(pkg.name, 'Watching'));
569
- projectScreen.updateRunningPhase('compile-watch');
570
- }
571
- }
572
- catch (e) {
573
- ts_common_1.StaticLogger.logError(e);
574
- }
575
- };
576
- return new Promise((resolve, error) => {
577
- watcher
578
- .on('error', (error) => {
579
- ts_common_1.StaticLogger.logError('Error while watching', error);
580
- })
581
- .on('ready', () => {
582
- ts_common_1.StaticLogger.logInfo('Watching: ', sourcesPaths);
583
- packages.packages.map(pkg => projectScreen.updateOrCreatePackage(pkg.name, 'Watching'));
584
- watcher
585
- .on('add', (path) => {
586
- ts_common_1.StaticLogger.logInfo(`New File added: ${path}`);
587
- watchListener(path);
588
- })
589
- .on('change', (path) => {
590
- ts_common_1.StaticLogger.logInfo(`Detected changes in file: ${path}`);
591
- watchListener(path);
592
- })
593
- .on('unlinkDir', (path) => {
594
- ts_common_1.StaticLogger.logInfo(`Deleted Directory: ${path}`);
595
- watchListener(path, true);
596
- })
597
- .on('unlink', (path) => {
598
- ts_common_1.StaticLogger.logInfo(`File Deleted: ${path}`);
599
- watchListener(path, true);
600
- });
601
- });
602
- process.on('SIGINT', async (status) => {
603
- await watcher.close();
604
- await project_manager_1.MemKey_ProjectManager.get().updateRunningStatus({
605
- 'phaseKey': 'compile-watch',
606
- 'packageDependencyIndex': 0
607
- });
608
- process.exit(0);
609
- resolve();
610
- });
611
- });
612
- }
613
- };
614
- const executorMap = {};
615
- let runningAppsLogs;
616
- exports.Phase_Launch = {
617
- type: 'package',
618
- name: 'launch',
619
- terminatingPhase: true,
620
- mandatoryPhases: [exports.Phase_ResolveEnv],
621
- filter: async (pkg) => { var _a; return !!((_a = pkg.name.match(new RegExp(params_1.RuntimeParams.launch))) === null || _a === void 0 ? void 0 : _a[0]) && (pkg.type === 'firebase-functions-app' || pkg.type === 'firebase-hosting-app' || pkg.type === types_1.PackageType_Python); },
622
- action: async (pkg) => {
623
- const projectManager = project_manager_1.MemKey_ProjectManager.get();
624
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
625
- if (!runningAppsLogs) {
626
- projectScreen.dispose();
627
- projectManager.clearLogger();
628
- runningAppsLogs = new RunningProcessLogs_1.RunningProcessLogs();
629
- runningAppsLogs.create();
630
- }
631
- const logClient = new ts_common_1.LogClient_MemBuffer(pkg.name);
632
- logClient.setComposer((tag, level) => {
633
- ts_common_1._logger_finalDate.setTime(Date.now() - ts_common_1._logger_timezoneOffset);
634
- const date = ts_common_1._logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23).split('_')[1];
635
- return `${date} ${(0, ts_common_1._logger_getPrefix)(level)}: `;
636
- });
637
- logClient.setFilter((level, tag) => {
638
- return tag === pkg.name;
639
- });
640
- ts_common_1.BeLogged.addClient(logClient);
641
- projectScreen.updateOrCreatePackage(pkg.name, 'Launching...');
642
- if (pkg.type === 'firebase-functions-app') {
643
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.registerApp(pkg.name, logClient);
644
- const executor = await new command_executors_1.CommandExecutor_FirebaseFunction(pkg).execute();
645
- executorMap[pkg.name] = executor;
646
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.addOnTerminateCallback(async () => {
647
- await executor.kill();
648
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.unregisterApp(pkg.name);
649
- });
650
- return;
651
- }
652
- if (pkg.type === 'firebase-hosting-app') {
653
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.registerApp(pkg.name, logClient);
654
- const executor = await new command_executors_1.CommandExecutor_FirebaseHosting(pkg).execute();
655
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.addOnTerminateCallback(async () => {
656
- await executor.kill();
657
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.unregisterApp(pkg.name);
658
- });
659
- }
660
- if (pkg.type === types_1.PackageType_Python) {
661
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.registerApp(pkg.name, logClient);
662
- const startPython = async () => {
663
- const executor = new CommandExecutor_Python_1.CommandExecutor_Python(pkg);
664
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.addOnTerminateCallback(async () => {
665
- await executor.kill();
666
- runningAppsLogs === null || runningAppsLogs === void 0 ? void 0 : runningAppsLogs.unregisterApp(pkg.name);
667
- });
668
- await executor.execute();
669
- };
670
- // will listen to advisor and km be execution and then launch em
671
- if (params_1.RuntimeParams.encounterManagerListen) {
672
- logClient.log(pkg.name, ts_common_1.LogLevel.Info, true, ['Awaiting Advisor & KM BE launch']);
673
- const advisorExecutor = executorMap['advisor-backend'];
674
- const kmExecutor = executorMap['km-backend'];
675
- if (!advisorExecutor)
676
- logClient.log(pkg.name, ts_common_1.LogLevel.Error, true, ['Advisor BE executor not registered yet']);
677
- if (!kmExecutor)
678
- logClient.log(pkg.name, ts_common_1.LogLevel.Error, true, ['KM BE executor not registered yet']);
679
- let advisorUp = false;
680
- let kmUp = false;
681
- advisorExecutor === null || advisorExecutor === void 0 ? void 0 : advisorExecutor.addOnReadyCallback(async () => {
682
- advisorUp = true;
683
- if (!kmUp)
684
- return logClient.log(pkg.name, ts_common_1.LogLevel.Info, true, ['Advisor launched, waiting for KM']);
685
- logClient.log(pkg.name, ts_common_1.LogLevel.Info, true, ['Advisor & KM BE launched, Starting!']);
686
- await startPython();
687
- });
688
- kmExecutor === null || kmExecutor === void 0 ? void 0 : kmExecutor.addOnReadyCallback(async () => {
689
- kmUp = true;
690
- if (!advisorUp)
691
- return logClient.log(pkg.name, ts_common_1.LogLevel.Info, true, ['KM launched, waiting for Advisor']);
692
- logClient.log(pkg.name, ts_common_1.LogLevel.Info, true, ['Advisor & KM BE launched, Starting!']);
693
- await startPython();
694
- });
695
- }
696
- else if (params_1.RuntimeParams.encounterManager) {
697
- // will launch em without waiting
698
- await startPython();
699
- }
700
- }
701
- projectScreen.updateOrCreatePackage(pkg.name, 'Died');
702
- }
703
- };
704
- exports.Phase_DeployFrontend = {
705
- type: 'package',
706
- name: 'deploy-frontend',
707
- terminatingPhase: false,
708
- mandatoryPhases: [exports.Phase_ResolveEnv],
709
- filter: async (pkg) => {
710
- var _a;
711
- const match = !!((_a = pkg.name.match(new RegExp(params_1.RuntimeParams.deploy))) === null || _a === void 0 ? void 0 : _a[0]);
712
- return match && pkg.type === 'firebase-hosting-app';
713
- },
714
- action: async (pkg) => {
715
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
716
- if (pkg.type !== 'firebase-hosting-app')
717
- throw new ts_common_1.BadImplementationException(`Somehow got a non firebase hosting package here: ${(0, ts_common_1.__stringify)(pkg)}`);
718
- projectScreen.updateOrCreatePackage(pkg.name, 'Deploying');
719
- const counter = timeCounter();
720
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
721
- .cd(pkg.path)
722
- .append(`firebase --debug deploy --only hosting`)
723
- .execute();
724
- projectScreen.updateOrCreatePackage(pkg.name, `Deployed (${counter.format('mm:ss.zzz')})`);
725
- }
726
- };
727
- exports.Phase_DeployBackend = {
728
- type: 'package',
729
- name: 'deploy-functions',
730
- terminatingPhase: true,
731
- mandatoryPhases: [exports.Phase_ResolveEnv],
732
- filter: async (pkg) => {
733
- var _a;
734
- const match = !!((_a = pkg.name.match(new RegExp(params_1.RuntimeParams.deploy))) === null || _a === void 0 ? void 0 : _a[0]);
735
- return match && pkg.type === 'firebase-functions-app';
736
- },
737
- action: async (pkg) => {
738
- const projectScreen = ProjectScreen_1.MemKey_ProjectScreen.get();
739
- if (pkg.type !== 'firebase-functions-app')
740
- throw new ts_common_1.BadImplementationException(`Somehow got a non firebase functions package here: ${(0, ts_common_1.__stringify)(pkg)}`);
741
- projectScreen.updateOrCreatePackage(pkg.name, 'Deploying...');
742
- const counter = timeCounter();
743
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
744
- .cd(pkg.path)
745
- .cd('dist')
746
- .ls()
747
- .cat('package.json')
748
- .cat('index.js')
749
- .cd_()
750
- .append(`firebase --debug deploy --only functions --force`)
751
- .execute();
752
- projectScreen.updateOrCreatePackage(pkg.name, `Deployed (${counter.format('mm:ss.zzz')})`);
753
- }
754
- };
755
- function timeCounter() {
756
- const started = (0, ts_common_1.currentTimeMillis)();
757
- return {
758
- dt: () => (0, ts_common_1.currentTimeMillis)() - started,
759
- format: (format) => {
760
- let dt = (0, ts_common_1.currentTimeMillis)() - started;
761
- const hours = Math.floor(dt / ts_common_1.Hour);
762
- dt -= hours * ts_common_1.Hour;
763
- const minutes = Math.floor(dt / ts_common_1.Minute);
764
- dt -= minutes * ts_common_1.Minute;
765
- const seconds = Math.floor(dt / ts_common_1.Second);
766
- dt -= seconds * ts_common_1.Second;
767
- const millis = dt;
768
- return format
769
- .replace('hh', String(hours).padStart(2, '0'))
770
- .replace('mm', String(minutes).padStart(2, '0'))
771
- .replace('ss', String(seconds).padStart(2, '0'))
772
- .replace('zzz', String(millis).padStart(3, '0'));
773
- }
774
- };
775
- }