@nu-art/build-and-install 0.204.67 → 0.204.68
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.
- package/build-and-install.js +11 -26
- package/core/package/generate.js +5 -3
- package/core/params/params.d.ts +3 -2
- package/core/params/params.js +16 -4
- package/defaults/consts.d.ts +11 -23
- package/defaults/consts.js +7 -7
- package/package.json +1 -1
- package/phases/phases.js +7 -3
- package/screen/ProjectScreen.js +0 -1
- package/v2/phase/consts.d.ts +53 -0
- package/v2/phase/consts.js +146 -0
- package/v2/phase/index.d.ts +2 -0
- package/v2/phase/index.js +18 -0
- package/v2/phase/types.d.ts +9 -0
- package/v2/phase/types.js +2 -0
- package/v2/phase-runner/PhaseRunner.d.ts +69 -13
- package/v2/phase-runner/PhaseRunner.js +392 -32
- package/v2/phase-runner/PhaseRunnerDispatcher.d.ts +25 -0
- package/v2/phase-runner/PhaseRunnerDispatcher.js +26 -0
- package/v2/phase-runner/RunnerParams.d.ts +12 -0
- package/v2/phase-runner/RunnerParams.js +9 -0
- package/v2/phase-runner/consts.d.ts +7 -0
- package/v2/phase-runner/consts.js +9 -0
- package/v2/phase-runner/types.d.ts +6 -9
- package/v2/phase-runner/types.js +4 -0
- package/v2/project/types.d.ts +8 -0
- package/v2/project/types.js +2 -0
- package/v2/screens/list-screen.d.ts +47 -0
- package/v2/screens/list-screen.js +196 -0
- package/v2/unit/core/BaseUnit.d.ts +18 -7
- package/v2/unit/core/BaseUnit.js +35 -10
- package/v2/unit/core/Unit_Python.d.ts +18 -2
- package/v2/unit/core/Unit_Python.js +30 -1
- package/v2/unit/core/Unit_Typescript.d.ts +15 -13
- package/v2/unit/core/Unit_Typescript.js +40 -36
- package/v2/unit/core/Unit_TypescriptLib.d.ts +27 -3
- package/v2/unit/core/Unit_TypescriptLib.js +98 -4
- package/v2/unit/core/Unit_TypescriptProject.d.ts +11 -2
- package/v2/unit/core/Unit_TypescriptProject.js +29 -0
- package/v2/unit/core/index.d.ts +2 -1
- package/v2/unit/core/index.js +2 -1
- package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.d.ts +40 -0
- package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.js +312 -0
- package/v2/unit/firebase-units/Unit_FirebaseHostingApp.d.ts +32 -0
- package/v2/unit/firebase-units/Unit_FirebaseHostingApp.js +159 -0
- package/v2/unit/firebase-units/index.d.ts +2 -0
- package/v2/unit/firebase-units/index.js +18 -0
- package/v2/unit/thunderstorm.d.ts +291 -0
- package/v2/unit/thunderstorm.js +199 -0
- package/v2/unit/types.d.ts +7 -0
- package/v2/unit/types.js +2 -0
- package/v2/BasePackage.d.ts +0 -4
- package/v2/BasePackage.js +0 -9
- package/v2/ProjectManagerV2.d.ts +0 -8
- package/v2/ProjectManagerV2.js +0 -23
- package/v2/test/test.d.ts +0 -14
- package/v2/test/test.js +0 -85
- package/v2/unit/core/types.d.ts +0 -13
- package/v2/unit/core/types.js +0 -23
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BAI_ListScreen = void 0;
|
|
4
|
+
const ConsoleContainer_1 = require("@nu-art/commando/console/ConsoleContainer");
|
|
5
|
+
const PhaseRunnerDispatcher_1 = require("../phase-runner/PhaseRunnerDispatcher");
|
|
6
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
7
|
+
class BAI_ListScreen extends ConsoleContainer_1.ConsoleContainer {
|
|
8
|
+
//######################### Lifecycle #########################
|
|
9
|
+
__onPhaseChange(phase) {
|
|
10
|
+
this.setState({ currentPhaseName: phase.name });
|
|
11
|
+
}
|
|
12
|
+
__onUnitStatusChange(unit) {
|
|
13
|
+
this.renderUnitList();
|
|
14
|
+
this.container.screen.render();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of ConsoleScreen.
|
|
18
|
+
*
|
|
19
|
+
* @param units - The units this screen should keep track of
|
|
20
|
+
* @param {Widgets.IScreenOptions} [props] - The properties to apply to the screen widget.
|
|
21
|
+
* @param {ScreenKeyBinding[]} [keyBinding] - An array of key bindings for the screen widget.
|
|
22
|
+
*/
|
|
23
|
+
constructor(units, props, keyBinding = []) {
|
|
24
|
+
super('screen', { smartCSR: true, title: 'Build and Install' }, [{
|
|
25
|
+
keys: ['escape', 'q', 'C-c'],
|
|
26
|
+
callback: async () => {
|
|
27
|
+
var _a;
|
|
28
|
+
this.logInfo('Kill command received');
|
|
29
|
+
await ((_a = this.onKillCB) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
30
|
+
this.logInfo('Killed!');
|
|
31
|
+
return process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}]);
|
|
34
|
+
this.unitWidgets = [];
|
|
35
|
+
this.units = units;
|
|
36
|
+
}
|
|
37
|
+
initLogger() {
|
|
38
|
+
this.logClient = new ts_common_1.LogClient_MemBuffer('log-out.txt');
|
|
39
|
+
ts_common_1.BeLogged.removeConsole(ts_common_1.LogClient_Terminal);
|
|
40
|
+
ts_common_1.BeLogged.addClient(this.logClient);
|
|
41
|
+
this.logClient.setForTerminal();
|
|
42
|
+
this.logClient.setComposer((tag, level) => {
|
|
43
|
+
ts_common_1._logger_finalDate.setTime(Date.now() - ts_common_1._logger_timezoneOffset);
|
|
44
|
+
const date = ts_common_1._logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23).split('_')[1];
|
|
45
|
+
return ` ${date} ${(0, ts_common_1._logger_getPrefix)(level)} ${tag}: `;
|
|
46
|
+
});
|
|
47
|
+
this.logClient.setLogAppendedListener(() => {
|
|
48
|
+
this.renderLogs();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//######################### Content Creation #########################
|
|
52
|
+
create() {
|
|
53
|
+
if (!this.logClient)
|
|
54
|
+
this.initLogger();
|
|
55
|
+
super.create();
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
createContent() {
|
|
59
|
+
this.createPhaseWidget();
|
|
60
|
+
this.createUnitListWidget();
|
|
61
|
+
this.createLogWidget();
|
|
62
|
+
PhaseRunnerDispatcher_1.dispatcher_UnitStatusChange.addListener(this);
|
|
63
|
+
PhaseRunnerDispatcher_1.dispatcher_PhaseChange.addListener(this);
|
|
64
|
+
}
|
|
65
|
+
createPhaseWidget() {
|
|
66
|
+
const props = {
|
|
67
|
+
top: 0,
|
|
68
|
+
left: 0,
|
|
69
|
+
height: 3,
|
|
70
|
+
width: '30%',
|
|
71
|
+
content: 'phases',
|
|
72
|
+
border: { type: 'line' },
|
|
73
|
+
tags: true,
|
|
74
|
+
styles: {
|
|
75
|
+
border: { fg: 'blue' },
|
|
76
|
+
fg: 'blue',
|
|
77
|
+
},
|
|
78
|
+
align: 'center',
|
|
79
|
+
};
|
|
80
|
+
this.phaseWidget = this.createWidget('text', props);
|
|
81
|
+
}
|
|
82
|
+
createUnitListWidget() {
|
|
83
|
+
const props = {
|
|
84
|
+
top: 3,
|
|
85
|
+
left: 0,
|
|
86
|
+
bottom: 0,
|
|
87
|
+
width: '30%',
|
|
88
|
+
border: { type: 'line' },
|
|
89
|
+
align: 'left',
|
|
90
|
+
style: {
|
|
91
|
+
border: { fg: 'blue' },
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
this.unitWrapperWidget = this.createWidget('list', props);
|
|
95
|
+
this.units.forEach((unit, i) => this.createUnitItemWidget(unit, i));
|
|
96
|
+
}
|
|
97
|
+
createUnitItemWidget(unit, index) {
|
|
98
|
+
const containerProps = {
|
|
99
|
+
top: (this.unitWrapperWidget.top + 1) + index,
|
|
100
|
+
width: '30%-3',
|
|
101
|
+
left: 2,
|
|
102
|
+
height: 1,
|
|
103
|
+
};
|
|
104
|
+
const labelProps = {
|
|
105
|
+
width: '50%',
|
|
106
|
+
height: '100%',
|
|
107
|
+
left: 0,
|
|
108
|
+
align: 'left',
|
|
109
|
+
style: {
|
|
110
|
+
fg: 'blue',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const statusProps = {
|
|
114
|
+
width: '50%',
|
|
115
|
+
height: '100%',
|
|
116
|
+
right: 0,
|
|
117
|
+
align: 'right',
|
|
118
|
+
style: {
|
|
119
|
+
fg: 'blue',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
const containerWidget = this.createWidget('box', containerProps);
|
|
123
|
+
const labelWidget = this.createWidget('text', labelProps);
|
|
124
|
+
const statusWidget = this.createWidget('text', statusProps);
|
|
125
|
+
containerWidget.on('mousedown', () => this.onUnitSelect(unit, index));
|
|
126
|
+
containerWidget.append(labelWidget);
|
|
127
|
+
containerWidget.append(statusWidget);
|
|
128
|
+
this.unitWrapperWidget.pushItem(containerWidget);
|
|
129
|
+
this.unitWidgets.push([containerWidget, labelWidget, statusWidget]);
|
|
130
|
+
}
|
|
131
|
+
createLogWidget() {
|
|
132
|
+
const props = {
|
|
133
|
+
top: 0,
|
|
134
|
+
right: 0,
|
|
135
|
+
bottom: 0,
|
|
136
|
+
width: '70%',
|
|
137
|
+
border: { type: 'line' },
|
|
138
|
+
style: {
|
|
139
|
+
border: { fg: 'blue' }
|
|
140
|
+
},
|
|
141
|
+
valign: 'top',
|
|
142
|
+
align: 'left',
|
|
143
|
+
mouse: true,
|
|
144
|
+
};
|
|
145
|
+
this.logWidget = this.createWidget('log', props);
|
|
146
|
+
}
|
|
147
|
+
//######################### Render #########################
|
|
148
|
+
render() {
|
|
149
|
+
this.renderPhase();
|
|
150
|
+
this.renderUnitList();
|
|
151
|
+
this.renderLogs();
|
|
152
|
+
}
|
|
153
|
+
renderPhase() {
|
|
154
|
+
var _a;
|
|
155
|
+
this.phaseWidget.setContent((_a = this.state.currentPhaseName) !== null && _a !== void 0 ? _a : 'Initializing');
|
|
156
|
+
}
|
|
157
|
+
renderUnitList() {
|
|
158
|
+
this.units.forEach((unit, index) => {
|
|
159
|
+
var _a;
|
|
160
|
+
const selected = unit === this.state.selectedUnit;
|
|
161
|
+
const widgets = this.unitWidgets[index];
|
|
162
|
+
widgets[1].setText(unit.config.label);
|
|
163
|
+
widgets[2].setText((_a = unit.getStatus()) !== null && _a !== void 0 ? _a : 'N/A');
|
|
164
|
+
widgets[1].style.bg = selected ? 'blue' : undefined;
|
|
165
|
+
widgets[1].style.fg = selected ? 'white' : 'blue';
|
|
166
|
+
widgets[2].style.bg = selected ? 'blue' : undefined;
|
|
167
|
+
widgets[2].style.fg = selected ? 'white' : 'blue';
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
renderLogs() {
|
|
171
|
+
const scrollPosition = this.logWidget.getScroll();
|
|
172
|
+
const content = this.state.selectedUnit ? this.state.selectedUnit.getLogs() : this.logClient.buffers[0];
|
|
173
|
+
this.logWidget.setContent(content);
|
|
174
|
+
this.logWidget.setScroll(scrollPosition);
|
|
175
|
+
}
|
|
176
|
+
//######################### Kill #########################
|
|
177
|
+
setKillCB(cb) {
|
|
178
|
+
this.onKillCB = cb;
|
|
179
|
+
// Remove all listeners to the process kill event
|
|
180
|
+
// process.listeners('SIGINT').forEach(listener => process.removeListener('SIGINT', listener));
|
|
181
|
+
//Register a new listener for process kill event
|
|
182
|
+
// process.on('SIGINT', async () => {
|
|
183
|
+
// await cb();
|
|
184
|
+
// this.dispose();
|
|
185
|
+
// process.exit(0);
|
|
186
|
+
// });
|
|
187
|
+
}
|
|
188
|
+
//######################### Events #########################
|
|
189
|
+
onUnitSelect(unit, index) {
|
|
190
|
+
this.state.selectedUnit = unit === this.state.selectedUnit ? undefined : unit;
|
|
191
|
+
this.renderUnitList();
|
|
192
|
+
this.renderLogs();
|
|
193
|
+
this.container.screen.render();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.BAI_ListScreen = BAI_ListScreen;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { Logger } from '@nu-art/ts-common';
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
2
|
+
import { RunnerParamKey } from '../../phase-runner/RunnerParams';
|
|
3
|
+
type Config<C> = {
|
|
4
4
|
key: string;
|
|
5
5
|
label: string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
filter?: () => boolean | Promise<boolean>;
|
|
7
|
+
} & C;
|
|
8
|
+
type RuntimeConfig<C> = {
|
|
9
|
+
dependencyName: string;
|
|
10
|
+
unitDependencyNames: string[];
|
|
11
|
+
} & C;
|
|
12
|
+
export declare class BaseUnit<_Config extends {} = {}, _RuntimeConfig extends {} = {}, C extends Config<_Config> = Config<_Config>, RTC extends RuntimeConfig<_RuntimeConfig> = RuntimeConfig<_RuntimeConfig>> extends Logger {
|
|
8
13
|
readonly config: Readonly<C>;
|
|
9
|
-
|
|
14
|
+
readonly runtime: RTC;
|
|
15
|
+
private unitStatus?;
|
|
16
|
+
private logger;
|
|
10
17
|
constructor(config: C);
|
|
11
|
-
protected init(): Promise<void>;
|
|
18
|
+
protected init(setInitialized?: boolean): Promise<void>;
|
|
19
|
+
protected getRunnerParam(key: RunnerParamKey): string | undefined;
|
|
12
20
|
private initLogClient;
|
|
13
|
-
|
|
21
|
+
protected setStatus(status?: string): void;
|
|
22
|
+
getStatus(): string | undefined;
|
|
23
|
+
kill(): Promise<void>;
|
|
24
|
+
getLogs(): string;
|
|
14
25
|
}
|
|
15
26
|
export {};
|
package/v2/unit/core/BaseUnit.js
CHANGED
|
@@ -2,31 +2,56 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseUnit = void 0;
|
|
4
4
|
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
|
+
const RunnerParams_1 = require("../../phase-runner/RunnerParams");
|
|
6
|
+
const PhaseRunnerDispatcher_1 = require("../../phase-runner/PhaseRunnerDispatcher");
|
|
5
7
|
class BaseUnit extends ts_common_1.Logger {
|
|
6
8
|
constructor(config) {
|
|
7
9
|
super(config.key);
|
|
8
|
-
this.setGetRunnerParamCaller = (caller) => {
|
|
9
|
-
this.getRunnerParam = caller;
|
|
10
|
-
};
|
|
11
10
|
this.config = Object.freeze(config);
|
|
11
|
+
this.runtime = {
|
|
12
|
+
dependencyName: this.config.key,
|
|
13
|
+
unitDependencyNames: [],
|
|
14
|
+
};
|
|
12
15
|
this.initLogClient();
|
|
13
16
|
}
|
|
14
|
-
async init() {
|
|
15
|
-
|
|
17
|
+
async init(setInitialized = true) {
|
|
18
|
+
this.setStatus('Initializing');
|
|
19
|
+
//Register the unit to PhaseRunnerEvent dispatcher
|
|
20
|
+
PhaseRunnerDispatcher_1.dispatcher_PhaseChange.addListener(this);
|
|
21
|
+
PhaseRunnerDispatcher_1.dispatcher_UnitStatusChange.addListener(this);
|
|
22
|
+
if (setInitialized)
|
|
23
|
+
this.setStatus('Initialized');
|
|
16
24
|
}
|
|
17
25
|
//######################### Internal Logic #########################
|
|
26
|
+
getRunnerParam(key) {
|
|
27
|
+
return RunnerParams_1.MemKey_RunnerParams.get({})[key];
|
|
28
|
+
}
|
|
18
29
|
initLogClient() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
this.logger = new ts_common_1.LogClient_MemBuffer(this.tag);
|
|
31
|
+
this.logger.setForTerminal();
|
|
32
|
+
this.logger.setComposer((tag, level) => {
|
|
22
33
|
ts_common_1._logger_finalDate.setTime(Date.now() - ts_common_1._logger_timezoneOffset);
|
|
23
34
|
const date = ts_common_1._logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23).split('_')[1];
|
|
24
35
|
return `${date} ${(0, ts_common_1._logger_getPrefix)(level)}: `;
|
|
25
36
|
});
|
|
26
|
-
|
|
37
|
+
this.logger.setFilter((level, tag) => {
|
|
27
38
|
return tag === this.tag;
|
|
28
39
|
});
|
|
29
|
-
ts_common_1.BeLogged.addClient(
|
|
40
|
+
ts_common_1.BeLogged.addClient(this.logger);
|
|
41
|
+
}
|
|
42
|
+
setStatus(status) {
|
|
43
|
+
this.unitStatus = status;
|
|
44
|
+
PhaseRunnerDispatcher_1.dispatcher_UnitStatusChange.dispatch(this);
|
|
45
|
+
}
|
|
46
|
+
//######################### Public Functions #########################
|
|
47
|
+
getStatus() {
|
|
48
|
+
return this.unitStatus;
|
|
49
|
+
}
|
|
50
|
+
async kill() {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
getLogs() {
|
|
54
|
+
return this.logger.buffers[0];
|
|
30
55
|
}
|
|
31
56
|
}
|
|
32
57
|
exports.BaseUnit = BaseUnit;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
import { Phase_Install } from '../../phase';
|
|
2
|
+
import { UnitPhaseImplementor } from '../types';
|
|
1
3
|
import { BaseUnit } from './BaseUnit';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
+
import { Commando, CommandoInteractive } from '@nu-art/commando/core/cli';
|
|
5
|
+
import { Cli_Basic } from '@nu-art/commando/cli/basic';
|
|
6
|
+
type _Config<C> = {
|
|
7
|
+
pathToPackage: string;
|
|
8
|
+
} & C;
|
|
9
|
+
type _RuntimeConfig<RTC> = {
|
|
10
|
+
pathTo: {
|
|
11
|
+
pkg: string;
|
|
12
|
+
};
|
|
13
|
+
} & RTC;
|
|
14
|
+
export declare class Unit_Python<Config extends {} = {}, RuntimeConfig extends {} = {}, C extends _Config<Config> = _Config<Config>, RTC extends _RuntimeConfig<RuntimeConfig> = _RuntimeConfig<RuntimeConfig>> extends BaseUnit<C, RTC> implements UnitPhaseImplementor<[Phase_Install]> {
|
|
15
|
+
protected commando: CommandoInteractive & Commando & Cli_Basic;
|
|
16
|
+
constructor(config: Unit_Python<C, RTC>['config']);
|
|
17
|
+
protected init(): Promise<void>;
|
|
18
|
+
private initCommando;
|
|
4
19
|
install(): Promise<void>;
|
|
5
20
|
}
|
|
21
|
+
export {};
|
|
@@ -3,9 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Unit_Python = void 0;
|
|
4
4
|
const BaseUnit_1 = require("./BaseUnit");
|
|
5
5
|
const cli_1 = require("@nu-art/commando/core/cli");
|
|
6
|
+
const tools_1 = require("@nu-art/commando/core/tools");
|
|
7
|
+
const basic_1 = require("@nu-art/commando/cli/basic");
|
|
6
8
|
class Unit_Python extends BaseUnit_1.BaseUnit {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.commando = cli_1.CommandoInteractive.create(basic_1.Cli_Basic);
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
await super.init();
|
|
15
|
+
this.runtime.pathTo = {
|
|
16
|
+
pkg: (0, tools_1.convertToFullPath)(this.config.pathToPackage),
|
|
17
|
+
};
|
|
18
|
+
this.logWarning(`Python Path ${this.runtime.pathTo.pkg}`);
|
|
19
|
+
await this.initCommando();
|
|
20
|
+
}
|
|
21
|
+
//######################### Internal Logic #########################
|
|
22
|
+
async initCommando() {
|
|
23
|
+
this.commando
|
|
24
|
+
.setUID(this.config.key)
|
|
25
|
+
.cd(this.runtime.pathTo.pkg)
|
|
26
|
+
.debug();
|
|
27
|
+
//Install & Enter VENV
|
|
28
|
+
await this.commando
|
|
29
|
+
.append('python3 -m venv venv')
|
|
30
|
+
.append('source venv/bin/activate')
|
|
31
|
+
.execute();
|
|
32
|
+
//Set Python Path
|
|
33
|
+
await this.commando.append('export PYTHONPATH=.').execute();
|
|
34
|
+
}
|
|
35
|
+
//######################### Phase Implementation #########################
|
|
7
36
|
async install() {
|
|
8
|
-
await
|
|
37
|
+
await this.commando.append('pip install -r requirements.txt').execute();
|
|
9
38
|
}
|
|
10
39
|
}
|
|
11
40
|
exports.Unit_Python = Unit_Python;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { BaseUnit } from './BaseUnit';
|
|
2
|
-
import { Phase_CopyPackageJSON, UnitPhaseImplementor } from './types';
|
|
3
2
|
import { PackageJson } from '../../../core/types';
|
|
4
|
-
|
|
3
|
+
import { AbsolutePath, RelativePath } from '@nu-art/ts-common';
|
|
4
|
+
import { Phase_CopyPackageJSON } from '../../phase';
|
|
5
|
+
import { UnitPhaseImplementor } from '../types';
|
|
6
|
+
declare const PackageJsonTargetKeys: readonly ["template", "root", "dist"];
|
|
5
7
|
type PackageJsonTargetKey = typeof PackageJsonTargetKeys[number];
|
|
6
|
-
type _Config<
|
|
7
|
-
pathToPackage:
|
|
8
|
-
} &
|
|
9
|
-
|
|
8
|
+
type _Config<C> = {
|
|
9
|
+
pathToPackage: RelativePath;
|
|
10
|
+
} & C;
|
|
11
|
+
type RTC_Unit_Typescript<RTC> = {
|
|
12
|
+
pathTo: {
|
|
13
|
+
pkg: AbsolutePath;
|
|
14
|
+
};
|
|
15
|
+
} & RTC;
|
|
16
|
+
export declare class Unit_Typescript<Config extends {} = {}, RuntimeConfig extends {} = {}, C extends _Config<Config> = _Config<Config>, RTC extends RTC_Unit_Typescript<RuntimeConfig> = RTC_Unit_Typescript<RuntimeConfig>> extends BaseUnit<C, RTC> implements UnitPhaseImplementor<[Phase_CopyPackageJSON]> {
|
|
10
17
|
readonly packageJson: {
|
|
11
18
|
[k in PackageJsonTargetKey]: PackageJson;
|
|
12
19
|
};
|
|
20
|
+
protected init(setInitialized?: boolean): Promise<void>;
|
|
21
|
+
private loadTemplatePackageJSON;
|
|
13
22
|
/**
|
|
14
23
|
* Create a packageJson object for each target key
|
|
15
24
|
* @private
|
|
@@ -34,13 +43,6 @@ export declare class Unit_Typescript<Config extends {} = {}, C extends _Config<C
|
|
|
34
43
|
* @private
|
|
35
44
|
*/
|
|
36
45
|
private convertPJForDist;
|
|
37
|
-
/**
|
|
38
|
-
* Converts a template __package.json file into a usable package.json for the unit
|
|
39
|
-
* as it will be in a .dependencies of a deployable unit
|
|
40
|
-
* @param template
|
|
41
|
-
* @private
|
|
42
|
-
*/
|
|
43
|
-
private convertPJForDependency;
|
|
44
46
|
copyPackageJson(): Promise<void>;
|
|
45
47
|
}
|
|
46
48
|
export {};
|
|
@@ -31,27 +31,44 @@ const ts_common_1 = require("@nu-art/ts-common");
|
|
|
31
31
|
const map_project_packages_1 = require("../../../logic/map-project-packages");
|
|
32
32
|
const fs = __importStar(require("fs"));
|
|
33
33
|
const fs_1 = require("fs");
|
|
34
|
+
const RunnerParams_1 = require("../../phase-runner/RunnerParams");
|
|
35
|
+
const PackageJsonTargetKey_Template = 'template';
|
|
34
36
|
const PackageJsonTargetKey_Root = 'root';
|
|
35
37
|
const PackageJsonTargetKey_Dist = 'dist';
|
|
36
|
-
const
|
|
37
|
-
const PackageJsonTargetKeys = [PackageJsonTargetKey_Root, PackageJsonTargetKey_Dist, PackageJsonTargetKey_Dependency];
|
|
38
|
+
const PackageJsonTargetKeys = [PackageJsonTargetKey_Template, PackageJsonTargetKey_Root, PackageJsonTargetKey_Dist];
|
|
38
39
|
class Unit_Typescript extends BaseUnit_1.BaseUnit {
|
|
39
40
|
constructor() {
|
|
40
41
|
super(...arguments);
|
|
41
42
|
this.packageJson = {};
|
|
42
43
|
}
|
|
44
|
+
async init(setInitialized = true) {
|
|
45
|
+
var _a;
|
|
46
|
+
await super.init(false);
|
|
47
|
+
this.runtime.pathTo = {
|
|
48
|
+
pkg: (0, tools_1.convertToFullPath)(this.config.pathToPackage),
|
|
49
|
+
};
|
|
50
|
+
await this.loadTemplatePackageJSON();
|
|
51
|
+
this.runtime.dependencyName = this.packageJson.template.name;
|
|
52
|
+
this.runtime.unitDependencyNames = (0, ts_common_1._keys)((_a = this.packageJson.template.dependencies) !== null && _a !== void 0 ? _a : {});
|
|
53
|
+
if (setInitialized)
|
|
54
|
+
this.setStatus('Initialized');
|
|
55
|
+
}
|
|
43
56
|
//######################### Internal Logic #########################
|
|
57
|
+
async loadTemplatePackageJSON() {
|
|
58
|
+
const unitRootPath = this.runtime.pathTo.pkg;
|
|
59
|
+
const templatePath = `${unitRootPath}/${consts_1.CONST_PackageJSONTemplate}`;
|
|
60
|
+
if (!fs.existsSync(templatePath))
|
|
61
|
+
throw new ts_common_1.BadImplementationException(`Missing __package.json file in root for unit ${this.config.label}`);
|
|
62
|
+
this.packageJson.template = JSON.parse(await fs_1.promises.readFile(templatePath, 'utf-8'));
|
|
63
|
+
}
|
|
44
64
|
/**
|
|
45
65
|
* Create a packageJson object for each target key
|
|
46
66
|
* @private
|
|
47
67
|
*/
|
|
48
68
|
async populatePackageJson() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
throw new ts_common_1.BadImplementationException(`Missing __package.json file in root for unit ${this.config.label}`);
|
|
53
|
-
const template = JSON.parse(await fs_1.promises.readFile(templatePath, 'utf-8'));
|
|
54
|
-
PackageJsonTargetKeys.forEach(key => this.packageJson[key] = this.convertTemplatePackageJSON(key, template));
|
|
69
|
+
if (!this.packageJson.template)
|
|
70
|
+
await this.loadTemplatePackageJSON();
|
|
71
|
+
PackageJsonTargetKeys.forEach(key => this.packageJson[key] = this.convertTemplatePackageJSON(key, this.packageJson.template));
|
|
55
72
|
}
|
|
56
73
|
/**
|
|
57
74
|
* Execute template to packageJson object conversion based on target key
|
|
@@ -61,12 +78,12 @@ class Unit_Typescript extends BaseUnit_1.BaseUnit {
|
|
|
61
78
|
*/
|
|
62
79
|
convertTemplatePackageJSON(targetKey, template) {
|
|
63
80
|
switch (targetKey) {
|
|
81
|
+
case PackageJsonTargetKey_Template:
|
|
82
|
+
return template;
|
|
64
83
|
case PackageJsonTargetKey_Root:
|
|
65
84
|
return this.convertPJForRoot(template);
|
|
66
85
|
case PackageJsonTargetKey_Dist:
|
|
67
86
|
return this.convertPJForDist(template);
|
|
68
|
-
case PackageJsonTargetKey_Dependency:
|
|
69
|
-
return this.convertPJForDependency(template);
|
|
70
87
|
default:
|
|
71
88
|
throw new ts_common_1.ImplementationMissingException(`No implementation for targetKey ${targetKey}`);
|
|
72
89
|
}
|
|
@@ -77,11 +94,15 @@ class Unit_Typescript extends BaseUnit_1.BaseUnit {
|
|
|
77
94
|
* @private
|
|
78
95
|
*/
|
|
79
96
|
convertPJForRoot(template) {
|
|
80
|
-
var _a, _b;
|
|
81
97
|
//Get the package params for replacing in the template package json
|
|
82
|
-
const
|
|
98
|
+
const projectConfig = RunnerParams_1.MemKey_ProjectConfig.get();
|
|
83
99
|
//Convert template to actual package.json
|
|
84
|
-
|
|
100
|
+
const converted = (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(template, (value, key) => projectConfig.params[key] ? 'workspace:*' : projectConfig.params[value]);
|
|
101
|
+
//Set dynamic params for this pkg
|
|
102
|
+
projectConfig.params[converted.name] = converted.version;
|
|
103
|
+
projectConfig.params[`${converted.name}_path`] = `file:.dependencies/${this.config.key}`; //Not sure about this one
|
|
104
|
+
RunnerParams_1.MemKey_ProjectConfig.set(projectConfig);
|
|
105
|
+
return converted;
|
|
85
106
|
}
|
|
86
107
|
/**
|
|
87
108
|
* Converts a template __package.json file into a usable package.json for the unit dist
|
|
@@ -89,39 +110,22 @@ class Unit_Typescript extends BaseUnit_1.BaseUnit {
|
|
|
89
110
|
* @private
|
|
90
111
|
*/
|
|
91
112
|
convertPJForDist(template) {
|
|
92
|
-
var _a, _b, _c;
|
|
93
|
-
//Get the package params for replacing in the template package json
|
|
94
|
-
const params = (_b = (_a = consts_1.MemKey_Packages.get()) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {};
|
|
95
|
-
const converted = (_c = this.packageJson[PackageJsonTargetKey_Root]) !== null && _c !== void 0 ? _c : this.convertPJForRoot(template);
|
|
96
|
-
params[converted.name] = converted.version;
|
|
97
|
-
params[`${converted.name}_path`] = `file:.dependencies/${this.config.key}`; //Not sure about this one
|
|
98
|
-
//Convert template to actual package.json
|
|
99
|
-
return (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(template, (value, key) => { var _a; return (_a = params[key]) !== null && _a !== void 0 ? _a : params[value]; });
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Converts a template __package.json file into a usable package.json for the unit
|
|
103
|
-
* as it will be in a .dependencies of a deployable unit
|
|
104
|
-
* @param template
|
|
105
|
-
* @private
|
|
106
|
-
*/
|
|
107
|
-
convertPJForDependency(template) {
|
|
108
|
-
var _a, _b, _c;
|
|
109
113
|
//Get the package params for replacing in the template package json
|
|
110
|
-
const params =
|
|
111
|
-
const converted = (_c = this.packageJson[PackageJsonTargetKey_Root]) !== null && _c !== void 0 ? _c : this.convertPJForRoot(template);
|
|
112
|
-
params[converted.name] = converted.version;
|
|
113
|
-
params[`${converted.name}_path`] = `file:.dependencies/${this.config.key}`; //Not sure about this one
|
|
114
|
+
const params = RunnerParams_1.MemKey_ProjectConfig.get().params;
|
|
114
115
|
//Convert template to actual package.json
|
|
115
116
|
return (0, map_project_packages_1.convertPackageJSONTemplateToPackJSON_Value)(template, (value, key) => { var _a; return (_a = params[key]) !== null && _a !== void 0 ? _a : params[value]; });
|
|
116
117
|
}
|
|
117
118
|
//######################### Phase Implementations #########################
|
|
118
119
|
async copyPackageJson() {
|
|
120
|
+
this.setStatus('Resolving PackageJSON');
|
|
119
121
|
//Populate packageJson objects
|
|
120
122
|
await this.populatePackageJson();
|
|
121
123
|
//Get path
|
|
122
|
-
const unitRootPath =
|
|
124
|
+
const unitRootPath = this.runtime.pathTo.pkg;
|
|
125
|
+
const targetPath = `${unitRootPath}/${consts_1.CONST_PackageJSON}`;
|
|
123
126
|
//Create the package.json file in target location
|
|
124
|
-
await fs_1.promises.writeFile(
|
|
127
|
+
await fs_1.promises.writeFile(targetPath, JSON.stringify(this.packageJson.root, null, 2), { encoding: 'utf-8' });
|
|
128
|
+
this.setStatus('PackageJSON resolved');
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
exports.Unit_Typescript = Unit_Typescript;
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import { Unit_Typescript } from './Unit_Typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { UnitPhaseImplementor } from '../types';
|
|
3
|
+
import { Phase_CheckCyclicImports, Phase_Compile, Phase_Lint, Phase_PreCompile, Phase_PrintDependencyTree, Phase_Purge } from '../../phase';
|
|
3
4
|
type _Config<Config> = {
|
|
4
5
|
customTSConfig?: boolean;
|
|
6
|
+
output: string;
|
|
5
7
|
} & Config;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
type _RuntimeConfig<RTC> = {
|
|
9
|
+
pathTo: {
|
|
10
|
+
pkg: string;
|
|
11
|
+
output: string;
|
|
12
|
+
};
|
|
13
|
+
} & RTC;
|
|
14
|
+
export declare class Unit_TypescriptLib<Config extends {} = {}, RuntimeConfig extends {} = {}, C extends _Config<Config> = _Config<Config>, RTC extends _RuntimeConfig<RuntimeConfig> = _RuntimeConfig<RuntimeConfig>> extends Unit_Typescript<C, RTC> implements UnitPhaseImplementor<[
|
|
15
|
+
Phase_PreCompile,
|
|
16
|
+
Phase_Compile,
|
|
17
|
+
Phase_PrintDependencyTree,
|
|
18
|
+
Phase_CheckCyclicImports,
|
|
19
|
+
Phase_Purge,
|
|
20
|
+
Phase_Lint
|
|
21
|
+
]> {
|
|
22
|
+
protected init(setInitialized?: boolean): Promise<void>;
|
|
23
|
+
protected resolveTSConfig(): Promise<void>;
|
|
24
|
+
protected clearOutputDir(): Promise<void>;
|
|
25
|
+
protected compileImpl(): Promise<void>;
|
|
26
|
+
protected copyAssetsToOutput(): Promise<void>;
|
|
27
|
+
protected copyPackageJSONToOutput(): Promise<void>;
|
|
8
28
|
preCompile(): Promise<void>;
|
|
9
29
|
compile(): Promise<void>;
|
|
30
|
+
purge(): Promise<void>;
|
|
31
|
+
printDependencyTree(): Promise<void>;
|
|
32
|
+
checkCyclicImports(): Promise<void>;
|
|
33
|
+
lint(): Promise<void>;
|
|
10
34
|
}
|
|
11
35
|
export {};
|