@nu-art/build-and-install 0.204.99 → 0.204.101

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.
@@ -5,7 +5,7 @@ const params_1 = require("./core/params/params");
5
5
  const PhaseRunner_1 = require("./v2/phase-runner/PhaseRunner");
6
6
  const thunderstorm_1 = require("./v2/unit/thunderstorm");
7
7
  ts_common_1.DebugFlag.DefaultLogLevel = params_1.RuntimeParams.debug ? ts_common_1.LogLevel.Debug : ts_common_1.LogLevel.Info;
8
- const runner = new PhaseRunner_1.PhaseRunner('./.config/project-config-v2.ts');
8
+ const runner = new PhaseRunner_1.PhaseRunner('./.config/project-config.ts');
9
9
  if (params_1.RuntimeParams.runWithThunderstorm)
10
10
  runner.registerUnits(thunderstorm_1.allTSUnits);
11
11
  runner
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "rules": {
3
3
  ".read": false,
4
- ".write": false
4
+ ".write": false,
5
+ "state": {
6
+ "ModuleBE_SyncManager": {
7
+ "syncData": {
8
+ ".read": true,
9
+ ".write": false
10
+ }
11
+ },
12
+ "ModuleBE_FocusedObject": {
13
+ "focusedData": {
14
+ ".read": true,
15
+ ".write": false
16
+ }
17
+ }
18
+ }
5
19
  }
6
- }
7
-
20
+ }
@@ -16,20 +16,24 @@ _express.all('*', (req, res) => {
16
16
 
17
17
  console.log(`PROXY ${counter} - [${req.method}] ${url}`);
18
18
 
19
+ const handleError = (error: any) => {
20
+ console.log(`ERROR calling: ${url}`, error);
21
+ };
22
+
19
23
  try {
20
24
  let reqContent;
21
25
  if (req.method === 'POST') {
22
- reqContent = request.post({uri: url, body: req.body});
26
+ reqContent = request.post({uri: url, body: req.body}, handleError);
23
27
  } else if (req.method === 'PUT') {
24
- reqContent = request.put({uri: url, body: req.body});
28
+ reqContent = request.put({uri: url, body: req.body}, handleError);
25
29
  } else if (req.method === 'GET') {
26
- reqContent = request.get(url);
30
+ reqContent = request.get(url, handleError);
27
31
  } else if (req.method === 'DELETE') {
28
- reqContent = request.delete(url);
32
+ reqContent = request.delete(url, handleError);
29
33
  } else if (req.method === 'HEAD') {
30
- reqContent = request.head(url);
34
+ reqContent = request.head(url, handleError);
31
35
  } else {
32
- reqContent = request(url);
36
+ reqContent = request(url, handleError);
33
37
  }
34
38
 
35
39
  req.pipe(reqContent).pipe(res, {end: true});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/build-and-install",
3
- "version": "0.204.99",
3
+ "version": "0.204.101",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -8,6 +8,7 @@ export declare class PhaseRunnerDispatcher<T, K extends FunctionKeys<T> = Functi
8
8
  addListener(listener: any): void;
9
9
  removeListener(listener: any): void;
10
10
  dispatch(...data: P): void;
11
+ dispatchAsync(...data: P): Promise<void>;
11
12
  }
12
13
  export interface PhaseRunner_OnPhaseChange {
13
14
  __onPhaseChange: (data: Phase<string>) => void;
@@ -23,6 +23,13 @@ class PhaseRunnerDispatcher {
23
23
  (_a = listener[this.method]) === null || _a === void 0 ? void 0 : _a.call(listener, ...data);
24
24
  });
25
25
  }
26
+ async dispatchAsync(...data) {
27
+ await Promise.all(this.listeners.map(async (listener) => {
28
+ var _a;
29
+ // @ts-ignore
30
+ return (_a = listener[this.method]) === null || _a === void 0 ? void 0 : _a.call(listener, ...data);
31
+ }));
32
+ }
26
33
  }
27
34
  exports.PhaseRunnerDispatcher = PhaseRunnerDispatcher;
28
35
  exports.dispatcher_PhaseChange = new PhaseRunnerDispatcher('__onPhaseChange');
@@ -65,17 +65,7 @@ class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
65
65
  if (!(event.button === 'middle' && event.action === 'mouseup'))
66
66
  return;
67
67
  if ((0, ts_common_1.currentTimeMillis)() - doubleClickTimestamp < 500) {
68
- try {
69
- this.toggleFullScreenMode(unitIndex);
70
- }
71
- catch (e) {
72
- console.log(e);
73
- console.log(e);
74
- console.log(e);
75
- console.log(e);
76
- console.log(e);
77
- }
78
- return;
68
+ return this.toggleFullScreenMode(unitIndex);
79
69
  }
