@catladder/cli 3.20.2 → 3.21.1
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/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +1 -1
- package/dist/pipeline/src/types/hooks.d.ts +15 -6
- package/dist/pipeline/src/utils/writeFiles.d.ts +2 -0
- package/dist/pipeline/src/utils/writeFiles.js +18 -6
- package/dist/pipeline/src/utils/writeFiles.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type BaseHookContext = {
|
|
2
2
|
/**
|
|
3
3
|
* the filename of the file
|
|
4
4
|
*/
|
|
5
5
|
filename: string;
|
|
6
|
-
/**
|
|
7
|
-
* the extension of the file
|
|
8
|
-
*/
|
|
9
|
-
extension: string;
|
|
10
6
|
/**
|
|
11
7
|
* the path of the file
|
|
12
8
|
*/
|
|
13
9
|
path: string;
|
|
10
|
+
/**
|
|
11
|
+
* the extension of the file
|
|
12
|
+
*/
|
|
13
|
+
extension: string;
|
|
14
|
+
};
|
|
15
|
+
export type YamlHookContext = BaseHookContext & {
|
|
16
|
+
data: any;
|
|
17
|
+
};
|
|
18
|
+
export type FileHookContext = BaseHookContext & {
|
|
14
19
|
/**
|
|
15
20
|
* the content of the file
|
|
16
21
|
*/
|
|
@@ -21,6 +26,10 @@ export type Hooks = {
|
|
|
21
26
|
/**
|
|
22
27
|
* transform the file before it is written. If undefined is returned, the file is not modified
|
|
23
28
|
*/
|
|
24
|
-
transformFileBeforeWrite
|
|
29
|
+
transformFileBeforeWrite?: (fileHookContext: FileHookContext) => MaybePromise<string | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* transform the yaml before it is written. If undefined is returned, the yaml is not modified
|
|
32
|
+
*/
|
|
33
|
+
transformYamlBeforeWrite?: (fileHookContext: YamlHookContext) => MaybePromise<any | undefined>;
|
|
25
34
|
};
|
|
26
35
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { stringify } from "yaml";
|
|
2
2
|
import type { Config } from "../types";
|
|
3
|
+
import type { BaseHookContext } from "../types/hooks";
|
|
3
4
|
type WriteFileOptions = {
|
|
4
5
|
commentChar: string;
|
|
5
6
|
};
|
|
@@ -10,6 +11,7 @@ export declare class FileWriter {
|
|
|
10
11
|
static create(config: Config): FileWriter;
|
|
11
12
|
constructor(config: Config);
|
|
12
13
|
protected writeTheFile(path: string, content: string): Promise<void>;
|
|
14
|
+
protected getBaseHookContext(path: string): Promise<BaseHookContext>;
|
|
13
15
|
writeGeneratedFile(path: string, content: string, options: WriteFileOptions): Promise<void>;
|
|
14
16
|
writeYamlfile(path: string, data: any): Promise<void>;
|
|
15
17
|
protected getAutoGeneratedHeader(commentChar: string): string;
|
|
@@ -21,21 +21,33 @@ class FileWriter {
|
|
|
21
21
|
}
|
|
22
22
|
async writeTheFile(path, content) {
|
|
23
23
|
var _a, _b;
|
|
24
|
-
const transformedContent = await ((_a = this.config.hooks) === null || _a === void 0 ? void 0 : _a.transformFileBeforeWrite({
|
|
25
|
-
|
|
24
|
+
const transformedContent = await ((_b = (_a = this.config.hooks) === null || _a === void 0 ? void 0 : _a.transformFileBeforeWrite) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
25
|
+
...(await this.getBaseHookContext(path)),
|
|
26
26
|
content,
|
|
27
|
-
extension: (_b = path.split(".").pop()) !== null && _b !== void 0 ? _b : "",
|
|
28
|
-
path,
|
|
29
27
|
}));
|
|
30
28
|
await (0, promises_1.writeFile)(path, transformedContent !== null && transformedContent !== void 0 ? transformedContent : content, {
|
|
31
29
|
encoding: "utf-8",
|
|
32
30
|
});
|
|
33
31
|
}
|
|
32
|
+
async getBaseHookContext(path) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const filename = (_a = path.split("/").pop()) !== null && _a !== void 0 ? _a : "";
|
|
35
|
+
return {
|
|
36
|
+
filename,
|
|
37
|
+
path,
|
|
38
|
+
extension: (_b = path.split(".").pop()) !== null && _b !== void 0 ? _b : "",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
34
41
|
async writeGeneratedFile(path, content, options) {
|
|
35
42
|
await this.writeTheFile(path, [this.getAutoGeneratedHeader(options.commentChar), content].join("\n"));
|
|
36
43
|
}
|
|
37
|
-
writeYamlfile(path, data) {
|
|
38
|
-
|
|
44
|
+
async writeYamlfile(path, data) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const dataTransformed = await ((_b = (_a = this.config.hooks) === null || _a === void 0 ? void 0 : _a.transformYamlBeforeWrite) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
47
|
+
...(await this.getBaseHookContext(path)),
|
|
48
|
+
data,
|
|
49
|
+
}));
|
|
50
|
+
return this.writeGeneratedFile(path, (0, yaml_1.stringify)(dataTransformed !== null && dataTransformed !== void 0 ? dataTransformed : data, exports.yamlStringifyOptions), {
|
|
39
51
|
commentChar: "#",
|
|
40
52
|
});
|
|
41
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeFiles.js","sourceRoot":"","sources":["../../../../../pipeline/src/utils/writeFiles.ts"],"names":[],"mappings":";;;AAAA,0CAAwC;AACxC,+BAAiC;
|
|
1
|
+
{"version":3,"file":"writeFiles.js","sourceRoot":"","sources":["../../../../../pipeline/src/utils/writeFiles.ts"],"names":[],"mappings":";;;AAAA,0CAAwC;AACxC,+BAAiC;AAYpB,QAAA,oBAAoB,GAAqB;IACpD,iEAAiE;IACjE,SAAS,EAAE,CAAC;IACZ,4DAA4D;IAC5D,kBAAkB,EAAE,IAAI;IACxB,qEAAqE;IACrE,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF,MAAa,UAAU;IACd,MAAM,CAAC,MAAM,CAAC,MAAc;QACjC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM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