@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,11 @@
1
+ import { PackageJson } from '../configs';
2
+ import { Package, Package_Sourceless } from './package';
3
+ type WithPackageJson = {
4
+ packageJsonTemplate: PackageJson;
5
+ packageJsonWorkspace?: PackageJson;
6
+ packageJsonOutput?: PackageJson;
7
+ packageJsonRuntime?: PackageJson;
8
+ };
9
+ export type RuntimePackage = Required<Package> & WithPackageJson;
10
+ export type RuntimePackage_WithOutput = Required<Exclude<Package, Package_Sourceless>> & WithPackageJson;
11
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { StringMap } from '@nu-art/ts-common';
2
+ import { Package, RuntimePackage } from './package';
3
+ export type ProjectConfig = {
4
+ params: StringMap;
5
+ packages: Package[];
6
+ };
7
+ export type RuntimeProjectConfig = {
8
+ packages: Package[];
9
+ params: StringMap;
10
+ packagesDependency?: RuntimePackage[][];
11
+ packageMap?: {
12
+ [packageName: string]: RuntimePackage;
13
+ };
14
+ };
15
+ export type Constructor<T> = new (...args: any) => T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ import { ProjectConfig, RuntimePackage, RuntimePackage_WithOutput } from '../core/types';
2
+ import { Logger } from '@nu-art/ts-common';
3
+ export declare const PackageBuildPhaseType_Package: "package";
4
+ export declare const PackageBuildPhaseType_PackageWithOutput: "package-with-output";
5
+ export declare const PackageBuildPhaseType_Project: "project";
6
+ type BuildPhase_Base = {
7
+ name: string;
8
+ terminatingPhase?: boolean;
9
+ mandatoryPhases?: BuildPhase[];
10
+ };
11
+ type BuildPhase_Package = BuildPhase_Base & {
12
+ type: typeof PackageBuildPhaseType_Package;
13
+ action: (pkg: RuntimePackage) => Promise<any>;
14
+ filter?: (pkg: RuntimePackage) => Promise<boolean>;
15
+ };
16
+ type BuildPhase_PackageWithOutput = BuildPhase_Base & {
17
+ type: typeof PackageBuildPhaseType_PackageWithOutput;
18
+ action: (pkg: RuntimePackage_WithOutput) => Promise<any>;
19
+ filter?: (pkg: RuntimePackage_WithOutput) => Promise<boolean>;
20
+ };
21
+ type BuildPhase_Project = BuildPhase_Base & {
22
+ type: 'project';
23
+ action: () => Promise<any>;
24
+ filter?: () => Promise<boolean>;
25
+ };
26
+ export type BuildPhase = BuildPhase_Package | BuildPhase_PackageWithOutput | BuildPhase_Project;
27
+ export declare class ProjectManager extends Logger {
28
+ private phases;
29
+ private config;
30
+ constructor(config: ProjectConfig);
31
+ registerPhase(phase: BuildPhase): void;
32
+ execute(phasesToRun?: BuildPhase[]): Promise<void>;
33
+ private resolveAllMandatoryPhases;
34
+ runPhaseByKey(phaseKey: string): Promise<void>;
35
+ private getPackagesForPhaseType;
36
+ private runPhase;
37
+ }
38
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectManager = exports.PackageBuildPhaseType_Project = exports.PackageBuildPhaseType_PackageWithOutput = exports.PackageBuildPhaseType_Package = void 0;
4
+ const types_1 = require("../core/types");
5
+ const ts_common_1 = require("@nu-art/ts-common");
6
+ exports.PackageBuildPhaseType_Package = 'package';
7
+ exports.PackageBuildPhaseType_PackageWithOutput = 'package-with-output';
8
+ exports.PackageBuildPhaseType_Project = 'project';
9
+ const PackageBuildPhaseTypes = [exports.PackageBuildPhaseType_Package, exports.PackageBuildPhaseType_PackageWithOutput, exports.PackageBuildPhaseType_Project];
10
+ class ProjectManager extends ts_common_1.Logger {
11
+ constructor(config) {
12
+ super();
13
+ this.phases = [];
14
+ this.getPackagesForPhaseType = (phaseType) => {
15
+ var _a;
16
+ const allRuntimePackages = [];
17
+ (_a = this.config.packagesDependency) === null || _a === void 0 ? void 0 : _a.forEach(dependency => dependency.forEach(_package => allRuntimePackages.push(_package)));
18
+ switch (phaseType) {
19
+ case exports.PackageBuildPhaseType_Project:
20
+ return [];
21
+ case exports.PackageBuildPhaseType_Package:
22
+ return allRuntimePackages;
23
+ case exports.PackageBuildPhaseType_PackageWithOutput:
24
+ return allRuntimePackages.filter(_package => {
25
+ const packageType = _package.type;
26
+ return types_1.PackageTypesWithOutput.includes(packageType);
27
+ });
28
+ default:
29
+ return allRuntimePackages;
30
+ }
31
+ };
32
+ this.config = config;
33
+ ts_common_1.BeLogged.addClient(ts_common_1.LogClient_Terminal);
34
+ this.setMinLevel(ts_common_1.LogLevel.Verbose);
35
+ }
36
+ registerPhase(phase) {
37
+ this.phases.push(phase);
38
+ }
39
+ async execute(phasesToRun) {
40
+ for (const phase of (phasesToRun !== null && phasesToRun !== void 0 ? phasesToRun : this.phases)) {
41
+ const didRun = await this.runPhase(phase);
42
+ //terminate execution if phase is terminating
43
+ if (didRun && phase.terminatingPhase)
44
+ break;
45
+ }
46
+ }
47
+ resolveAllMandatoryPhases(phase) {
48
+ let result = [phase];
49
+ if (phase.mandatoryPhases) {
50
+ for (const childPhase of phase.mandatoryPhases) {
51
+ result = result.concat(this.resolveAllMandatoryPhases(childPhase));
52
+ }
53
+ }
54
+ return (0, ts_common_1.filterDuplicates)(result, result => result.name);
55
+ }
56
+ async runPhaseByKey(phaseKey) {
57
+ const phase = this.phases.find(phase => phase.name === phaseKey);
58
+ if (!phase)
59
+ return;
60
+ const finalPhasesToRun = this.resolveAllMandatoryPhases(phase).reverse();
61
+ return this.execute(finalPhasesToRun);
62
+ }
63
+ async runPhase(phase) {
64
+ var _a;
65
+ if (phase.type === exports.PackageBuildPhaseType_Project) {
66
+ if (!phase.filter || await phase.filter()) {
67
+ this.logInfo(`Running project phase: ${phase.name}`);
68
+ await phase.action();
69
+ return true;
70
+ }
71
+ this.logVerbose(`Skipping project phase: ${phase.name}`);
72
+ return false;
73
+ }
74
+ const relevantPackages = this.getPackagesForPhaseType(phase.type);
75
+ if (relevantPackages.length === 0)
76
+ return false;
77
+ let didPrint = false;
78
+ let didRun = false;
79
+ for (const packages of (_a = this.config.packagesDependency) !== null && _a !== void 0 ? _a : []) {
80
+ const packagesToCheck = packages.filter(pkg => relevantPackages.includes(pkg));
81
+ const filteredPackages = (0, ts_common_1.filterInstances)(await Promise.all(packagesToCheck.map(async (pkg) => {
82
+ if (!phase.filter || await phase.filter(pkg))
83
+ return pkg;
84
+ })));
85
+ const finalPackages = filteredPackages.filter(pkg => pkg);
86
+ if (finalPackages.length === 0)
87
+ continue;
88
+ if (!didPrint) {
89
+ this.logInfo(`Running phase: ${phase.name}`);
90
+ didPrint = true;
91
+ }
92
+ if (finalPackages.length === 1)
93
+ this.logDebug(` Package: ${packagesToCheck.map(pkg => pkg.name)[0]}`);
94
+ else
95
+ this.logDebug(` Packages: ${JSON.stringify(packagesToCheck.map(pkg => pkg.name))}`);
96
+ const errors = await Promise.all(finalPackages.map(async (pkg) => {
97
+ try {
98
+ await phase.action(pkg);
99
+ didRun = true;
100
+ }
101
+ catch (e) {
102
+ return e;
103
+ }
104
+ }));
105
+ if ((0, ts_common_1.filterInstances)(errors).length > 0) {
106
+ errors.forEach((error, index) => {
107
+ var _a, _b, _c, _d;
108
+ if (!error)
109
+ return;
110
+ this.logError(`\nError in package: ${(_a = packages[index].packageJsonTemplate) === null || _a === void 0 ? void 0 : _a.name}`);
111
+ if ((_b = error.stdout) === null || _b === void 0 ? void 0 : _b.length)
112
+ this.logVerbose(error.stdout);
113
+ if ((_c = error.stderr) === null || _c === void 0 ? void 0 : _c.length)
114
+ this.logVerboseBold(error.stderr);
115
+ else if ((_d = error.message) === null || _d === void 0 ? void 0 : _d.length)
116
+ this.logError(error.message);
117
+ });
118
+ throw new Error(`${(0, ts_common_1.filterInstances)(errors).length} Errors in phase "${phase.name}"`);
119
+ }
120
+ }
121
+ return didRun;
122
+ // throw new Error(`Unknown phase type '${JSON.stringify(phase)}'`);
123
+ }
124
+ }
125
+ exports.ProjectManager = ProjectManager;
@@ -0,0 +1,4 @@
1
+ import { Package, PackageJson, ProjectConfig, RuntimePackage, RuntimeProjectConfig } from '../core/types';
2
+ export declare function convertPackageJSONTemplateToPackJSON_Value(template: PackageJson, value: (value: string, key?: string) => string): PackageJson;
3
+ export declare function convertToRuntimePackage(basePackage: Package, project: ProjectConfig): RuntimePackage;
4
+ export declare function mapProjectPackages(projectConfig: ProjectConfig): RuntimeProjectConfig;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapProjectPackages = exports.convertToRuntimePackage = exports.convertPackageJSONTemplateToPackJSON_Value = void 0;
4
+ const consts_1 = require("../core/consts");
5
+ const fs_1 = require("fs");
6
+ const types_1 = require("../core/types");
7
+ const ts_common_1 = require("@nu-art/ts-common");
8
+ const tools_1 = require("@nu-art/commando/core/tools");
9
+ function getRuntimePackageBaseDetails_Sourceless(basePackage) {
10
+ return {
11
+ name: basePackage.name,
12
+ path: (0, tools_1.convertToFullPath)(basePackage.path),
13
+ type: basePackage.type,
14
+ };
15
+ }
16
+ function getRuntimePackageBaseDetails_Lib(basePackage) {
17
+ var _a, _b;
18
+ const packageRoot = (0, tools_1.convertToFullPath)(basePackage.path);
19
+ return {
20
+ name: basePackage.name,
21
+ path: packageRoot,
22
+ type: basePackage.type,
23
+ output: (0, tools_1.convertToFullPath)(basePackage.output, packageRoot),
24
+ customTsConfig: (_a = basePackage.customTsConfig) !== null && _a !== void 0 ? _a : false,
25
+ sources: (_b = basePackage.sources) !== null && _b !== void 0 ? _b : []
26
+ };
27
+ }
28
+ function getRuntimePackageBaseDetails_Firebase(basePackage) {
29
+ var _a, _b, _c;
30
+ const packageRoot = (0, tools_1.convertToFullPath)(basePackage.path);
31
+ return {
32
+ name: basePackage.name,
33
+ path: packageRoot,
34
+ type: basePackage.type,
35
+ output: (0, tools_1.convertToFullPath)(basePackage.output, packageRoot),
36
+ customTsConfig: (_a = basePackage.customTsConfig) !== null && _a !== void 0 ? _a : false,
37
+ sources: (_b = basePackage.sources) !== null && _b !== void 0 ? _b : [],
38
+ envConfig: (_c = basePackage.envConfig) !== null && _c !== void 0 ? _c : {},
39
+ };
40
+ }
41
+ function getRuntimePackageBaseDetails(basePackage) {
42
+ switch (basePackage.type) {
43
+ case types_1.PackageType_Sourceless:
44
+ return getRuntimePackageBaseDetails_Sourceless(basePackage);
45
+ case types_1.PackageType_ProjectLib:
46
+ case types_1.PackageType_InfraLib:
47
+ return getRuntimePackageBaseDetails_Lib(basePackage);
48
+ case types_1.PackageType_FirebaseFunctionsApp:
49
+ case types_1.PackageType_FirebaseHostingApp:
50
+ return getRuntimePackageBaseDetails_Firebase(basePackage);
51
+ }
52
+ }
53
+ function convertPackageJSONTemplateToPackJSON_Value(template, value) {
54
+ let workspacePackageJsonAsString = (0, ts_common_1.__stringify)(template, true);
55
+ let match = null;
56
+ do {
57
+ match = workspacePackageJsonAsString.match(/"(.*?)": ?"\$([A-Z_]+?)"/);
58
+ if (match === null || match === void 0 ? void 0 : match[0])
59
+ workspacePackageJsonAsString = workspacePackageJsonAsString.replace(new RegExp(`\\$${match[2]}`), value(match[2], match[1]));
60
+ } while (match);
61
+ const packageJson = JSON.parse(workspacePackageJsonAsString);
62
+ return packageJson;
63
+ }
64
+ exports.convertPackageJSONTemplateToPackJSON_Value = convertPackageJSONTemplateToPackJSON_Value;
65
+ function convertToRuntimePackage(basePackage, project) {
66
+ const runtimePackage = getRuntimePackageBaseDetails(basePackage);
67
+ //Get template package json
68
+ if (!(0, fs_1.existsSync)(runtimePackage.path))
69
+ throw new Error(`package: ${runtimePackage.path} is missing the ${consts_1.CONST_PackageJSONTemplate} files`);
70
+ const pjTemplate = JSON.parse((0, fs_1.readFileSync)(`${runtimePackage.path}/${consts_1.CONST_PackageJSONTemplate}`, 'utf-8'));
71
+ return Object.assign(Object.assign({}, runtimePackage), { packageJsonTemplate: pjTemplate });
72
+ }
73
+ exports.convertToRuntimePackage = convertToRuntimePackage;
74
+ function mapProjectPackages(projectConfig) {
75
+ const packages = projectConfig.packages.map(basePackage => convertToRuntimePackage(basePackage, projectConfig));
76
+ const packagesDependency = groupPackagesByDependencyLevel(packages);
77
+ return Object.assign(Object.assign({}, projectConfig), { packages,
78
+ packagesDependency, packageMap: (0, ts_common_1.arrayToMap)(packages, p => p.packageJsonTemplate.name) });
79
+ }
80
+ exports.mapProjectPackages = mapProjectPackages;
81
+ function groupPackagesByDependencyLevel(packages) {
82
+ const packageNames = packages.map(p => p.packageJsonTemplate.name);
83
+ const packagesConfigWithDependencies = packages
84
+ .map(_package => {
85
+ const packageDependencies = packageNames.filter(name => { var _a; return (_a = _package.packageJsonTemplate.dependencies) === null || _a === void 0 ? void 0 : _a[name]; });
86
+ return Object.assign({ packageDependencies }, _package);
87
+ });
88
+ // Map to keep track of each package's level
89
+ const levels = new Map();
90
+ // Function to recursively find the level of a package
91
+ function findLevel(pkgName, visited = new Set()) {
92
+ if (visited.has(pkgName)) {
93
+ throw new Error(`Circular dependency detected for package ${pkgName}`);
94
+ }
95
+ visited.add(pkgName);
96
+ const pkg = packagesConfigWithDependencies.find(p => p.packageJsonTemplate.name === pkgName);
97
+ if (!pkg)
98
+ throw new Error(`Package ${pkgName} not found`);
99
+ // A package with no dependencies is at level 0
100
+ if (pkg.packageDependencies.length === 0)
101
+ return 0;
102
+ // Find the maximum level among dependencies
103
+ const maxDependencyLevel = Math.max(...pkg.packageDependencies.map(dep => findLevel(dep, new Set(visited))));
104
+ return 1 + maxDependencyLevel;
105
+ }
106
+ // Determine the level of each package
107
+ packagesConfigWithDependencies.forEach(pkg => {
108
+ const level = findLevel(pkg.packageJsonTemplate.name);
109
+ levels.set(pkg.packageJsonTemplate.name, level);
110
+ });
111
+ // Group packages by their level
112
+ const groupedPackages = new Map();
113
+ levels.forEach((level, pkgName) => {
114
+ const pkg = packages.find(p => p.packageJsonTemplate.name === pkgName);
115
+ if (pkg) {
116
+ if (!groupedPackages.has(level)) {
117
+ groupedPackages.set(level, []);
118
+ }
119
+ groupedPackages.get(level).push(pkg);
120
+ }
121
+ });
122
+ // Sort and convert the grouped packages into a sorted array of arrays
123
+ const sortedLevels = Array.from(groupedPackages.keys()).sort((a, b) => a - b);
124
+ return sortedLevels.map(level => groupedPackages.get(level));
125
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@nu-art/build-and-install",
3
+ "version": "0.203.117",
4
+ "description": "",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "infra",
8
+ "nu-art",
9
+ "commando"
10
+ ],
11
+ "homepage": "https://github.com/nu-art-js/thunderstorm",
12
+ "bugs": {
13
+ "url": "https://github.com/nu-art-js/thunderstorm/issues"
14
+ },
15
+ "publishConfig": {
16
+ "directory": "dist",
17
+ "linkDirectory": true
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+ssh://git@github.com:nu-art-js/thunderstorm.git"
22
+ },
23
+ "license": "Apache-2.0",
24
+ "author": "TacB0sS",
25
+ "main": "index.js",
26
+ "types": "index.d.ts",
27
+ "files": [
28
+ "**/*"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc"
32
+ },
33
+ "dependencies": {
34
+ "chokidar": "^3.6.0",
35
+ "@nu-art/ts-common": "0.203.117",
36
+ "@nu-art/commando": "0.203.117"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^18.0.0"
40
+ }
41
+ }
@@ -0,0 +1,24 @@
1
+ import { BuildPhase } from '../logic/ProjectManager';
2
+ export declare const projectPackages: import("../core/types").RuntimeProjectConfig;
3
+ export declare const Phase_PrintHelp: BuildPhase;
4
+ export declare const Phase_SetWithThunderstorm: BuildPhase;
5
+ export declare const Phase_SetupProject: BuildPhase;
6
+ export declare const Phase_ResolveTemplate: BuildPhase;
7
+ export declare const Phase_ResolveEnv: BuildPhase;
8
+ export declare const Phase_ResolvePackages: BuildPhase;
9
+ export declare const Phase_InstallNvm: BuildPhase;
10
+ export declare const Phase_PrintDependencyTree: BuildPhase;
11
+ export declare const Phase_CheckCyclicImports: BuildPhase;
12
+ export declare const Phase_PrintEnv: BuildPhase;
13
+ export declare const Phase_PackagePurge: BuildPhase;
14
+ export declare const Phase_InstallGlobals: BuildPhase;
15
+ export declare const Phase_InstallPnpm: BuildPhase;
16
+ export declare const Phase_InstallPackages: BuildPhase;
17
+ export declare const Phase_Clean: BuildPhase;
18
+ export declare const Phase_Lint: BuildPhase;
19
+ export declare const Phase_Debug: BuildPhase;
20
+ export declare const Phase_Compile: BuildPhase;
21
+ export declare const Phase_CompileWatch: BuildPhase;
22
+ export declare const Phase_Launch: BuildPhase;
23
+ export declare const Phase_DeployFrontend: BuildPhase;
24
+ export declare const Phase_DeployBackend: BuildPhase;