@git.zone/cli 8.2.2 → 8.2.3
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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/mod_commit/mod.plugins.d.ts +1 -2
- package/dist_ts/mod_commit/mod.plugins.js +2 -3
- package/dist_ts/mod_deprecate/helpers.deprecation.js +2 -2
- package/dist_ts/mod_format/formatters/assets.formatter.js +3 -2
- package/dist_ts/mod_format/formatters/license.formatter.js +5 -3
- package/dist_ts/mod_format/formatters/templates.formatter.d.ts +1 -1
- package/dist_ts/mod_format/formatters/templates.formatter.js +4 -3
- package/dist_ts/mod_format/helpers.licensecheck.d.ts +12 -0
- package/dist_ts/mod_format/helpers.licensecheck.js +17 -0
- package/dist_ts/mod_format/mod.plugins.d.ts +1 -3
- package/dist_ts/mod_format/mod.plugins.js +2 -4
- package/dist_ts/mod_release/helpers.commitinfo.d.ts +20 -0
- package/dist_ts/mod_release/helpers.commitinfo.js +81 -0
- package/dist_ts/mod_release/helpers.npmartifact.js +2 -2
- package/dist_ts/mod_release/index.js +3 -5
- package/dist_ts/mod_release/mod.plugins.d.ts +0 -2
- package/dist_ts/mod_release/mod.plugins.js +1 -3
- package/dist_ts/mod_services/classes.dockercontainer.js +3 -3
- package/dist_ts/mod_services/classes.interprocesslock.js +2 -2
- package/dist_ts/mod_services/classes.legacymongomigration.js +2 -2
- package/dist_ts/mod_services/classes.servicemanager.js +2 -2
- package/dist_ts/mod_services/index.js +5 -5
- package/dist_ts/mod_services/mod.plugins.d.ts +1 -2
- package/dist_ts/mod_services/mod.plugins.js +2 -3
- package/dist_ts/mod_template/classes.scaftemplate.d.ts +44 -0
- package/dist_ts/mod_template/classes.scaftemplate.js +115 -0
- package/dist_ts/mod_template/index.d.ts +2 -2
- package/dist_ts/mod_template/index.js +3 -2
- package/dist_ts/mod_template/mod.plugins.d.ts +6 -2
- package/dist_ts/mod_template/mod.plugins.js +7 -3
- package/dist_ts/plugins.d.ts +1 -2
- package/dist_ts/plugins.js +2 -3
- package/package.json +6 -7
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/mod_commit/mod.plugins.ts +1 -2
- package/ts/mod_deprecate/helpers.deprecation.ts +1 -1
- package/ts/mod_format/formatters/assets.formatter.ts +2 -1
- package/ts/mod_format/formatters/license.formatter.ts +11 -6
- package/ts/mod_format/formatters/templates.formatter.ts +3 -2
- package/ts/mod_format/helpers.licensecheck.ts +40 -0
- package/ts/mod_format/mod.plugins.ts +0 -4
- package/ts/mod_release/helpers.commitinfo.ts +108 -0
- package/ts/mod_release/helpers.npmartifact.ts +1 -1
- package/ts/mod_release/index.ts +2 -4
- package/ts/mod_release/mod.plugins.ts +0 -4
- package/ts/mod_services/classes.dockercontainer.ts +2 -2
- package/ts/mod_services/classes.interprocesslock.ts +1 -1
- package/ts/mod_services/classes.legacymongomigration.ts +1 -1
- package/ts/mod_services/classes.servicemanager.ts +1 -1
- package/ts/mod_services/index.ts +4 -4
- package/ts/mod_services/mod.plugins.ts +1 -2
- package/ts/mod_template/classes.scaftemplate.ts +159 -0
- package/ts/mod_template/index.ts +2 -1
- package/ts/mod_template/mod.plugins.ts +7 -2
- package/ts/plugins.ts +0 -2
|
@@ -2,6 +2,7 @@ import { BaseFormatter } from '../classes.baseformatter.js';
|
|
|
2
2
|
import type { IFormatWarning, IPlannedChange } from '../interfaces.format.js';
|
|
3
3
|
import * as plugins from '../mod.plugins.js';
|
|
4
4
|
import * as paths from '../../paths.js';
|
|
5
|
+
import { ScafTemplate } from '../../mod_template/classes.scaftemplate.js';
|
|
5
6
|
import { logger, logVerbose } from '../../gitzone.logging.js';
|
|
6
7
|
import { getCliConfigValue, readSmartconfigFile } from '../../helpers.smartconfig.js';
|
|
7
8
|
import { getSealedReleaseConfigError } from '../../helpers.sealedrelease.js';
|
|
@@ -309,7 +310,7 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
309
310
|
throw new Error(`Managed asset template does not exist: ${templateName}`);
|
|
310
311
|
}
|
|
311
312
|
|
|
312
|
-
const scafTemplate = new
|
|
313
|
+
const scafTemplate = new ScafTemplate(templateDir);
|
|
313
314
|
await scafTemplate.readTemplateFromDir();
|
|
314
315
|
await scafTemplate.supplyVariables(variables);
|
|
315
316
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { BaseFormatter } from '../classes.baseformatter.js';
|
|
2
2
|
import type { IFormatWarning, IPlannedChange } from '../interfaces.format.js';
|
|
3
3
|
import * as plugins from '../mod.plugins.js';
|
|
4
|
+
import {
|
|
5
|
+
findDependenciesWithLicenses,
|
|
6
|
+
type IPnpmLicensedPackage,
|
|
7
|
+
} from '../helpers.licensecheck.js';
|
|
4
8
|
import * as paths from '../../paths.js';
|
|
5
9
|
import { logger } from '../../gitzone.logging.js';
|
|
6
10
|
|
|
@@ -70,7 +74,7 @@ export class LicenseFormatter extends BaseFormatter {
|
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
private async checkLicenses(): Promise<{
|
|
73
|
-
failingModules:
|
|
77
|
+
failingModules: IPnpmLicensedPackage[];
|
|
74
78
|
} | undefined> {
|
|
75
79
|
const nodeModulesPath = plugins.path.join(paths.cwd, 'node_modules');
|
|
76
80
|
const nodeModulesExists = await plugins.smartfs
|
|
@@ -81,10 +85,11 @@ export class LicenseFormatter extends BaseFormatter {
|
|
|
81
85
|
return undefined;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
return {
|
|
89
|
+
failingModules: await findDependenciesWithLicenses(
|
|
90
|
+
paths.cwd,
|
|
91
|
+
INCOMPATIBLE_LICENSES,
|
|
92
|
+
),
|
|
93
|
+
};
|
|
89
94
|
}
|
|
90
95
|
}
|
|
@@ -2,6 +2,7 @@ import { BaseFormatter } from '../classes.baseformatter.js';
|
|
|
2
2
|
import type { IFormatWarning, IPlannedChange } from '../interfaces.format.js';
|
|
3
3
|
import * as plugins from '../mod.plugins.js';
|
|
4
4
|
import * as paths from '../../paths.js';
|
|
5
|
+
import { ScafTemplate } from '../../mod_template/classes.scaftemplate.js';
|
|
5
6
|
import { logger, logVerbose } from '../../gitzone.logging.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -43,12 +44,12 @@ export class TemplatesFormatter extends BaseFormatter {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
|
-
* Render a template directory
|
|
47
|
+
* Render a template directory and return a map of path → content.
|
|
47
48
|
*/
|
|
48
49
|
private async renderTemplate(templateName: string): Promise<Map<string, string>> {
|
|
49
50
|
const templateDir = plugins.path.join(paths.templatesDir, templateName);
|
|
50
51
|
|
|
51
|
-
const scafTemplate = new
|
|
52
|
+
const scafTemplate = new ScafTemplate(templateDir);
|
|
52
53
|
await scafTemplate.readTemplateFromDir();
|
|
53
54
|
|
|
54
55
|
const gitzoneData = this.project.gitzoneConfig?.data;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as plugins from './mod.plugins.js';
|
|
2
|
+
|
|
3
|
+
/** One license group entry of `pnpm licenses list --json`. */
|
|
4
|
+
export interface IPnpmLicensedPackage {
|
|
5
|
+
name: string;
|
|
6
|
+
versions: string[];
|
|
7
|
+
license: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** `pnpm licenses list --json` groups the installed packages by their license expression. */
|
|
11
|
+
export type TPnpmLicenseMap = Record<string, IPnpmLicensedPackage[]>;
|
|
12
|
+
|
|
13
|
+
/** Lists every installed dependency of the project with its license, as pnpm reports it. */
|
|
14
|
+
export const listDependencyLicenses = async (
|
|
15
|
+
projectDirArg: string,
|
|
16
|
+
): Promise<IPnpmLicensedPackage[]> => {
|
|
17
|
+
const smartshellInstance = new plugins.smartshell.Smartshell({ executor: 'bash' });
|
|
18
|
+
const result = await smartshellInstance.execSpawn('pnpm', ['licenses', 'list', '--json'], {
|
|
19
|
+
cwd: projectDirArg,
|
|
20
|
+
silent: true,
|
|
21
|
+
});
|
|
22
|
+
if (result.exitCode !== 0) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`\`pnpm licenses list --json\` exited with code ${result.exitCode} in ${projectDirArg}: ${
|
|
25
|
+
result.stdout.trim() || result.stderr.trim()
|
|
26
|
+
}`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const licenseMap = JSON.parse(result.stdout) as TPnpmLicenseMap;
|
|
30
|
+
return Object.values(licenseMap).flat();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The dependencies whose license expression is exactly one of the given licenses. */
|
|
34
|
+
export const findDependenciesWithLicenses = async (
|
|
35
|
+
projectDirArg: string,
|
|
36
|
+
licensesArg: readonly string[],
|
|
37
|
+
): Promise<IPnpmLicensedPackage[]> =>
|
|
38
|
+
(await listDependencyLicenses(projectDirArg)).filter((packageArg) =>
|
|
39
|
+
licensesArg.includes(packageArg.license),
|
|
40
|
+
);
|
|
@@ -2,18 +2,14 @@ export * from '../plugins.js';
|
|
|
2
2
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import * as smartfile from '@push.rocks/smartfile';
|
|
5
|
-
import * as smartlegal from '@push.rocks/smartlegal';
|
|
6
5
|
import * as smartobject from '@push.rocks/smartobject';
|
|
7
6
|
import * as smartconfig from '@push.rocks/smartconfig';
|
|
8
7
|
import * as smartdiff from '@push.rocks/smartdiff';
|
|
9
|
-
import * as smartscaf from '@push.rocks/smartscaf';
|
|
10
8
|
|
|
11
9
|
export {
|
|
12
10
|
path,
|
|
13
11
|
smartfile,
|
|
14
|
-
smartlegal,
|
|
15
12
|
smartobject,
|
|
16
13
|
smartconfig,
|
|
17
14
|
smartdiff,
|
|
18
|
-
smartscaf,
|
|
19
15
|
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
|
|
3
|
+
/** The source folders that carry a baked commit info module, where they exist. */
|
|
4
|
+
export const commitInfoDirs = ["ts", "ts_web"] as const;
|
|
5
|
+
export const commitInfoFileName = "00_commitinfo_data.ts";
|
|
6
|
+
|
|
7
|
+
export interface ICommitInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
description: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The escapes with a shorter spelling than `\uXXXX`, matching `JSON.stringify`. */
|
|
14
|
+
const stringLiteralEscapes: ReadonlyMap<string, string> = new Map([
|
|
15
|
+
["\\", "\\\\"],
|
|
16
|
+
["'", "\\'"],
|
|
17
|
+
["\b", "\\b"],
|
|
18
|
+
["\t", "\\t"],
|
|
19
|
+
["\n", "\\n"],
|
|
20
|
+
["\f", "\\f"],
|
|
21
|
+
["\r", "\\r"],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The characters that may not stand as themselves inside a single-quoted
|
|
26
|
+
* TypeScript string: the backslash, the quote itself, the C0 control range,
|
|
27
|
+
* the line separators U+2028 and U+2029, and unpaired surrogates, which a
|
|
28
|
+
* utf8 write would otherwise turn into U+FFFD. Paired surrogates stay, so
|
|
29
|
+
* emoji remain readable in the generated file.
|
|
30
|
+
*/
|
|
31
|
+
const stringLiteralEscapePattern =
|
|
32
|
+
/['\\\u0000-\u001f\u2028\u2029]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
33
|
+
|
|
34
|
+
/** Renders a value as a single-quoted TypeScript string literal that evaluates back to it. */
|
|
35
|
+
const toStringLiteral = (valueArg: string): string =>
|
|
36
|
+
`'${valueArg.replace(
|
|
37
|
+
stringLiteralEscapePattern,
|
|
38
|
+
(characterArg) =>
|
|
39
|
+
stringLiteralEscapes.get(characterArg) ??
|
|
40
|
+
`\\u${characterArg.charCodeAt(0).toString(16).padStart(4, "0")}`,
|
|
41
|
+
)}'`;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The baked module. Every project commits it, so its bytes are a contract:
|
|
45
|
+
* the header, the key order, single-quoted literals, two-space indentation
|
|
46
|
+
* and the trailing newline stay exactly as `@push.rocks/commitinfo` wrote them.
|
|
47
|
+
*/
|
|
48
|
+
export const renderCommitInfoModule = (infoArg: ICommitInfo): string =>
|
|
49
|
+
`/**
|
|
50
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
51
|
+
*/
|
|
52
|
+
export const commitinfo = {
|
|
53
|
+
name: ${toStringLiteral(infoArg.name)},
|
|
54
|
+
version: ${toStringLiteral(infoArg.version)},
|
|
55
|
+
description: ${toStringLiteral(infoArg.description)}
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
const isDirectory = async (pathArg: string): Promise<boolean> => {
|
|
60
|
+
try {
|
|
61
|
+
return (await plugins.fs.stat(pathArg)).isDirectory();
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Bakes the package name and description from package.json together with the
|
|
72
|
+
* release version into `00_commitinfo_data.ts` of every commit info folder the
|
|
73
|
+
* project has. Returns the written files.
|
|
74
|
+
*/
|
|
75
|
+
export const writeCommitInfoFiles = async (
|
|
76
|
+
projectDirArg: string,
|
|
77
|
+
versionArg: string,
|
|
78
|
+
): Promise<string[]> => {
|
|
79
|
+
const targetDirs: string[] = [];
|
|
80
|
+
for (const dir of commitInfoDirs) {
|
|
81
|
+
const dirPath = plugins.path.join(projectDirArg, dir);
|
|
82
|
+
if (await isDirectory(dirPath)) {
|
|
83
|
+
targetDirs.push(dirPath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (targetDirs.length === 0) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const packageJson = JSON.parse(
|
|
90
|
+
await plugins.fs.readFile(
|
|
91
|
+
plugins.path.join(projectDirArg, "package.json"),
|
|
92
|
+
"utf8",
|
|
93
|
+
),
|
|
94
|
+
) as { name?: unknown; description?: unknown };
|
|
95
|
+
const moduleSource = renderCommitInfoModule({
|
|
96
|
+
name: typeof packageJson.name === "string" ? packageJson.name : "",
|
|
97
|
+
version: versionArg,
|
|
98
|
+
description:
|
|
99
|
+
typeof packageJson.description === "string" ? packageJson.description : "",
|
|
100
|
+
});
|
|
101
|
+
const writtenFiles: string[] = [];
|
|
102
|
+
for (const dirPath of targetDirs) {
|
|
103
|
+
const filePath = plugins.path.join(dirPath, commitInfoFileName);
|
|
104
|
+
await plugins.fs.writeFile(filePath, moduleSource, "utf8");
|
|
105
|
+
writtenFiles.push(filePath);
|
|
106
|
+
}
|
|
107
|
+
return writtenFiles;
|
|
108
|
+
};
|
|
@@ -1137,7 +1137,7 @@ const waitForNpmProbe = async (
|
|
|
1137
1137
|
return lastResult;
|
|
1138
1138
|
}
|
|
1139
1139
|
if (attempt + 1 < attempts) {
|
|
1140
|
-
await plugins.
|
|
1140
|
+
await plugins.smartpromise.delayFor(
|
|
1141
1141
|
probeDelayForAttempt(attempt, delayMs, maxDelayMs),
|
|
1142
1142
|
);
|
|
1143
1143
|
}
|
package/ts/mod_release/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type IResolvedReleaseWorkflow,
|
|
19
19
|
} from "../helpers.workflow.js";
|
|
20
20
|
import * as commitHelpers from "../mod_commit/mod.helpers.js";
|
|
21
|
+
import { writeCommitInfoFiles } from "./helpers.commitinfo.js";
|
|
21
22
|
import {
|
|
22
23
|
inspectReleaseBranch,
|
|
23
24
|
integrateReleaseBranch,
|
|
@@ -1810,10 +1811,7 @@ async function runVersionStep(
|
|
|
1810
1811
|
`Bumping version: ${currentVersion} -> ${resolutionArg.version}`,
|
|
1811
1812
|
);
|
|
1812
1813
|
|
|
1813
|
-
|
|
1814
|
-
version: resolutionArg.version,
|
|
1815
|
-
});
|
|
1816
|
-
await commitInfo.writeIntoPotentialDirs();
|
|
1814
|
+
await writeCommitInfoFiles(cwdArg, resolutionArg.version);
|
|
1817
1815
|
await commitHelpers.updateProjectVersionFiles(
|
|
1818
1816
|
projectType,
|
|
1819
1817
|
resolutionArg.version,
|
|
@@ -591,7 +591,7 @@ export class DockerContainer {
|
|
|
591
591
|
/** Longer bound for root-helper cleanup, which may delete a large tree. */
|
|
592
592
|
private cleanupTimeoutSeconds = 600;
|
|
593
593
|
private bindOperationDelay = async (millisecondsArg: number): Promise<void> =>
|
|
594
|
-
plugins.
|
|
594
|
+
plugins.smartpromise.delayFor(millisecondsArg);
|
|
595
595
|
|
|
596
596
|
constructor() {
|
|
597
597
|
this.smartshell = new plugins.smartshell.Smartshell({
|
|
@@ -1624,7 +1624,7 @@ export class DockerContainer {
|
|
|
1624
1624
|
if (await this.isRunning(containerName)) {
|
|
1625
1625
|
return true;
|
|
1626
1626
|
}
|
|
1627
|
-
await plugins.
|
|
1627
|
+
await plugins.smartpromise.delayFor(1000);
|
|
1628
1628
|
}
|
|
1629
1629
|
return false;
|
|
1630
1630
|
}
|
|
@@ -118,7 +118,7 @@ export class InterProcessLock {
|
|
|
118
118
|
`If that process no longer exists, inspect and remove ${this.lockPath}.`,
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
|
-
await plugins.
|
|
121
|
+
await plugins.smartpromise.delayFor(Math.min(this.pollMs, remaining));
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -1115,7 +1115,7 @@ export class LegacyMongoMigration {
|
|
|
1115
1115
|
if (Date.now() > deadline) {
|
|
1116
1116
|
throw new Error(`The temporary MongoDB reader ${name} did not become ready in time.`);
|
|
1117
1117
|
}
|
|
1118
|
-
await plugins.
|
|
1118
|
+
await plugins.smartpromise.delayFor(readerPollIntervalMs);
|
|
1119
1119
|
}
|
|
1120
1120
|
}
|
|
1121
1121
|
|
|
@@ -216,7 +216,7 @@ export interface IObjectStorageBucketReconciliationOptions {
|
|
|
216
216
|
|
|
217
217
|
const defaultObjectStorageClock: IObjectStorageReconciliationClock = {
|
|
218
218
|
now: () => Date.now(),
|
|
219
|
-
delay: async (millisecondsArg) => plugins.
|
|
219
|
+
delay: async (millisecondsArg) => plugins.smartpromise.delayFor(millisecondsArg),
|
|
220
220
|
};
|
|
221
221
|
|
|
222
222
|
class ObjectStorageStageError extends Error {
|
package/ts/mod_services/index.ts
CHANGED
|
@@ -504,7 +504,7 @@ export async function handleRestart(serviceManager: ServiceManager, service: str
|
|
|
504
504
|
case "mongodb":
|
|
505
505
|
await serviceManager.assertMongoStartupAllowed();
|
|
506
506
|
await serviceManager.stopMongoDB();
|
|
507
|
-
await plugins.
|
|
507
|
+
await plugins.smartpromise.delayFor(2000);
|
|
508
508
|
await serviceManager.startMongoDB();
|
|
509
509
|
restarted = true;
|
|
510
510
|
break;
|
|
@@ -513,7 +513,7 @@ export async function handleRestart(serviceManager: ServiceManager, service: str
|
|
|
513
513
|
case "s3":
|
|
514
514
|
await serviceManager.assertObjectStorageStartupAllowed();
|
|
515
515
|
await serviceManager.stopObjectStorage();
|
|
516
|
-
await plugins.
|
|
516
|
+
await plugins.smartpromise.delayFor(2000);
|
|
517
517
|
await serviceManager.startObjectStorage();
|
|
518
518
|
restarted = true;
|
|
519
519
|
break;
|
|
@@ -521,7 +521,7 @@ export async function handleRestart(serviceManager: ServiceManager, service: str
|
|
|
521
521
|
case "elasticsearch":
|
|
522
522
|
case "es":
|
|
523
523
|
await serviceManager.stopElasticsearch();
|
|
524
|
-
await plugins.
|
|
524
|
+
await plugins.smartpromise.delayFor(2000);
|
|
525
525
|
await serviceManager.startElasticsearch();
|
|
526
526
|
restarted = true;
|
|
527
527
|
break;
|
|
@@ -535,7 +535,7 @@ export async function handleRestart(serviceManager: ServiceManager, service: str
|
|
|
535
535
|
await serviceManager.assertObjectStorageStartupAllowed();
|
|
536
536
|
}
|
|
537
537
|
await serviceManager.stopAll();
|
|
538
|
-
await plugins.
|
|
538
|
+
await plugins.smartpromise.delayFor(2000);
|
|
539
539
|
await serviceManager.startAll();
|
|
540
540
|
restarted = true;
|
|
541
541
|
break;
|
|
@@ -3,9 +3,8 @@ export * from '../plugins.js';
|
|
|
3
3
|
import * as smartshell from '@push.rocks/smartshell';
|
|
4
4
|
import * as smartfile from '@push.rocks/smartfile';
|
|
5
5
|
import * as smartnetwork from '@push.rocks/smartnetwork';
|
|
6
|
-
import * as smartdelay from '@push.rocks/smartdelay';
|
|
7
6
|
|
|
8
7
|
// @lossless.org scope
|
|
9
8
|
import * as nosqldb from '@lossless.org/client/nosqldb';
|
|
10
9
|
|
|
11
|
-
export { smartshell, smartfile, smartnetwork,
|
|
10
|
+
export { smartshell, smartfile, smartnetwork, nosqldb };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as plugins from './mod.plugins.js';
|
|
2
|
+
import { answerDefaultsWithoutTerminal, withPrompts } from '../helpers.prompts.js';
|
|
3
|
+
|
|
4
|
+
/** The file at the root of a template folder that configures the template. */
|
|
5
|
+
export const scafConfigFileName = '.smartscaf.yml';
|
|
6
|
+
|
|
7
|
+
/** The content of a template's `.smartscaf.yml`. */
|
|
8
|
+
export interface IScafTemplateConfig {
|
|
9
|
+
/** The answers offered for missing variables, keyed by their dotted name. */
|
|
10
|
+
defaults: Record<string, unknown>;
|
|
11
|
+
/** Template folders, relative to this one, whose files are merged into it. */
|
|
12
|
+
dependencies: {
|
|
13
|
+
merge: string[];
|
|
14
|
+
};
|
|
15
|
+
/** Shell commands run in the destination after the template is written. */
|
|
16
|
+
runafter: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A handlebars template folder: every file is rendered with the supplied
|
|
21
|
+
* variables, a `fileName` frontmatter entry renames the rendered file, and
|
|
22
|
+
* `{-{ … }-}` survives rendering as `{{ … }}`.
|
|
23
|
+
*/
|
|
24
|
+
export class ScafTemplate {
|
|
25
|
+
public readonly dirPath: string;
|
|
26
|
+
public config: IScafTemplateConfig = {
|
|
27
|
+
defaults: {},
|
|
28
|
+
dependencies: { merge: [] },
|
|
29
|
+
runafter: [],
|
|
30
|
+
};
|
|
31
|
+
/** The template files, followed by the files of every merged template. */
|
|
32
|
+
public templateFiles: plugins.smartfile.SmartFile[] = [];
|
|
33
|
+
public suppliedVariables: Record<string, unknown> = {};
|
|
34
|
+
public missingVariables: string[] = [];
|
|
35
|
+
|
|
36
|
+
constructor(dirPathArg: string) {
|
|
37
|
+
this.dirPath = plugins.path.resolve(dirPathArg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reads the template folder, its configuration and the templates it merges. */
|
|
41
|
+
public async readTemplateFromDir(): Promise<void> {
|
|
42
|
+
const ownFiles = await readFolderFiles(this.dirPath);
|
|
43
|
+
const configFile = ownFiles.find((fileArg) => fileArg.path === scafConfigFileName);
|
|
44
|
+
const parsedConfig = configFile
|
|
45
|
+
? ((await plugins.smartyaml.yamlStringToObject(
|
|
46
|
+
configFile.contents.toString(),
|
|
47
|
+
)) as Partial<IScafTemplateConfig> | null)
|
|
48
|
+
: null;
|
|
49
|
+
this.config = {
|
|
50
|
+
defaults: parsedConfig?.defaults ?? {},
|
|
51
|
+
dependencies: { merge: parsedConfig?.dependencies?.merge ?? [] },
|
|
52
|
+
runafter: parsedConfig?.runafter ?? [],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
this.templateFiles = ownFiles;
|
|
56
|
+
for (const dependency of this.config.dependencies.merge) {
|
|
57
|
+
const dependencyDir = plugins.path.join(this.dirPath, dependency);
|
|
58
|
+
if (!(await plugins.smartfs.directory(dependencyDir).exists())) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Template ${this.dirPath} merges ${dependency}, which is not a folder at ${dependencyDir}`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
this.templateFiles.push(...(await readFolderFiles(dependencyDir)));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Merges the given variables into the supplied ones and updates the missing variables. */
|
|
68
|
+
public async supplyVariables(variablesArg: Record<string, unknown>): Promise<void> {
|
|
69
|
+
this.suppliedVariables = {
|
|
70
|
+
...this.suppliedVariables,
|
|
71
|
+
...variablesArg,
|
|
72
|
+
};
|
|
73
|
+
this.missingVariables = await this.findMissingVariables();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Asks for every missing variable, offering the template default. Without an
|
|
78
|
+
* interactive terminal the defaults are taken.
|
|
79
|
+
*/
|
|
80
|
+
public async askCliForMissingVariables(): Promise<void> {
|
|
81
|
+
this.missingVariables = await this.findMissingVariables();
|
|
82
|
+
if (this.missingVariables.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const questions: plugins.smartconsole.IInputQuestion[] = this.missingVariables.map(
|
|
86
|
+
(variableArg) => {
|
|
87
|
+
const defaultValue = this.config.defaults[variableArg];
|
|
88
|
+
return {
|
|
89
|
+
name: variableArg,
|
|
90
|
+
type: 'input',
|
|
91
|
+
default: defaultValue ? String(defaultValue) : 'undefined variable',
|
|
92
|
+
message: `What is the value of ${variableArg}?`,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
const answers = await withPrompts((promptsArg) =>
|
|
97
|
+
promptsArg.askAll(questions, answerDefaultsWithoutTerminal),
|
|
98
|
+
);
|
|
99
|
+
for (const [variable, value] of Object.entries(answers)) {
|
|
100
|
+
plugins.smartobject.smartAdd(this.suppliedVariables, variable, value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Renders every template file in memory; the template files stay untouched. */
|
|
105
|
+
public async renderToMemory(): Promise<plugins.smartfile.SmartFile[]> {
|
|
106
|
+
const renderedFiles: plugins.smartfile.SmartFile[] = [];
|
|
107
|
+
for (const templateFile of this.getContentFiles()) {
|
|
108
|
+
const document = await plugins.smartmarkdown.parseFrontmatter(
|
|
109
|
+
plugins.smarthbs.renderString(templateFile.contents.toString(), this.suppliedVariables),
|
|
110
|
+
);
|
|
111
|
+
const fileName = document.data.fileName;
|
|
112
|
+
const filePath =
|
|
113
|
+
typeof fileName === 'string' && fileName
|
|
114
|
+
? plugins.path.join(plugins.path.dirname(templateFile.path), fileName)
|
|
115
|
+
: templateFile.path;
|
|
116
|
+
renderedFiles.push(
|
|
117
|
+
plugins.smartFileFactory.fromBuffer(
|
|
118
|
+
filePath,
|
|
119
|
+
Buffer.from(await plugins.smarthbs.postprocess(document.content)),
|
|
120
|
+
templateFile.base,
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return renderedFiles;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Renders the template into the destination folder and runs its `runafter` commands there. */
|
|
128
|
+
public async writeToDisk(destinationDirArg: string): Promise<void> {
|
|
129
|
+
const renderedFiles = await this.renderToMemory();
|
|
130
|
+
await plugins.smartFileFactory
|
|
131
|
+
.virtualDirectoryFromFileArray(renderedFiles)
|
|
132
|
+
.saveToDisk(destinationDirArg);
|
|
133
|
+
const smartshellInstance = new plugins.smartshell.Smartshell({ executor: 'bash' });
|
|
134
|
+
for (const command of this.config.runafter) {
|
|
135
|
+
await smartshellInstance.execStrict(command, { cwd: destinationDirArg });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The files that get rendered: everything except the configuration of each merged template. */
|
|
140
|
+
private getContentFiles(): plugins.smartfile.SmartFile[] {
|
|
141
|
+
return this.templateFiles.filter((fileArg) => fileArg.path !== scafConfigFileName);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async findMissingVariables(): Promise<string[]> {
|
|
145
|
+
const missingVariables = new Set<string>();
|
|
146
|
+
for (const templateFile of this.getContentFiles()) {
|
|
147
|
+
for (const variable of await plugins.smarthbs.checkVarsSatisfaction(
|
|
148
|
+
templateFile.contents.toString(),
|
|
149
|
+
this.suppliedVariables,
|
|
150
|
+
)) {
|
|
151
|
+
missingVariables.add(variable);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return [...missingVariables];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const readFolderFiles = async (dirPathArg: string): Promise<plugins.smartfile.SmartFile[]> =>
|
|
159
|
+
(await plugins.smartFileFactory.virtualDirectoryFromPath(dirPathArg)).listFiles();
|
package/ts/mod_template/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as plugins from './mod.plugins.js';
|
|
2
2
|
import * as paths from '../paths.js';
|
|
3
|
+
import { ScafTemplate } from './classes.scaftemplate.js';
|
|
3
4
|
|
|
4
5
|
import { logger } from '../gitzone.logging.js';
|
|
5
6
|
import { answerDefaultsWithoutTerminal, ask, stringChoices } from '../helpers.prompts.js';
|
|
@@ -17,7 +18,7 @@ export const isTemplate = async (templateNameArg: string) => {
|
|
|
17
18
|
|
|
18
19
|
export const getTemplate = async (templateNameArg: string) => {
|
|
19
20
|
if (await isTemplate(templateNameArg)) {
|
|
20
|
-
const localScafTemplate = new
|
|
21
|
+
const localScafTemplate = new ScafTemplate(
|
|
21
22
|
getTemplatePath(templateNameArg),
|
|
22
23
|
);
|
|
23
24
|
await localScafTemplate.readTemplateFromDir();
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export * from '../plugins.js';
|
|
2
2
|
|
|
3
3
|
import * as smartfile from '@push.rocks/smartfile';
|
|
4
|
-
import * as
|
|
4
|
+
import * as smarthbs from '@push.rocks/smarthbs/iso';
|
|
5
|
+
import * as smartmarkdown from '@push.rocks/smartmarkdown/iso';
|
|
6
|
+
import * as smartobject from '@push.rocks/smartobject';
|
|
7
|
+
import * as smartyaml from '@push.rocks/smartyaml';
|
|
5
8
|
|
|
6
|
-
export
|
|
9
|
+
export const smartFileFactory = smartfile.SmartFileFactory.nodeFs();
|
|
10
|
+
|
|
11
|
+
export { smartfile, smarthbs, smartmarkdown, smartobject, smartyaml };
|
package/ts/plugins.ts
CHANGED
|
@@ -18,7 +18,6 @@ import * as smartshell from '@push.rocks/smartshell';
|
|
|
18
18
|
import * as smartnetwork from '@push.rocks/smartnetwork';
|
|
19
19
|
import * as smartfile from '@push.rocks/smartfile';
|
|
20
20
|
import { SmartFs, SmartFsProviderNode } from '@push.rocks/smartfs';
|
|
21
|
-
import * as smartdelay from '@push.rocks/smartdelay';
|
|
22
21
|
|
|
23
22
|
// @lossless.org scope
|
|
24
23
|
import * as objectstorage from '@lossless.org/client/objectstorage';
|
|
@@ -68,7 +67,6 @@ export {
|
|
|
68
67
|
smartshell,
|
|
69
68
|
smartnetwork,
|
|
70
69
|
smartfile,
|
|
71
|
-
smartdelay,
|
|
72
70
|
objectstorage,
|
|
73
71
|
s3,
|
|
74
72
|
tsdockerReleaseProtocol,
|