@nu-art/build-and-install 0.203.117

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 (39) hide show
  1. package/build-and-install.d.ts +1 -0
  2. package/build-and-install.js +42 -0
  3. package/core/consts.d.ts +4 -0
  4. package/core/consts.js +7 -0
  5. package/core/package/consts.d.ts +12 -0
  6. package/core/package/consts.js +50 -0
  7. package/core/package/generate.d.ts +218 -0
  8. package/core/package/generate.js +74 -0
  9. package/core/params/params.d.ts +50 -0
  10. package/core/params/params.js +389 -0
  11. package/core/params/types.d.ts +51 -0
  12. package/core/params/types.js +2 -0
  13. package/core/types/configs/firebasejson.d.ts +20 -0
  14. package/core/types/configs/firebasejson.js +2 -0
  15. package/core/types/configs/firebaserc.d.ts +16 -0
  16. package/core/types/configs/firebaserc.js +2 -0
  17. package/core/types/configs/index.d.ts +3 -0
  18. package/core/types/configs/index.js +19 -0
  19. package/core/types/configs/package-json.d.ts +17 -0
  20. package/core/types/configs/package-json.js +2 -0
  21. package/core/types/core.d.ts +3 -0
  22. package/core/types/core.js +2 -0
  23. package/core/types/index.d.ts +4 -0
  24. package/core/types/index.js +20 -0
  25. package/core/types/package/index.d.ts +2 -0
  26. package/core/types/package/index.js +18 -0
  27. package/core/types/package/package.d.ts +65 -0
  28. package/core/types/package/package.js +10 -0
  29. package/core/types/package/runtime-package.d.ts +11 -0
  30. package/core/types/package/runtime-package.js +2 -0
  31. package/core/types/project-config.d.ts +15 -0
  32. package/core/types/project-config.js +2 -0
  33. package/logic/ProjectManager.d.ts +38 -0
  34. package/logic/ProjectManager.js +125 -0
  35. package/logic/map-project-packages.d.ts +4 -0
  36. package/logic/map-project-packages.js +125 -0
  37. package/package.json +41 -0
  38. package/phases/phases.d.ts +24 -0
  39. package/phases/phases.js +458 -0