80
70
  doubleClickTimestamp = (0, ts_common_1.currentTimeMillis)();
81
71
  });
@@ -1,7 +1,7 @@
1
1
  import { Unit_Typescript, Unit_Typescript_Config, Unit_Typescript_RuntimeConfig } from './Unit_Typescript';
2
- import { UnitPhaseImplementor, WatchEventType } from '../types';
2
+ import { UnitPhaseImplementor } from '../types';
3
3
  import { Phase_CheckCyclicImports, Phase_Compile, Phase_Lint, Phase_PreCompile, Phase_PrintDependencyTree, Phase_Purge } from '../../phase';
4
- import { OnWatchEvent } from '../runner-dispatchers';
4
+ import { OnWatchReady } from '../runner-dispatchers';
5
5
  export type Unit_TypescriptLib_Config = Unit_Typescript_Config & {
6
6
  customTSConfig?: boolean;
7
7
  output: string;
@@ -19,23 +19,26 @@ export declare class Unit_TypescriptLib<C extends Unit_TypescriptLib_Config = Un
19
19
  Phase_CheckCyclicImports,
20
20
  Phase_Purge,
21
21
  Phase_Lint
22
- ]>, OnWatchEvent {
23
- private debounceWatch?;
22
+ ]>, OnWatchReady {
24
23
  constructor(config: Unit_TypescriptLib<C, RTC>['config']);
25
- __onWatchEvent(type: WatchEventType, path?: string): Promise<void>;
24
+ __onWatchReady(): Promise<void>;
26
25
  protected init(setInitialized?: boolean): Promise<void>;
27
26
  protected resolveTSConfig(): Promise<void>;
28
27
  protected clearOutputDir(): Promise<void>;
29
28
  protected compileImpl(): Promise<void>;
30
29
  protected copyAssetsToOutput(): Promise<void>;
31
30
  protected copyPackageJSONToOutput(): Promise<void>;
32
- protected handleWatchChange(path: string, shouldRemoveDist?: boolean): Promise<void>;
31
+ /**
32
+ * Watch compile actions, use this to perform all necessary compile actions for watch.
33
+ * watch compile is a subset of the general watch action
34
+ */
35
+ watchCompile(): Promise<void>;
33
36
  /**
34
37
  * Remove the deleted file/folder from the dist folder on watch remove file event
35
38
  * @param path The path of the currently removed file/folder
36
39
  * @private
37
40
  */
38
- private removeSpecificFileFromDist;
41
+ removeSpecificFileFromDist(path: string): Promise<void>;
39
42
  preCompile(): Promise<void>;
40
43
  compile(): Promise<void>;
41
44
  purge(): Promise<void>;
@@ -32,7 +32,6 @@ const RunnerParams_1 = require("../../phase-runner/RunnerParams");
32
32
  const consts_1 = require("../../../core/consts");
33
33
  const params_1 = require("../../../core/params/params");
34
34
  const runner_dispatchers_1 = require("../runner-dispatchers");
35
- const consts_2 = require("../consts");
36
35
  const CliError_1 = require("@nu-art/commando/shell/core/CliError");
37
36
  const nvm_1 = require("@nu-art/commando/shell/plugins/nvm");
38
37
  const basic_1 = require("@nu-art/commando/shell/plugins/basic");
@@ -52,17 +51,12 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
52
51
  super(config);
53
52
  this.addToClassStack(Unit_TypescriptLib);
54
53
  }
