ngx-devkit-builders 0.0.3 → 0.0.5
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/README.md +2 -1
- package/package.json +1 -1
- package/version/index.js +58 -18
- package/version/schema.json +5 -0
package/README.md
CHANGED
|
@@ -41,7 +41,8 @@ _More builders can be added in the future._
|
|
|
41
41
|
"outputFile": "src/environments/version.ts", // or src/assets/version.json
|
|
42
42
|
"fields": ["version", "date", "author", "git"], // or custom selection
|
|
43
43
|
"lint": "eslint", // or "tslint"
|
|
44
|
-
"variable": "VERSION" // or whatever you want
|
|
44
|
+
"variable": "VERSION", // or whatever you want
|
|
45
|
+
"verbose": false // or true
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
package/package.json
CHANGED
package/version/index.js
CHANGED
|
@@ -3,45 +3,85 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const architect_1 = require("@angular-devkit/architect");
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
exports.default = (0, architect_1.createBuilder)(({ outputFile, fields, lint, variable }, ctx) => {
|
|
6
|
+
exports.default = (0, architect_1.createBuilder)(({ outputFile, fields, lint, variable, verbose }, ctx) => {
|
|
7
7
|
ctx.logger.info('🚧 Creating version information file…');
|
|
8
8
|
let targetFile = '';
|
|
9
|
+
const generalError = '❌ Creating version information file failed';
|
|
9
10
|
try {
|
|
11
|
+
const result = {};
|
|
10
12
|
const rootPath = (0, core_1.getSystemPath)((0, core_1.normalize)(ctx.workspaceRoot));
|
|
11
13
|
const encoding = 'utf-8';
|
|
14
|
+
if (verbose === true)
|
|
15
|
+
ctx.logger.info(`Encoding for read/write is ${encoding}`);
|
|
12
16
|
const fileToPatch = `${rootPath}/${outputFile}`;
|
|
17
|
+
if (verbose === true)
|
|
18
|
+
ctx.logger.info(`Output file is ${fileToPatch}`);
|
|
13
19
|
targetFile = fileToPatch;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
head = head.split(':')[1].trim();
|
|
20
|
+
const packageJson = JSON.parse((0, fs_1.readFileSync)(`${rootPath}/package.json`, encoding));
|
|
21
|
+
if (fields.includes('version')) {
|
|
22
|
+
result.version = packageJson.version;
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (fields.includes('date')) {
|
|
25
|
+
result.date = new Date().toISOString();
|
|
26
|
+
}
|
|
27
|
+
if (fields.includes('author')) {
|
|
28
|
+
result.author = packageJson.author;
|
|
29
|
+
}
|
|
30
|
+
if (fields.includes('git')) {
|
|
31
|
+
const headFile = `${rootPath}/.git/HEAD`;
|
|
32
|
+
if (verbose === true)
|
|
33
|
+
ctx.logger.info(`Head is ${headFile}`);
|
|
34
|
+
if (!(0, fs_1.existsSync)(headFile)) {
|
|
35
|
+
ctx.logger.info(generalError);
|
|
36
|
+
ctx.logger.error(`${headFile} was not found`);
|
|
37
|
+
return {
|
|
38
|
+
success: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let head = (0, fs_1.readFileSync)(headFile, encoding).toString().trim();
|
|
42
|
+
if (head.split(':').length > 1) {
|
|
43
|
+
head = head.split(':')[1].trim();
|
|
44
|
+
}
|
|
45
|
+
if (verbose === true)
|
|
46
|
+
ctx.logger.info(`Head is ${head}`);
|
|
47
|
+
const refFile = `${rootPath}/.git/${head}`;
|
|
48
|
+
if (verbose === true)
|
|
49
|
+
ctx.logger.info(`Last commit is located here ${refFile}`);
|
|
50
|
+
if (!(0, fs_1.existsSync)(refFile)) {
|
|
51
|
+
ctx.logger.info(generalError);
|
|
52
|
+
ctx.logger.error(`${refFile} was not found`);
|
|
53
|
+
return {
|
|
54
|
+
success: false
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const commit = head ? (0, fs_1.readFileSync)(refFile, encoding).toString().trim() : undefined;
|
|
58
|
+
if (verbose === true)
|
|
59
|
+
ctx.logger.info(`Commit is ${commit}`);
|
|
60
|
+
const branch = head?.split('/')?.pop();
|
|
61
|
+
if (verbose === true)
|
|
62
|
+
ctx.logger.info(`Branch is ${branch}`);
|
|
63
|
+
const git = branch || commit ? { branch, commit } : undefined;
|
|
64
|
+
result.git = git;
|
|
65
|
+
}
|
|
66
|
+
const json = JSON.stringify(result, null, 2);
|
|
29
67
|
const rawFormat = outputFile?.split('.')?.pop();
|
|
30
68
|
const format = ['json', 'ts'].includes(rawFormat) ? rawFormat : 'json';
|
|
69
|
+
if (verbose === true)
|
|
70
|
+
ctx.logger.info(`Output format is: ${format}`);
|
|
31
71
|
if (format === 'ts') {
|
|
32
72
|
(0, fs_1.writeFileSync)(fileToPatch, `// IMPORTANT: THIS FILE IS AUTO GENERATED!
|
|
33
73
|
/* ${lint === 'tslint' ? 'tslint:disable' : 'eslint-disable'} */
|
|
34
74
|
export const ${variable} = ${json};
|
|
35
75
|
/* ${lint === 'tslint' ? 'tslint:enable' : 'eslint-enable'} */
|
|
36
|
-
`, { encoding
|
|
76
|
+
`, { encoding });
|
|
37
77
|
}
|
|
38
78
|
else {
|
|
39
79
|
(0, fs_1.writeFileSync)(fileToPatch, json, { encoding });
|
|
40
80
|
}
|
|
41
81
|
}
|
|
42
82
|
catch (error) {
|
|
43
|
-
ctx.logger.info(
|
|
44
|
-
ctx.logger.error(error);
|
|
83
|
+
ctx.logger.info(generalError);
|
|
84
|
+
ctx.logger.error(JSON.stringify(error, null, 2));
|
|
45
85
|
return {
|
|
46
86
|
success: false
|
|
47
87
|
};
|
package/version/schema.json
CHANGED