@nu-art/build-and-install 0.400.7 → 0.400.9

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.
@@ -8,7 +8,7 @@ import { ProjectUnit } from './v3/units/ProjectUnit.js';
8
8
  import { PhaseManager } from './v3/PhaseManager.js';
9
9
  import { Unit_NodeProject } from './v3/units/index.js';
10
10
  import { resolve } from 'path';
11
- import { CONST_BaiConfig, CONST_NodeModules } from './core/consts.js';
11
+ import { CONST_BaiConfig, CONST_NodeModules, CONST_VersionApp } from './core/consts.js';
12
12
  import { UnitMapper_FirebaseFunction, UnitMapper_FirebaseHosting, UnitMapper_NodeLib, UnitMapper_NodeProject } from './v3/UnitsMapper/resolvers/index.js';
13
13
  import { CLIParamsResolver } from '@nu-art/commando/cli-params/CLIParamsResolver';
14
14
  import { RunningStatusHandler } from './v3/RunningStatusHandler.js';
@@ -93,8 +93,11 @@ export class BuildAndInstall extends Logger {
93
93
  }));
94
94
  const globalOutputFolder = resolve(this.pathToProject, '.trash/output');
95
95
  this.unitsDependencyMapper = new UnitsDependencyMapper(unitsDependencies, globalOutputFolder);