@@ -0,0 +1,458 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Phase_DeployBackend = exports.Phase_DeployFrontend = exports.Phase_Launch = exports.Phase_CompileWatch = exports.Phase_Compile = exports.Phase_Debug = exports.Phase_Lint = exports.Phase_Clean = exports.Phase_InstallPackages = exports.Phase_InstallPnpm = exports.Phase_InstallGlobals = exports.Phase_PackagePurge = exports.Phase_PrintEnv = exports.Phase_CheckCyclicImports = exports.Phase_PrintDependencyTree = exports.Phase_InstallNvm = exports.Phase_ResolvePackages = exports.Phase_ResolveEnv = exports.Phase_ResolveTemplate = exports.Phase_SetupProject = exports.Phase_SetWithThunderstorm = exports.Phase_PrintHelp = exports.projectPackages = void 0;
4
+ const ProjectManager_1 = require("../logic/ProjectManager");
5
+ const map_project_packages_1 = require("../logic/map-project-packages");
6
+ const fs = require("fs");
7
+ const fs_1 = require("fs");
8
+ const consts_1 = require("../core/consts");
9
+ const tools_1 = require("@nu-art/commando/core/tools");
10
+ const ts_common_1 = require("@nu-art/ts-common");
11
+ const types_1 = require("../core/types");
12
+ const generate_1 = require("../core/package/generate");
13
+ const consts_2 = require("../core/package/consts");
14
+ const nvm_1 = require("@nu-art/commando/cli/nvm");
15
+ const params_1 = require("../core/params/params");
16
+ const basic_1 = require("@nu-art/commando/cli/basic");
17
+ const pnpm_1 = require("@nu-art/commando/cli/pnpm");
18
+ const chokidar = require("chokidar");
19
+ const pathToConfig = (0, tools_1.convertToFullPath)('./.config/project-config.ts');
20
+ if (!fs.existsSync(pathToConfig))
21
+ throw new ts_common_1.ImplementationMissingException(`Missing ./.config/project-config.ts file, could not find in path: ${pathToConfig}`);
22
+ const projectConfig = require(pathToConfig).default;
23
+ const CONST_ThunderstormVersionKey = 'THUNDERSTORM_SDK_VERSION';
24
+ const CONST_ThunderstormDependencyKey = 'THUNDERSTORM_SDK_VERSION_DEPENDENCY';
25
+ const CONST_ProjectVersionKey = 'APP_VERSION';
26
+ const CONST_ProjectDependencyKey = 'APP_VERSION_DEPENDENCY';
27
+ const CONST_TS_Config = `tsconfig.json`;
28
+ const CONST_RunningRoot = process.cwd();
29
+ const pathToProjectTS_Config = (0, tools_1.convertToFullPath)(`./.config/${CONST_TS_Config}`);
30
+ const pathToProjectEslint = (0, tools_1.convertToFullPath)('./.config/.eslintrc.js');
31
+ exports.projectPackages = (0, map_project_packages_1.mapProjectPackages)(projectConfig);
32
+ const runInDebug = false;
33
+ let runningWithInfra = false;
34
+ exports.Phase_PrintHelp = {
35
+ type: 'project',
36
+ name: 'printHelp',
37
+ terminatingPhase: true,
38
+ filter: async () => params_1.RuntimeParams.help,
39
+ action: async () => {
40
+ const commando = nvm_1.NVM.createCommando(basic_1.Cli_Basic);
41
+ commando.append('echo "Build and install parameters:"');
42
+ //Resolve all params by group
43
+ 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) => {
44
+ var _a, _b, _c, _d;
45
+ 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];
46
+ return mapper[(_d = item.group) !== null && _d !== void 0 ? _d : 'No Group'];
47
+ });
48
+ (0, ts_common_1._keys)(paramsByGroup).map(paramGroup => {
49
+ commando.append(`echo "${paramGroup}:" \n`);
50
+ paramsByGroup[paramGroup].map(param => {
51
+ commando.append(`echo "\n ${param.keys.join(' | ')} \n \t\t${param.description.trim().split('\n').join('\n\t\t')} \n"`);
52
+ });
53
+ });
54
+ return commando.execute();
55
+ }
56
+ };
57
+ exports.Phase_SetWithThunderstorm = {
58
+ type: 'project',
59
+ name: 'with-ts-home',
60
+ action: async () => {
61
+ var _a;
62
+ // set value of the running with infra flag
63
+ if (params_1.RuntimeParams.thunderstormHome)
64
+ return runningWithInfra = true;
65
+ // Remove all the infra packages from the runtime project
66
+ exports.projectPackages.packagesDependency = (_a = exports.projectPackages.packagesDependency) === null || _a === void 0 ? void 0 : _a.map(_packageArray => _packageArray.filter(_package => _package.type !== types_1.PackageType_InfraLib));
67
+ return runningWithInfra = false;
68
+ }
69
+ };
70
+ exports.Phase_SetupProject = {
71
+ type: 'project',
72
+ name: 'setup-project',
73
+ action: async () => {
74
+ const thunderstormVersionJson = require((0, tools_1.convertToFullPath)('./version-thunderstorm.json'));
75
+ exports.projectPackages.params[CONST_ThunderstormVersionKey] = thunderstormVersionJson.version;
76
+ exports.projectPackages.params[CONST_ThunderstormDependencyKey] = thunderstormVersionJson.version;
77
+ const projectVersionJson = require((0, tools_1.convertToFullPath)('./version-app.json'));
78
+ exports.projectPackages.params[CONST_ProjectVersionKey] = projectVersionJson.version;
79
+ exports.projectPackages.params[CONST_ProjectDependencyKey] = projectVersionJson.version;
80
+ }
81
+ };
82
+ exports.Phase_ResolveTemplate = {
83
+ type: 'package',
84
+ name: 'resolve-template',
85
+ mandatoryPhases: [exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
86
+ action: async (pkg) => {
87
+ // with workspace: *
88
+ pkg.packageJsonWorkspace = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
89
+ const toRet = projectConfig.params[key] ? 'workspace:*' : projectConfig.params[value];
90
+ return toRet;
91
+ });
92
+ // placed package name to version
93
+ projectConfig.params[pkg.packageJsonWorkspace.name] = pkg.packageJsonWorkspace.version;
94
+ projectConfig.params[`${pkg.packageJsonWorkspace.name}_path`] = `file:.dependencies/${pkg.name}`;
95
+ // with versions for all packages, for be output: file:.dependencies/${pkg.name}
96
+ pkg.packageJsonOutput = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
97
+ var _a;
98
+ const toRet = (_a = projectConfig.params[key]) !== null && _a !== void 0 ? _a : projectConfig.params[value];
99
+ return toRet;
100
+ });
101
+ pkg.packageJsonRuntime = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(pkg.packageJsonTemplate, (value, key) => {
102
+ var _a, _b;
103
+ const toRet = (_b = (_a = projectConfig.params[`${key}_path`]) !== null && _a !== void 0 ? _a : projectConfig.params[key]) !== null && _b !== void 0 ? _b : projectConfig.params[value];
104
+ return toRet;
105
+ });
106
+ // write final package.json to package root folder
107
+ await fs_1.promises.writeFile(`${pkg.path}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonWorkspace, null, 2), { encoding: 'utf-8' });
108
+ // write final package.json to package output folder
109
+ if (pkg.type === 'sourceless')
110
+ return;
111
+ if (!fs.existsSync(pkg.output))
112
+ await fs_1.promises.mkdir(pkg.output);
113
+ }
114
+ };
115
+ exports.Phase_ResolveEnv = {
116
+ type: 'package',
117
+ name: 'resolve-env',
118
+ mandatoryPhases: [exports.Phase_ResolveTemplate, exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
119
+ filter: async (pkg) => pkg.type === 'firebase-functions-app' || pkg.type === 'firebase-hosting-app',
120
+ action: async (pkg) => {
121
+ var _a, _b;
122
+ const firebasePkg = pkg;
123
+ await fs_1.promises.writeFile(`${firebasePkg.path}/${consts_1.CONST_FirebaseRC}`, JSON.stringify((0, generate_1.createFirebaseRC)(firebasePkg, params_1.RuntimeParams.setEnv), null, 2), { encoding: 'utf-8' });
124
+ let fileContent;
125
+ if (pkg.type === 'firebase-hosting-app')
126
+ fileContent = (0, generate_1.createFirebaseHostingJSON)(firebasePkg, params_1.RuntimeParams.setEnv);
127
+ if (pkg.type === 'firebase-functions-app') {
128
+ const firebaseFunctionPkg = firebasePkg;
129
+ const pathToFirebaseConfigFolder = `${firebaseFunctionPkg.path}/${firebaseFunctionPkg.envConfig.pathToFirebaseConfig}`;
130
+ try {
131
+ await fs_1.promises.access(pathToFirebaseConfigFolder);
132
+ }
133
+ catch (e) {
134
+ await fs_1.promises.mkdir(pathToFirebaseConfigFolder, { recursive: true });
135
+ }
136
+ if (firebasePkg.envConfig.ssl) {
137
+ const pathToProxyFile = `${firebaseFunctionPkg.path}/src/main/proxy.ts`;
138
+ try {
139
+ await fs_1.promises.access(pathToProxyFile);
140
+ }
141
+ catch (e) {
142
+ let defaultFileContent = await fs_1.promises.readFile(`${__dirname}/defaults/backend-proxy/proxy._ts`, { encoding: 'utf-8' });
143
+ defaultFileContent = defaultFileContent.replace(/SERVER_PORT/g, `${firebasePkg.envConfig.basePort}`);
144
+ defaultFileContent = defaultFileContent.replace(/PATH_TO_SSL_KEY/g, `${(_a = firebasePkg.envConfig.ssl) === null || _a === void 0 ? void 0 : _a.pathToKey}`);
145
+ defaultFileContent = defaultFileContent.replace(/PATH_TO_SSL_CERTIFICATE/g, `${(_b = firebasePkg.envConfig.ssl) === null || _b === void 0 ? void 0 : _b.pathToCertificate}`);
146
+ await fs_1.promises.writeFile(pathToProxyFile, defaultFileContent, { encoding: 'utf-8' });
147
+ }
148
+ }
149
+ await Promise.all(consts_2.Default_ListOfFirebaseConfigFiles.map(async (firebaseConfigFile) => {
150
+ const pathToConfigFile = `${pathToFirebaseConfigFolder}/${firebaseConfigFile}`;
151
+ try {
152
+ await fs_1.promises.access(pathToConfigFile);
153
+ }
154
+ catch (e) {
155
+ const defaultFileContent = await fs_1.promises.readFile(`${__dirname}/defaults/.firebase_config/${firebaseConfigFile}`, { encoding: 'utf-8' });
156
+ await fs_1.promises.writeFile(pathToConfigFile, defaultFileContent, { encoding: 'utf-8' });
157
+ }
158
+ }));
159
+ fileContent = (0, generate_1.createFirebaseFunctionsJSON)(firebaseFunctionPkg, params_1.RuntimeParams.setEnv);
160
+ }
161
+ await fs_1.promises.writeFile(`${firebasePkg.path}/${consts_1.CONST_FirebaseJSON}`, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
162
+ }
163
+ };
164
+ exports.Phase_ResolvePackages = {
165
+ type: 'project',
166
+ name: 'setup-packages',
167
+ action: async () => {
168
+ }
169
+ };
170
+ exports.Phase_InstallNvm = {
171
+ type: 'project',
172
+ name: 'install-nvm',
173
+ mandatoryPhases: [exports.Phase_ResolveEnv],
174
+ action: async () => {
175
+ const installed = await nvm_1.NVM.installRequiredVersionIfNeeded();
176
+ if (!installed)
177
+ return;
178
+ }
179
+ };
180
+ exports.Phase_PrintDependencyTree = {
181
+ type: ProjectManager_1.PackageBuildPhaseType_Package,
182
+ name: 'print-dependency-tree',
183
+ terminatingPhase: true,
184
+ mandatoryPhases: [exports.Phase_ResolveEnv],
185
+ filter: async (pkg) => {
186
+ return params_1.RuntimeParams.dependencyTree && (0, ts_common_1.exists)(pkg.packageJsonWorkspace);
187
+ },
188
+ action: async (pkg) => {
189
+ return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
190
+ .cd(pkg.path)
191
+ .append(`mkdir -p ${CONST_RunningRoot}/.trash/dependencies`)
192
+ .append(`pnpm list --depth 1000 > "${CONST_RunningRoot}/.trash/dependencies/${pkg.name}.txt"`)
193
+ .execute();
194
+ }
195
+ };
196
+ exports.Phase_CheckCyclicImports = {
197
+ type: ProjectManager_1.PackageBuildPhaseType_PackageWithOutput,
198
+ name: 'check-cyclic-imports',
199
+ terminatingPhase: true,
200
+ mandatoryPhases: [exports.Phase_ResolveEnv],
201
+ filter: async (pkg) => params_1.RuntimeParams.checkCyclicImports,
202
+ action: async (pkg) => {
203
+ if (!pkg.output)
204
+ return;
205
+ return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
206
+ .cd(pkg.path)
207
+ .append(`npx madge --image "./imports-${pkg.name}.svg" --circular ${pkg.output}`)
208
+ .execute();
209
+ }
210
+ };
211
+ exports.Phase_PrintEnv = {
212
+ type: 'project',
213
+ name: 'print-env',
214
+ terminatingPhase: true,
215
+ mandatoryPhases: [exports.Phase_ResolveEnv],
216
+ filter: async () => params_1.RuntimeParams.printEnv,
217
+ action: async () => {
218
+ return nvm_1.NVM.createCommando(basic_1.Cli_Basic)
219
+ .append('npm -g list typescript eslint firebase-tools sort-package-json --depth=0')
220
+ .append('echo "npm version:"; npm -v')
221
+ .append('echo "node version:"; node -v')
222
+ .append('echo "base version:"; bash --version')
223
+ .execute();
224
+ }
225
+ };
226
+ exports.Phase_PackagePurge = {
227
+ type: ProjectManager_1.PackageBuildPhaseType_PackageWithOutput,
228
+ name: 'package-purge',
229
+ mandatoryPhases: [exports.Phase_ResolveEnv],
230
+ filter: async (pkg) => fs.existsSync(pkg.output) && params_1.RuntimeParams.purge,
231
+ action: async (pkg) => {
232
+ await fs_1.promises.rm(pkg.output, { recursive: true, force: true });
233
+ }
234
+ };
235
+ exports.Phase_InstallGlobals = {
236
+ type: 'project',
237
+ name: 'install-globals',
238
+ mandatoryPhases: [exports.Phase_ResolveEnv],
239
+ filter: async () => params_1.RuntimeParams.installGlobals,
240
+ action: async () => {
241
+ const globalPackages = 'firebase-tools@latest ts-node@latest typescript@latest eslint@^8.0.0';
242
+ await nvm_1.NVM.createCommando().append(`npm i -g ${globalPackages}`).execute();
243
+ }
244
+ };
245
+ exports.Phase_InstallPnpm = {
246
+ type: 'project',
247
+ name: 'install-pnpm',
248
+ mandatoryPhases: [exports.Phase_ResolveEnv],
249
+ action: async () => {
250
+ await pnpm_1.PNPM.install(nvm_1.NVM.createCommando());
251
+ }
252
+ };
253
+ exports.Phase_InstallPackages = {
254
+ type: 'project',
255
+ name: 'install-packages',
256
+ mandatoryPhases: [exports.Phase_ResolveEnv],
257
+ filter: async () => params_1.RuntimeParams.installPackages,
258
+ action: async () => {
259
+ const listOfLibs = exports.projectPackages.packages
260
+ .filter(pkg => runningWithInfra || ['project-lib', 'app', 'sourceless'].includes(pkg.type))
261
+ .map(pkg => pkg.path.replace(`${process.cwd()}/`, '').replace(process.cwd(), '.'));
262
+ await pnpm_1.PNPM.createWorkspace(listOfLibs);
263
+ await pnpm_1.PNPM.installPackages(nvm_1.NVM.createCommando());
264
+ }
265
+ };
266
+ exports.Phase_Clean = {
267
+ type: ProjectManager_1.PackageBuildPhaseType_PackageWithOutput,
268
+ name: 'clean',
269
+ mandatoryPhases: [exports.Phase_ResolveEnv],
270
+ filter: async (pkg) => params_1.RuntimeParams.clean,
271
+ action: async (pkg) => {
272
+ if (!fs.existsSync(pkg.output))
273
+ return;
274
+ await fs_1.promises.rm(pkg.output, { recursive: true, force: true });
275
+ }
276
+ };
277
+ exports.Phase_Lint = {
278
+ type: 'package',
279
+ name: 'lint',
280
+ mandatoryPhases: [exports.Phase_ResolveEnv],
281
+ filter: async (pkg) => params_1.RuntimeParams.lint && pkg.type !== 'sourceless',
282
+ action: async (pkg) => {
283
+ const folder = 'main';
284
+ const sourceFolder = `${pkg.path}/src/${folder}`;
285
+ return nvm_1.NVM.createCommando().append(`eslint --config ${pathToProjectEslint} --ext .ts --ext .tsx "${sourceFolder}"`).execute();
286
+ }
287
+ };
288
+ exports.Phase_Debug = {
289
+ type: 'project',
290
+ name: 'debug',
291
+ mandatoryPhases: [exports.Phase_ResolveEnv],
292
+ filter: async () => params_1.RuntimeParams.debug,
293
+ action: async () => {
294
+ console.log(JSON.stringify(exports.projectPackages, null, 2));
295
+ }
296
+ };
297
+ const sourcesPaths = [];
298
+ const suffixes = [
299
+ 'ts',
300
+ 'tsx',
301
+ 'scss',
302
+ 'json',
303
+ 'svg',
304
+ ];
305
+ const compileActions = {};
306
+ exports.Phase_Compile = {
307
+ type: 'package',
308
+ name: 'compile',
309
+ mandatoryPhases: [exports.Phase_ResolveEnv],
310
+ filter: async (pkg) => pkg.type !== 'sourceless' && !params_1.RuntimeParams.noBuild,
311
+ action: async (pkg) => {
312
+ var _a;
313
+ if (pkg.type === 'sourceless')
314
+ return;
315
+ const folder = 'main';
316
+ const sourceFolder = `${pkg.path}/src/${folder}`;
317
+ suffixes.forEach(suffix => {
318
+ sourcesPaths.push(`${sourceFolder}/**/*.${suffix}`);
319
+ });
320
+ const pathToLocalTsConfig = `${sourceFolder}/${CONST_TS_Config}`;
321
+ const commando = nvm_1.NVM.createCommando();
322
+ if (!pkg.customTsConfig)
323
+ await fs_1.promises.copyFile(pathToProjectTS_Config, pathToLocalTsConfig);
324
+ // --- HERE ---
325
+ await fs_1.promises.writeFile(`${pkg.output}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonOutput, null, 2), { encoding: 'utf-8' });
326
+ if (pkg.type == 'firebase-functions-app') {
327
+ await fs_1.promises.writeFile(`${pkg.output}/${consts_1.CONST_PackageJSON}`, JSON.stringify(pkg.packageJsonRuntime, null, 2), { encoding: 'utf-8' });
328
+ const runTimePackages = (0, ts_common_1.filterDuplicates)((_a = exports.projectPackages.packagesDependency) === null || _a === void 0 ? void 0 : _a.flat().filter(_pkg => {
329
+ var _a, _b;
330
+ if (_pkg.name === pkg.name)
331
+ return false;
332
+ 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(_pkg.packageJsonTemplate.name))
333
+ return false;
334
+ return _pkg.type !== 'sourceless';
335
+ }), __pkg => __pkg.name);
336
+ if (runTimePackages) {
337
+ for (const rtPack of runTimePackages) {
338
+ if (!rtPack.output)
339
+ continue;
340
+ const pkgOutputFolderAsDependency = `${pkg.output}/.dependencies/${rtPack.name}/`;
341
+ await nvm_1.NVM.createCommando()
342
+ .append(`mkdir -p ${pkgOutputFolderAsDependency}`)
343
+ .append(`rsync -a --delete ${rtPack.output}/ ${pkg.output}/.dependencies/${rtPack.name}/`)
344
+ .execute();
345
+ await fs_1.promises.writeFile(`${pkgOutputFolderAsDependency}/${consts_1.CONST_PackageJSON}`, JSON.stringify(rtPack.packageJsonRuntime, null, 2), { encoding: 'utf-8' });
346
+ }
347
+ }
348
+ }
349
+ compileActions[sourceFolder] = async (deleteDist) => {
350
+ if (deleteDist)
351
+ await fs_1.promises.rmdir(pkg.output);
352
+ await commando
353
+ .append(`tsc -p "${pathToLocalTsConfig}" --rootDir "${sourceFolder}" --outDir "${pkg.output}"`)
354
+ .execute();
355
+ };
356
+ return compileActions[sourceFolder]();
357
+ }
358
+ };
359
+ exports.Phase_CompileWatch = {
360
+ type: 'project',
361
+ name: 'compile-watch',
362
+ mandatoryPhases: [exports.Phase_ResolveEnv],
363
+ filter: async () => params_1.RuntimeParams.watch,
364
+ action: async () => {
365
+ const watcher = chokidar.watch(sourcesPaths);
366
+ const watchListener = (path, deleteDist) => {
367
+ const libPath = (0, ts_common_1._keys)(compileActions).find(libPath => path.startsWith(libPath));
368
+ if (!libPath)
369
+ return console.error(`couldn't find lib to run for path: ${libPath}...\nListening on: ${(0, ts_common_1.__stringify)(sourcesPaths, true)}`);
370
+ return compileActions[libPath](deleteDist);
371
+ };
372
+ watcher
373
+ .on('add', (path) => {
374
+ console.log(`New File added: ${path}`);
375
+ watchListener(path);
376
+ })
377
+ .on('change', (path) => {
378
+ console.log(`Detected changes in file: ${path}`);
379
+ watchListener(path);
380
+ })
381
+ .on('unlinkDir', (path) => {
382
+ console.log(`Deleted Directory: ${path}`);
383
+ watchListener(path, true);
384
+ })
385
+ .on('error', (error) => {
386
+ console.log(`error`, error);
387
+ })
388
+ .on('unlink', (path) => {
389
+ console.log(`File Deleted: ${path}`);
390
+ watchListener(path, true);
391
+ })
392
+ .on('ready', () => {
393
+ console.log('Watching: ', sourcesPaths);
394
+ });
395
+ }
396
+ };
397
+ let counter = 0;
398
+ exports.Phase_Launch = {
399
+ type: 'package',
400
+ name: 'launch',
401
+ mandatoryPhases: [exports.Phase_ResolveEnv],
402
+ 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'); },
403
+ action: async (pkg) => {
404
+ if (pkg.type === 'firebase-functions-app') {
405
+ await (0, ts_common_1.sleep)(1000 * counter++);
406
+ const allPorts = Array.from({ length: 10 }, (_, i) => `${pkg.envConfig.basePort + i}`);
407
+ const command = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
408
+ .cd(pkg.path).debug()
409
+ .append(`nvm use`)
410
+ .append(`echo RUNNING PACKAGE1 ${pkg.name}`)
411
+ .append(`array=($(lsof -ti:${allPorts.join(',')}))`)
412
+ .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
413
+ .append(`echo RUNNING PACKAGE2 ${pkg.name}`);
414
+ command.append(`firebase emulators:start --export-on-exit --import=.trash/data ${runInDebug ? `--inspect-functions ${pkg.envConfig.ssl}` : ''}`);
415
+ return command
416
+ .execute();
417
+ }
418
+ if (pkg.type === 'firebase-hosting-app')
419
+ return nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
420
+ .cd(pkg.path)
421
+ .append(`nvm use`)
422
+ .append(`pwd`)
423
+ .append(`npm run start`)
424
+ .execute();
425
+ }
426
+ };
427
+ exports.Phase_DeployFrontend = {
428
+ type: 'package',
429
+ name: 'deploy-frontend',
430
+ mandatoryPhases: [exports.Phase_ResolveEnv],
431
+ filter: async (pkg) => {
432
+ var _a;
433
+ console.log(`deploy flag(${pkg.name}): ${params_1.RuntimeParams.deploy}`);
434
+ return !!((_a = pkg.name.match(new RegExp(params_1.RuntimeParams.deploy))) === null || _a === void 0 ? void 0 : _a[0]) && pkg.type === 'firebase-hosting-app';
435
+ },
436
+ action: async (pkg) => {
437
+ if (pkg.type !== 'firebase-hosting-app')
438
+ throw new ts_common_1.BadImplementationException(`Somehow got a non firebase hosting package here: ${(0, ts_common_1.__stringify)(pkg)}`);
439
+ await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
440
+ .cd(pkg.path)
441
+ .append(`firebase deploy --only hosting`)
442
+ .execute();
443
+ }
444
+ };
445
+ exports.Phase_DeployBackend = {
446
+ type: 'package',
447
+ name: 'deploy-functions',
448
+ mandatoryPhases: [exports.Phase_ResolveEnv],
449
+ filter: async (pkg) => { var _a; return !!((_a = pkg.name.match(new RegExp(params_1.RuntimeParams.deploy))) === null || _a === void 0 ? void 0 : _a[0]) && pkg.type === 'firebase-functions-app'; },
450
+ action: async (pkg) => {
451
+ if (pkg.type !== 'firebase-functions-app')
452
+ throw new ts_common_1.BadImplementationException(`Somehow got a non firebase functions package here: ${(0, ts_common_1.__stringify)(pkg)}`);
453
+ await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
454
+ .cd(pkg.path)
455
+ .append(`firebase --debug deploy --only functions --force`)
456
+ .execute();
457
+ }
458
+ };