55
- async __onWatchEvent(type, path) {
56
- if (type === consts_2.WatchEvent_Ready)
57
- return this.setStatus('Watching');
58
- if (this.debounceWatch)
59
- delete this.debounceWatch;
60
- this.debounceWatch = (0, ts_common_1.debounce)(() => this.handleWatchChange(path, [consts_2.WatchEvent_RemoveFile, consts_2.WatchEvent_RemoveDir].includes(type)), ts_common_1.Second * 2, ts_common_1.Second * 10);
61
- this.debounceWatch();
54
+ async __onWatchReady() {
55
+ return this.setStatus('Watching');
62
56
  }
63
57
  async init(setInitialized = true) {
64
58
  await super.init(false);
65
- runner_dispatchers_1.dispatcher_WatchEvent.addListener(this);
59
+ runner_dispatchers_1.dispatcher_WatchReady.addListener(this);
66
60
  this.runtime.pathTo.output = this.runtime.pathTo.pkg + `/${this.config.output}`;
67
61
  if (setInitialized)
68
62
  this.setStatus('Initialized');
@@ -131,15 +125,13 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
131
125
  const fileContent = JSON.stringify(this.packageJson.dist, null, 2);
132
126
  await fs_1.promises.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
133
127
  }
134
- async handleWatchChange(path, shouldRemoveDist = false) {
135
- // ignore if path doesn't related to unit
136
- if (!path.startsWith(this.config.pathToPackage))
137
- return;
128
+ /**
129
+ * Watch compile actions, use this to perform all necessary compile actions for watch.
130
+ * watch compile is a subset of the general watch action
131
+ */
132
+ async watchCompile() {
138
133
  try {
139
134
  this.setStatus('Compiling', 'start');
140
- // check if dist folder must be cleared
141
- if (shouldRemoveDist)
142
- await this.removeSpecificFileFromDist(path);
143
135
  // perform all watch actions
144
136
  await this.compileImpl();
145
137
  await this.copyAssetsToOutput();
@@ -148,8 +140,6 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
148
140
  catch (e) {
149
141
  this.setStatus(`Watching with error`, e);
150
142
  }
151
- // dispatch unit post compile
152
- runner_dispatchers_1.dispatcher_UnitWatchCompile.dispatch(this);
153
143
  }
154
144
  /**
155
145
  * Remove the deleted file/folder from the dist folder on watch remove file event
@@ -157,6 +147,7 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
157
147
  * @private
158
148
  */
159
149
  async removeSpecificFileFromDist(path) {
150
+ this.setStatus('Removing files from dist', 'start');
160
151
  const distPathBase = path.replace('src/main', 'dist').replace(/\.ts$/, '');
161
152
  const pathsToDelete = [
162
153
  `${distPathBase}.js`,
@@ -172,6 +163,7 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
172
163
  }
173
164
  await fs_1.promises.rm(path, { recursive: true, force: true });
174
165
  }
166
+ this.setStatus('Files Removed and watching', 'end');
175
167
  }
176
168
  //######################### Phase Implementations #########################
177
169
  async preCompile() {
@@ -7,6 +7,7 @@ type Unit_TypescriptProject_Config = Unit_Typescript_Config & {
7
7
  };
8
8
  type Unit_TypescriptProject_RuntimeConfig = Unit_Typescript_RuntimeConfig & {};
9
9
  export declare class Unit_TypescriptProject<C extends Unit_TypescriptProject_Config = Unit_TypescriptProject_Config, RTC extends Unit_TypescriptProject_RuntimeConfig = Unit_TypescriptProject_RuntimeConfig> extends Unit_Typescript<C, RTC> implements UnitPhaseImplementor<[Phase_Install, Phase_Watch]> {
10
+ private watchDebounce;
10
11
  private readonly suffixesToWatch;
11
12
  constructor(config: Unit_TypescriptProject<C>['config']);
12
13
  private installGlobals;
@@ -22,6 +23,7 @@ export declare class Unit_TypescriptProject<C extends Unit_TypescriptProject_Con
22
23
  * @private
23
24
  */
24
25
  private initWatch;
26
+ private findUnit;
25
27
  private watchImpl;
26
28
  install(): Promise<void>;
27
29
  watch(): Promise<void>;
@@ -30,7 +30,6 @@ const ts_common_1 = require("@nu-art/ts-common");
30
30
  const consts_1 = require("../../phase-runner/consts");
31
31
  const chokidar = __importStar(require("chokidar"));
32
32
  const runner_dispatchers_1 = require("../runner-dispatchers");
33
- const consts_2 = require("../consts");
34
33
  const Unit_TypescriptLib_1 = require("./Unit_TypescriptLib");
35
34
  const firebase_units_1 = require("../firebase-units");
36
35
  const nvm_1 = require("@nu-art/commando/shell/plugins/nvm");
@@ -46,6 +45,13 @@ class Unit_TypescriptProject extends Unit_Typescript_1.Unit_Typescript {
46
45
  'json',
47
46
  'svg'
48
47
  ];
48
+ this.findUnit = (pathDeclarations, currentPath) => {
49
+ var _a;
50
+ const unitToReturn = (_a = pathDeclarations.find(declaration => currentPath.startsWith(declaration.pathToPackage))) === null || _a === void 0 ? void 0 : _a.unit;
51
+ if (!unitToReturn)
52
+ throw new ts_common_1.MUSTNeverHappenException(`current path doesnt match any declared unit, current path: ${currentPath}`);
53
+ return unitToReturn;
54
+ };
49
55
  this.addToClassStack(Unit_TypescriptProject);
50
56
  }
51
57
  //######################### Internal Logic #########################
@@ -86,8 +92,12 @@ class Unit_TypescriptProject extends Unit_Typescript_1.Unit_Typescript {
86
92
  .filter(unit => unit.isInstanceOf(Unit_TypescriptLib_1.Unit_TypescriptLib) && cantBeInstanceOf.every(_instance => !unit.isInstanceOf(_instance)));
87
93
  //return all paths to watch
88
94
  return projectLibs.map(lib => {
89
- const sourceFolder = `${lib.config.pathToPackage}/src/main`;
90
- return { paths: this.suffixesToWatch.map(suffix => `${sourceFolder}/**/*.${suffix}`), unit: lib };
95
+ const sourceFolder = `${lib.runtime.pathTo.pkg}/src/main`;
96
+ return {
97
+ paths: this.suffixesToWatch.map(suffix => `${sourceFolder}/**/*.${suffix}`),
98
+ unit: lib,
99
+ pathToPackage: lib.runtime.pathTo.pkg
100
+ };
91
101
  });
92
102
  }
93
103
  /**
@@ -101,25 +111,65 @@ class Unit_TypescriptProject extends Unit_Typescript_1.Unit_Typescript {
101
111
  // set all events to watch and handle them
102
112
  return new Promise((resolve, error) => {
103
113
  this.logInfo('Starting the watcher...');
114
+ const units = new Set();
115
+ const pathsToDelete = [];
116
+ const onUnitChange = (path) => {
117
+ const unit = this.findUnit(pathDeclarations, path);
118
+ // @ts-ignore - FIXME: should be a better way
119
+ unit.setStatus('Dirty');
120
+ //add unit to set
121
+ units.add(unit);
122
+ return unit;
123
+ };
124
+ // set the debounce event
125
+ this.watchDebounce = (0, ts_common_1.queuedDebounce)(async () => {
126
+ const _pathsToDelete = [...pathsToDelete];
127
+ const unitsToCompile = Array.from(units.values());
128
+ // clear values in order to start collecting values for next debounce
129
+ (0, ts_common_1.clearArrayInstance)(pathsToDelete);
130
+ units.clear();
131
+ // fire all delete events
132
+ await (0, ts_common_1.Promise_all_sequentially)(_pathsToDelete.map(path => {
133
+ return async () => path.unit.removeSpecificFileFromDist(path.path);
134
+ }));
135
+ // fire all compile events
136
+ await (0, ts_common_1.Promise_all_sequentially)(unitsToCompile.map(unit => {
137
+ return async () => unit.watchCompile();
138
+ }));
139
+ //dispatch post debounce event to parent
140
+ await runner_dispatchers_1.dispatcher_UnitWatchCompile.dispatchAsync(unitsToCompile);
141
+ }, 2 * ts_common_1.Second, 10 * ts_common_1.Second);
104
142
  watcher
105
143
  .on('error', (error) => {
106
144
  this.logError('Error while watching', error);
107
145
  })
108
146
  .on('ready', () => {
109
147
  this.logInfo('Watching...');
110
- runner_dispatchers_1.dispatcher_WatchEvent.dispatch(consts_2.WatchEvent_Ready);
148
+ runner_dispatchers_1.dispatcher_WatchReady.dispatch();
111
149
  watcher
112
150
  .on('add', (path) => {
113
- runner_dispatchers_1.dispatcher_WatchEvent.dispatch(consts_2.WatchEvent_Add, path);
151
+ onUnitChange(path);
152
+ //trigger debounce
153
+ this.watchDebounce();
114
154
  })
115
155
  .on('change', (path) => {
116
- runner_dispatchers_1.dispatcher_WatchEvent.dispatch(consts_2.WatchEvent_Update, path);
156
+ onUnitChange(path);
157
+ //trigger debounce
158
+ this.watchDebounce();
117
159
  })
118
160
  .on('unlinkDir', (path) => {
119
- runner_dispatchers_1.dispatcher_WatchEvent.dispatch(consts_2.WatchEvent_RemoveDir, path);
161
+ const unit = onUnitChange(path);
162
+ //update paths to delete
163
+ pathsToDelete.push({ path, unit });
164
+ //trigger debounce
165
+ this.watchDebounce();
120
166
  })
121
167
  .on('unlink', (path) => {
122
- runner_dispatchers_1.dispatcher_WatchEvent.dispatch(consts_2.WatchEvent_RemoveFile, path);
168
+ const unit = onUnitChange(path);
169
+ //update paths to delete
170
+ pathsToDelete.push({ path, unit });
171
+ //trigger debounce
172
+ this.watchDebounce();
123
173
  });
124
174
  });
125
175
  const terminatable = async () => {
@@ -9,7 +9,7 @@ export type Unit_FirebaseFunctionsApp_Config = Unit_TypescriptLib_Config & {
9
9
  };
10
10
  export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsApp_Config = Unit_FirebaseFunctionsApp_Config> extends Unit_TypescriptLib<C> implements UnitPhaseImplementor<[Phase_ResolveConfigs, Phase_Launch, Phase_DeployBackend]>, OnUnitWatchCompiled {
11
11
  static staggerCount: number;
12
- __onUnitWatchCompiled(unit: BaseUnit): Promise<void>;
12
+ __onUnitWatchCompiled(units: BaseUnit[]): Promise<void>;
13
13
  constructor(config: Unit_FirebaseFunctionsApp<C>['config']);
14
14
  protected init(setInitialized?: boolean): Promise<void>;
15
15
  resolveConfigs(): Promise<void>;
@@ -13,8 +13,8 @@ const runner_dispatchers_1 = require("../runner-dispatchers");
13
13
  const nvm_1 = require("@nu-art/commando/shell/plugins/nvm");
14
14
  const CONST_VersionApp = 'version-app.json';
15
15
  class Unit_FirebaseFunctionsApp extends core_1.Unit_TypescriptLib {
16
- async __onUnitWatchCompiled(unit) {
17
- if (this.runtime.unitDependencyNames.includes(unit.runtime.dependencyName)) {
16
+ async __onUnitWatchCompiled(units) {
17
+ if (units.some(unit => this.runtime.unitDependencyNames.includes(unit.runtime.dependencyName))) {
18
18
  this.setStatus('Compiling', 'start');
19
19
  try {
20
20
  await this.compileImpl();
@@ -36,7 +36,7 @@ class Unit_FirebaseFunctionsApp extends core_1.Unit_TypescriptLib {
36
36
  async init(setInitialized = true) {
37
37
  await super.init(false);
38
38
  // only sign on listeners when the unit is being initialized
39
- runner_dispatchers_1.dispatcher_WatchEvent.removeListener(this);
39
+ runner_dispatchers_1.dispatcher_WatchReady.removeListener(this);
40
40
  runner_dispatchers_1.dispatcher_UnitWatchCompile.addListener(this);
41
41
  if (setInitialized)
42
42
  this.setStatus('Initialized');
@@ -19,7 +19,7 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
19
19
  }
20
20
  async init(setInitialized = true) {
21
21
  await super.init(setInitialized);
22
- runner_dispatchers_1.dispatcher_WatchEvent.removeListener(this);
22
+ runner_dispatchers_1.dispatcher_WatchReady.removeListener(this);
23
23
  if (!this.config.firebaseConfig.hostingPort)
24
24
  throw new ts_common_1.BadImplementationException(`Unit ${this.config.label} missing hosting port in firebaseConfig`);
25
25
  }
@@ -81,21 +81,17 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
81
81
  hostname: 'localhost',
82
82
  port: this.config.firebaseConfig.basePort + 2,
83
83
  };
84
- const feConfig = {
85
- ModuleFE_Thunderstorm: {
84
+ const feConfig = Object.assign({ ModuleFE_Thunderstorm: {
86
85
  appName: `${this.config.key} - (${envConfig.env})`
87
- },
88
- ModuleFE_XHR: {
86
+ }, ModuleFE_XHR: {
89
87
  origin: envConfig.isLocal ? `https://localhost:${this.config.firebaseConfig.basePort}` : envConfig.backend.url,
90
88
  timeout: envConfig.backend.timeout || 30000,
91
89
  compress: envConfig.backend.compress || false,
92
90
  minLogLevel: envConfig.backend.minLogLevel || false,
93
- },
94
- ModuleFE_FirebaseListener: {
91
+ }, ModuleFE_FirebaseListener: {
95
92
  emulatorConfig: envConfig.isLocal ? emulatorConfig : undefined,
96
93
  firebaseConfig: (_a = envConfig.firebase.listener) === null || _a === void 0 ? void 0 : _a.config
97
- }
98
- };
94
+ } }, envConfig.otherConfig);
99
95
  const targetPath = (0, tools_1.convertToFullPath)(`${this.config.pathToPackage}/src/main/config.ts`);
100
96
  const fileContent = `export const config = ${JSON.stringify(feConfig, null, 2)};`;
101
97
  await fs_1.promises.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
@@ -1,11 +1,10 @@
1
1
  import { PhaseRunnerDispatcher } from '../phase-runner/PhaseRunnerDispatcher';
2
- import { WatchEventType } from './types';
3
2
  import { BaseUnit } from './core';
4
- export interface OnWatchEvent {
5
- __onWatchEvent: (type: WatchEventType, path?: string) => void;
3
+ export interface OnWatchReady {
4
+ __onWatchReady: () => void;
6
5
  }
7
- export declare const dispatcher_WatchEvent: PhaseRunnerDispatcher<OnWatchEvent, "__onWatchEvent", [type: WatchEventType, path?: string | undefined]>;
6
+ export declare const dispatcher_WatchReady: PhaseRunnerDispatcher<OnWatchReady, "__onWatchReady", []>;
8
7
  export interface OnUnitWatchCompiled {
9
- __onUnitWatchCompiled: (init: BaseUnit) => void;
8
+ __onUnitWatchCompiled: (units: BaseUnit[]) => void;
10
9
  }
11
- export declare const dispatcher_UnitWatchCompile: PhaseRunnerDispatcher<OnUnitWatchCompiled, "__onUnitWatchCompiled", [init: BaseUnit<import("./core").BaseUnit_Config, import("./core").BaseUnit_RuntimeConfig>]>;
10
+ export declare const dispatcher_UnitWatchCompile: PhaseRunnerDispatcher<OnUnitWatchCompiled, "__onUnitWatchCompiled", [units: BaseUnit<import("./core").BaseUnit_Config, import("./core").BaseUnit_RuntimeConfig>[]]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dispatcher_UnitWatchCompile = exports.dispatcher_WatchEvent = void 0;
3
+ exports.dispatcher_UnitWatchCompile = exports.dispatcher_WatchReady = void 0;
4
4
  const PhaseRunnerDispatcher_1 = require("../phase-runner/PhaseRunnerDispatcher");
5
- exports.dispatcher_WatchEvent = new PhaseRunnerDispatcher_1.PhaseRunnerDispatcher('__onWatchEvent');
5
+ exports.dispatcher_WatchReady = new PhaseRunnerDispatcher_1.PhaseRunnerDispatcher('__onWatchReady');
6
6
  exports.dispatcher_UnitWatchCompile = new PhaseRunnerDispatcher_1.PhaseRunnerDispatcher('__onUnitWatchCompiled');
@@ -1,24 +0,0 @@
1
- import { FirebaseEnvConfig, Package_FirebaseFunctionsApp, Package_FirebaseHostingAndFunctionApp, Package_FirebaseHostingApp } from '../types';
2
- export declare function createFirebaseHostingConfig<Env extends string>(pkg: Package_FirebaseHostingApp, env: Env): {
3
- projects: {
4
- default: string;
5
- };
6
- };
7
- export declare function createFirebaseFunctionConfig<Env extends string>(pkg: Package_FirebaseHostingApp, env: Env): void;
8
- export declare function createFirebaseRC<Env extends string>(pkg: Package_FirebaseHostingApp | Package_FirebaseFunctionsApp, env: Env): {
9
- projects: {
10
- default: string;
11
- };
12
- };
13
- export declare function writeToFile_HostingFirebaseJSON<Env extends string>(pkg: Package_FirebaseHostingApp | Package_FirebaseHostingAndFunctionApp, env: Env): Promise<void>;
14
- export declare function writeToFile_HostingFirebaseConfigJSON<Env extends string>(pkg: Package_FirebaseHostingApp | Package_FirebaseHostingAndFunctionApp, env: Env): Promise<void>;
15
- export declare function writeToFile_functionFirebaseConfigJSON<Env extends string>(pkg: Package_FirebaseFunctionsApp | Package_FirebaseHostingAndFunctionApp, env: Env): Promise<void>;
16
- export declare function writeToFile_FunctionFirebaseJSON<Env extends string>(pkg: Package_FirebaseFunctionsApp | Package_FirebaseHostingAndFunctionApp, env: Env): Promise<void>;
17
- export declare function createFirebaseFullJSON<Env extends string>(pkg: Package_FirebaseHostingAndFunctionApp, env: Env): {
18
- then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
19
- catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<void | TResult>;
20
- finally(onfinally?: (() => void) | null | undefined): Promise<void>;
21
- [Symbol.toStringTag]: string;
22
- };
23
- export declare function getEnvConfig(pkg: Package_FirebaseHostingApp | Package_FirebaseFunctionsApp | Package_FirebaseHostingAndFunctionApp): FirebaseEnvConfig<string>;
24
- export declare function generateProxyFile(firebasePkg: Package_FirebaseHostingApp | Package_FirebaseFunctionsApp, pathToFile: string): Promise<void>;
@@ -1,180 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateProxyFile = exports.getEnvConfig = exports.createFirebaseFullJSON = exports.writeToFile_FunctionFirebaseJSON = exports.writeToFile_functionFirebaseConfigJSON = exports.writeToFile_HostingFirebaseConfigJSON = exports.writeToFile_HostingFirebaseJSON = exports.createFirebaseRC = exports.createFirebaseFunctionConfig = exports.createFirebaseHostingConfig = void 0;
4
- const ts_common_1 = require("@nu-art/ts-common");
5
- const fs_1 = require("fs");
6
- const consts_1 = require("../consts");
7
- const consts_2 = require("../../defaults/consts");
8
- const params_1 = require("../params/params");
9
- function createFirebaseHostingConfig(pkg, env) {
10
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
11
- if (!envConfig)
12
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
13
- return {
14
- projects: {
15
- default: envConfig.projectId,
16
- }
17
- };
18
- }
19
- exports.createFirebaseHostingConfig = createFirebaseHostingConfig;
20
- function createFirebaseFunctionConfig(pkg, env) {
21
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
22
- if (!envConfig)
23
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
24
- return;
25
- }
26
- exports.createFirebaseFunctionConfig = createFirebaseFunctionConfig;
27
- function createFirebaseRC(pkg, env) {
28
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
29
- if (!envConfig)
30
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
31
- return {
32
- projects: {
33
- default: envConfig.projectId,
34
- }
35
- };
36
- }
37
- exports.createFirebaseRC = createFirebaseRC;
38
- function getHostingConfig(pkg, envConfig) {
39
- if (envConfig.isLocal)
40
- return {};
41
- return {
42
- hosting: pkg.envConfig.hosting
43
- };
44
- }
45
- async function writeToFile_HostingFirebaseJSON(pkg, env) {
46
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
47
- if (!envConfig)
48
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
49
- const fileContent = getHostingConfig(pkg, envConfig);
50
- await fs_1.promises.writeFile(`${pkg.path}/${consts_1.CONST_FirebaseJSON}`, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
51
- }
52
- exports.writeToFile_HostingFirebaseJSON = writeToFile_HostingFirebaseJSON;
53
- async function writeToFile_HostingFirebaseConfigJSON(pkg, env) {
54
- var _a;
55
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
56
- if (!envConfig)
57
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
58
- const emulatorConfig = {
59
- hostname: 'localhost',
60
- port: pkg.envConfig.basePort + 2,
61
- };
62
- const feConfig = {
63
- ModuleFE_Thunderstorm: {
64
- appName: `${pkg.name} - (${env})`
65
- },
66
- ModuleFE_XHR: {
67
- origin: envConfig.isLocal ? `https://localhost:${pkg.envConfig.basePort}` : envConfig.backend.url,
68
- timeout: envConfig.backend.timeout || 30000,
69
- compress: envConfig.backend.compress || false,
70
- minLogLevel: envConfig.backend.minLogLevel || false,
71
- },
72
- ModuleFE_FirebaseListener: {
73
- emulatorConfig: envConfig.isLocal ? emulatorConfig : undefined,
74
- firebaseConfig: (_a = envConfig.firebase.listener) === null || _a === void 0 ? void 0 : _a.config
75
- }
76
- };
77
- const fileContent = `export const config = ${JSON.stringify(feConfig, null, 2)};`;
78
- await fs_1.promises.writeFile(`${pkg.path}/src/main/config.ts`, fileContent, { encoding: 'utf-8' });
79
- }
80
- exports.writeToFile_HostingFirebaseConfigJSON = writeToFile_HostingFirebaseConfigJSON;
81
- async function writeToFile_functionFirebaseConfigJSON(pkg, env) {
82
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
83
- if (!envConfig)
84
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
85
- const beConfig = {
86
- name: envConfig.env
87
- };
88
- const fileContent = `${envConfig.isLocal ? '// @ts-ignore\nprocess.env[\'NODE_TLS_REJECT_UNAUTHORIZED\'] = 0;\n' : ''}
89
- export const Environment = ${JSON.stringify(beConfig)};`;
90
- await fs_1.promises.writeFile(`${pkg.path}/src/main/config.ts`, fileContent, { encoding: 'utf-8' });
91
- }
92
- exports.writeToFile_functionFirebaseConfigJSON = writeToFile_functionFirebaseConfigJSON;
93
- function getFunctionConfig(pkg, envConfig) {
94
- var _a, _b;
95
- if (envConfig.isLocal) {
96
- const port = pkg.envConfig.basePort;
97
- return {
98
- database: {
99
- rules: `${pkg.envConfig.pathToFirebaseConfig}/database.rules.json`
100
- },
101
- firestore: {
102
- rules: `${pkg.envConfig.pathToFirebaseConfig}/firestore.rules`,
103
- indexes: `${pkg.envConfig.pathToFirebaseConfig}/firestore.indexes.json`
104
- },
105
- storage: {
106
- rules: `${pkg.envConfig.pathToFirebaseConfig}/storage.rules`
107
- },
108
- remoteconfig: {
109
- template: `${pkg.envConfig.pathToFirebaseConfig}/remoteconfig.template.json`
110
- },
111
- functions: {
112
- ignore: (_a = pkg.envConfig.functions) === null || _a === void 0 ? void 0 : _a.ignore,
113
- source: '.',
114
- predeploy: [
115
- 'echo "Thunderstorm - Local environment is not deployable... Aborting..." && exit 2'
116
- ]
117
- },
118
- emulators: {
119
- functions: { port: port + 1 },
120
- database: { port: port + 2 },
121
- firestore: {
122
- port: port + 3,
123
- websocketPort: port + 4
124
- },
125
- pubsub: { port: port + 5 },
126
- storage: { port: port + 6 },
127
- auth: { port: port + 7 },
128
- ui: { port: port + 8, enabled: true },
129
- hub: { port: port + 9 },
130
- logging: { port: port + 10 }
131
- }
132
- };
133
- }
134
- else {
135
- return {
136
- functions: {
137
- source: pkg.output.replace(`${pkg.path}/`, ''),
138
- ignore: (_b = pkg.envConfig.functions) === null || _b === void 0 ? void 0 : _b.ignore
139
- }
140
- };
141
- }
142
- }
143
- async function writeToFile_FunctionFirebaseJSON(pkg, env) {
144
- const envConfig = getEnvConfig(pkg);
145
- const fileContent = getFunctionConfig(pkg, envConfig);
146
- await fs_1.promises.writeFile(`${pkg.path}/${consts_1.CONST_FirebaseJSON}`, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
147
- }
148
- exports.writeToFile_FunctionFirebaseJSON = writeToFile_FunctionFirebaseJSON;
149
- function createFirebaseFullJSON(pkg, env) {
150
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
151
- if (!envConfig)
152
- throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
153
- const hosting = writeToFile_HostingFirebaseJSON(pkg, env);
154
- const functions = writeToFile_FunctionFirebaseJSON(pkg, env);
155
- return Object.assign(Object.assign({}, hosting), functions);
156
- }
157
- exports.createFirebaseFullJSON = createFirebaseFullJSON;
158
- function getEnvConfig(pkg) {
159
- const env = params_1.RuntimeParams.environment;
160
- const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
161
- if (!envConfig)
162
- throw new ts_common_1.BadImplementationException(`No env config for env ${env} in package ${pkg.name}`);
163
- return envConfig;
164
- }
165
- exports.getEnvConfig = getEnvConfig;
166
- async function generateProxyFile(firebasePkg, pathToFile) {
167
- var _a, _b, _c;
168
- const envConfig = getEnvConfig(firebasePkg);
169
- const defaultFiles = consts_2.MemKey_DefaultFiles.get();
170
- if (!((_a = defaultFiles === null || defaultFiles === void 0 ? void 0 : defaultFiles.backend) === null || _a === void 0 ? void 0 : _a.proxy))
171
- return;
172
- let fileContent = await fs_1.promises.readFile(defaultFiles.backend.proxy, { encoding: 'utf-8' });
173
- fileContent = fileContent.replace(/PROJECT_ID/g, `${envConfig.projectId}`);
174
- fileContent = fileContent.replace(/PROXY_PORT/g, `${firebasePkg.envConfig.basePort}`);
175
- fileContent = fileContent.replace(/SERVER_PORT/g, `${firebasePkg.envConfig.basePort + 1}`);
176
- fileContent = fileContent.replace(/PATH_TO_SSL_KEY/g, `${(_b = firebasePkg.envConfig.ssl) === null || _b === void 0 ? void 0 : _b.pathToKey}`);
177
- fileContent = fileContent.replace(/PATH_TO_SSL_CERTIFICATE/g, `${(_c = firebasePkg.envConfig.ssl) === null || _c === void 0 ? void 0 : _c.pathToCertificate}`);
178
- await fs_1.promises.writeFile(pathToFile, fileContent, { encoding: 'utf-8' });
179
- }
180
- exports.generateProxyFile = generateProxyFile;