96
+ const versionFilePath = resolve(this.pathToProject, CONST_VersionApp);
97
+ this.logInfo('loading version from: ', versionFilePath);
98
+ const version = await FileSystemUtils.file.read.json(versionFilePath, { version: '1.0.0' });
96
99
  const runtimeContext = ({
97
- version: '',
100
+ version: version.version,
98
101
  parentUnit: this.nodeProjectUnit,
99
102
  childUnits: allProjectUnits,
100
103
  baiConfig,
package/core/consts.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { MemKey } from '@nu-art/ts-common/mem-storage/index';
2
2
  import { RuntimeProjectConfig } from './types/index.js';
3
+ export declare const CONST_VersionApp = "version-app.json";
3
4
  export declare const CONST_PackageJSONTemplate = "__package.json";
4
5
  export declare const CONST_PackageJSON = "package.json";
5
6
  export declare const CONST_NodeModules = "node_modules";
package/core/consts.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { MemKey } from '@nu-art/ts-common/mem-storage/index';
2
+ export const CONST_VersionApp = 'version-app.json';
2
3
  export const CONST_PackageJSONTemplate = '__package.json';
3
4
  export const CONST_PackageJSON = 'package.json';
4
5
  export const CONST_NodeModules = 'node_modules';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/build-and-install",
3
- "version": "0.400.7",
3
+ "version": "0.400.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "chokidar": "^3.6.0",
34
- "@nu-art/ts-common": "0.400.7",
35
- "@nu-art/commando": "0.400.7"
34
+ "@nu-art/ts-common": "0.400.9",
35
+ "@nu-art/commando": "0.400.9"
36
36
  },
37
37
  "unitConfig": {
38
38
  "type": "typescript-lib"
@@ -8,6 +8,7 @@ export type Unit_PackageJson_Config = Config_ProjectUnit & {
8
8
  };
9
9
  export declare class Unit_PackageJson<C extends Unit_PackageJson_Config = Unit_PackageJson_Config> extends ProjectUnit<C> implements UnitPhaseImplementor<[Phase_Purge, Phase_Prepare]> {
10
10
  constructor(config: C);
11
+ protected npmCommand(command: string): string;
11
12
  protected deriveDistDependencies(): StringMap;
12
13
  protected deriveLibDependencies(): StringMap;
13
14
  prepare(): Promise<void>;
@@ -10,6 +10,9 @@ export class Unit_PackageJson extends ProjectUnit {
10
10
  this.addToClassStack(Unit_PackageJson);
11
11
  }
12
12
  //######################### Internal Logic #########################
13
+ npmCommand(command) {
14
+ return resolve(this.runtimeContext.parentUnit.config.fullPath, './node_modules/.bin', command);
15
+ }
13
16
  deriveDistDependencies() {
14
17
  const params = this.runtimeContext.childUnits.reduce((dependencies, unit) => {
15
18
  dependencies[unit.config.key] = unit.config.packageJson.version;
@@ -1,7 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import { copyFileSync, existsSync, promises as _fs, readdirSync, statSync } from 'fs';
3
3
  import { __stringify, arrayToMap, BadImplementationException, ImplementationMissingException, LogLevel, NotImplementedYetException } from '@nu-art/ts-common';
4
- import { CONST_BaiConfig, CONST_FirebaseJSON, CONST_FirebaseRC, CONST_NodeModules, CONST_PackageJSON, CONST_PackageJSONTemplate, CONST_TS_CONFIG } from '../../core/consts.js';
4
+ import { CONST_BaiConfig, CONST_FirebaseJSON, CONST_FirebaseRC, CONST_PackageJSON, CONST_PackageJSONTemplate, CONST_TS_CONFIG } from '../../core/consts.js';
5
5
  import { CommandoException } from '@nu-art/commando/shell/core/CliError';
6
6
  import { Commando_NVM } from '@nu-art/commando/shell/plugins/nvm';
7
7
  import { Commando_Basic } from '@nu-art/commando/shell/plugins/basic';
@@ -160,8 +160,7 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
160
160
  return LogLevel.Error;
161
161
  })
162
162
  .addLogProcessor((log) => !log.includes('Now using node') && !log.includes('.nvmrc\' with version'));
163
- const command = resolve(this.runtimeContext.parentUnit.config.fullPath, CONST_NodeModules, 'typescript', 'bin', 'tsc');
164
- await this.executeAsyncCommando(commando, `${command} -p "${pathToTSConfig}" --rootDir "${pathToCompile}" --outDir "${this.config.output}"`, (stdout, stderr, exitCode) => {
163
+ await this.executeAsyncCommando(commando, `${this.npmCommand('tsc')} -p "${pathToTSConfig}" --rootDir "${pathToCompile}" --outDir "${this.config.output}"`, (stdout, stderr, exitCode) => {
165
164
  if (stderr.length)
166
165
  this.logError(stderr);
167
166
  if (exitCode > 0)
@@ -43,6 +43,7 @@ export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsA
43
43
  protected copyPackageJSONToOutput(): Promise<void>;
44
44
  prepare(): Promise<void>;
45
45
  resolveConfigs(): Promise<void>;
46
+ compile(): Promise<void>;
46
47
  postCompile(): Promise<void>;
47
48
  launch(): Promise<void>;
48
49
  releaseEmulatorPorts(): Promise<void>;
@@ -1,5 +1,4 @@
1
- import { CONST_FirebaseJSON, CONST_FirebaseRC, CONST_NodeModules, CONST_PackageJSON } from '../../../core/consts.js';
2
- import { promises as _fs } from 'fs';
1
+ import { CONST_FirebaseJSON, CONST_FirebaseRC, CONST_PackageJSON, CONST_VersionApp } from '../../../core/consts.js';
3
2
  import { __stringify, _keys, _logger_logPrefixes, deepClone, ImplementationMissingException, LogLevel, Second, sleep } from '@nu-art/ts-common';
4
3
  import { Const_FirebaseConfigKeys, Const_FirebaseDefaultsKeyToFile } from '../../../defaults/consts.js';
5
4
  import { Commando_NVM } from '@nu-art/commando/shell/plugins/nvm';
@@ -80,8 +79,11 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
80
79
  await this.resolveFunctionsRuntimeConfig();
81
80
  await this.resolveFunctionsJSON();
82
81
  }
83
- async postCompile() {
82
+ async compile() {
84
83
  await this.createAppVersionFile();
84
+ await super.compile();
85
+ }
86
+ async postCompile() {
85
87
  await this.createDependenciesDir();
86
88
  }
87
89
  async launch() {
@@ -109,7 +111,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
109
111
  this.functions[match[1]] = match[2];
110
112
  });
111
113
  const debug = this.runtimeContext.runtimeParams.verbose ? ' --debug' : '';
112
- await this.executeAsyncCommando(commando, `firebase${debug} deploy --only functions --force`, (stdout, stderr, exitCode) => {
114
+ await this.executeAsyncCommando(commando, `${this.npmCommand('firebase')}${debug} deploy --only functions --force`, (stdout, stderr, exitCode) => {
113
115
  if (exitCode === 0)
114
116
  return;
115
117
  throw new CommandoException(`Failed to deploy function with exit code ${exitCode}`, stdout, stderr, exitCode);
@@ -137,8 +139,8 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
137
139
  }
138
140
  }
139
141
  };
140
- const targetPath = `${this.config.fullPath}/${CONST_FirebaseRC}`;
141
- await _fs.writeFile(targetPath, JSON.stringify(rcConfig, null, 2), { encoding: 'utf-8' });
142
+ const targetPath = resolve(this.config.fullPath, CONST_FirebaseRC);
143
+ await FileSystemUtils.file.write.json(targetPath, rcConfig);
142
144
  }
143
145
  async resolveProxyFile() {
144
146
  const envConfig = this.getEnvConfig();
@@ -230,7 +232,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
230
232
  }
231
233
  };
232
234
  }
233
- await _fs.writeFile(targetPath, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
235
+ await FileSystemUtils.file.write.json(targetPath, fileContent);
234
236
  }
235
237
  async resolveFunctionsRuntimeConfig() {
236
238
  const envConfig = this.getEnvConfig();
@@ -243,16 +245,15 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
243
245
  };
244
246
  const inLocalIgnoreTLS = `${envConfig.isLocal ? '// @ts-ignore\nprocess.env[\'NODE_TLS_REJECT_UNAUTHORIZED\'] = 0;\n\n' : ''}`;
245
247
  const fileContent = `${inLocalIgnoreTLS}export const Environment = ${JSON.stringify(beConfig)};`;
246
- await _fs.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
248
+ await FileSystemUtils.file.write(targetPath, fileContent);
247
249
  }
248
250
  //######################### Compile Logic #########################
249
251
  async createAppVersionFile() {
250
252
  //Writing the file to the package source instead of the output is fine,
251
253
  //copyAssetsToOutput will move the file to output
252
- // const targetPath = `${this.config.fullPath}/src/main/${CONST_VersionApp}`;
253
- // const appVersion = MemKey_ProjectConfig.get().projectVersion;
254
- // const fileContent = JSON.stringify({version: appVersion}, null, 2);
255
- // await _fs.writeFile(targetPath, fileContent, {encoding: 'utf-8'});
254
+ const targetPath = `${this.config.fullPath}/src/main/${CONST_VersionApp}`;
255
+ const appVersion = this.runtimeContext.version;
256
+ await FileSystemUtils.file.write.json(targetPath, { version: appVersion });
256
257
  }
257
258
  deriveDistDependencies() {
258
259
  return this.dependencyUnits.reduce((dependencies, unit) => {
@@ -277,8 +278,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
277
278
  await this.resolveProxyFile();
278
279
  const commando = this.allocateCommando(Commando_NVM).applyNVM()
279
280
  .cd(this.config.fullPath);
280
- const command = `${this.runtimeContext.parentUnit.config.fullPath}/${CONST_NodeModules}/.bin/tsx`;
281
- await this.executeAsyncCommando(commando, `${command} src/main/proxy.ts`);
281
+ await this.executeAsyncCommando(commando, `${this.npmCommand('tsx')} src/main/proxy.ts`);
282
282
  this.logWarning('PROXY TERMINATED');
283
283
  }
284
284
  async runEmulator() {
@@ -292,7 +292,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
292
292
  return LogLevel.Warning;
293
293
  })
294
294
  .onLog(/.*Emulator Hub running.*/, () => this.setStatus('Launch Complete'));
295
- await this.executeAsyncCommando(commando, `firebase emulators:start --project ${this.config.envConfig.projectId} --export-on-exit --import=${this.config.pathToEmulatorData} ${this.runtimeContext.runtimeParams.debugBackend
295
+ await this.executeAsyncCommando(commando, `${this.npmCommand('firebase')} emulators:start --project ${this.config.envConfig.projectId} --export-on-exit --import=${this.config.pathToEmulatorData} ${this.runtimeContext.runtimeParams.debugBackend
296
296
  ? `--inspect-functions ${this.config.debugPort}` : ''}`);
297
297
  this.logWarning('EMULATORS TERMINATED');
298
298
  }
@@ -1,13 +1,12 @@
1
1
  import { ImplementationMissingException, LogLevel } from '@nu-art/ts-common';
2
- import { promises as _fs } from 'fs';
3
- import { CONST_FirebaseJSON, CONST_FirebaseRC } from '../../../core/consts.js';
2
+ import { CONST_FirebaseJSON, CONST_FirebaseRC, CONST_VersionApp } from '../../../core/consts.js';
4
3
  import { Commando_NVM } from '@nu-art/commando/shell/plugins/nvm';
5
4
  import { Commando_Basic } from '@nu-art/commando/shell/plugins/basic';
6
5
  import { resolve } from 'path';
7
6
  import { Unit_TypescriptLib } from '../Unit_TypescriptLib.js';
8
7
  import { CommandoException } from '@nu-art/commando/shell/core/CliError';
9
8
  import { deployLogFilter } from './common.js';
10
- const CONST_VersionApp = 'version-app.json';
9
+ import { FileSystemUtils } from '@nu-art/ts-common/utils/FileSystemUtils';
11
10
  export class Unit_FirebaseHostingApp extends Unit_TypescriptLib {
12
11
  hosting = {};
13
12
  static DefaultConfig_FirebaseHosting = {
@@ -48,7 +47,7 @@ export class Unit_FirebaseHostingApp extends Unit_TypescriptLib {
48
47
  this.hosting[match[1]] = match[2];
49
48
  });
50
49
  const debug = this.runtimeContext.runtimeParams.verbose ? ' --debug' : '';
51
- await this.executeAsyncCommando(commando, `firebase${debug} deploy --only hosting`);
50
+ await this.executeAsyncCommando(commando, `${this.npmCommand('firebase')}${debug} deploy --only hosting`);
52
51
  }
53
52
  //######################### ResolveConfig Logic #########################
54
53
  getEnvConfig() {
@@ -61,7 +60,7 @@ export class Unit_FirebaseHostingApp extends Unit_TypescriptLib {
61
60
  const envConfig = this.getEnvConfig();
62
61
  const rcConfig = { projects: { default: envConfig.projectId } };
63
62
  const targetPath = `${this.config.fullPath}/${CONST_FirebaseRC}`;
64
- await _fs.writeFile(targetPath, JSON.stringify(rcConfig, null, 2), { encoding: 'utf-8' });
63
+ await FileSystemUtils.file.write.json(targetPath, rcConfig);
65
64
  }
66
65
  async resolveHostingJSON() {
67
66
  const envConfig = this.getEnvConfig();
@@ -78,13 +77,13 @@ export class Unit_FirebaseHostingApp extends Unit_TypescriptLib {
78
77
  ]
79
78
  }
80
79
  };
81
- await _fs.writeFile(targetPath, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
80
+ await FileSystemUtils.file.write.json(targetPath, fileContent);
82
81
  }
83
82
  async resolveHostingRuntimeConfig() {
84
83
  const envConfig = this.getEnvConfig().config;
85
84
  const targetPath = resolve(this.config.fullPath, `./src/main/config.ts`);
86
85
  const fileContent = `export const config = ${JSON.stringify(envConfig, null, 2)};`;
87
- await _fs.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
86
+ await FileSystemUtils.file.write(targetPath, fileContent);
88
87
  }
89
88
  //######################### Compile Logic #########################
90
89
  async compileImpl() {
@@ -100,8 +99,7 @@ export class Unit_FirebaseHostingApp extends Unit_TypescriptLib {
100
99
  //Webpack bundles files into the output automatically!
101
100
  const targetPath = `${this.config.fullPath}/src/main/${CONST_VersionApp}`;
102
101
  const appVersion = this.runtimeContext.version;
103
- const fileContent = JSON.stringify({ version: appVersion }, null, 2);
104
- await _fs.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
102
+ await FileSystemUtils.file.write.json(targetPath, { version: appVersion });
105
103
  }
106
104
  //######################### Launch Logic #########################
107
105
  async runApp() {