ngx-devkit-builders 1.0.0 → 1.2.0
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/LICENSE +1 -1
- package/README.md +6 -37
- package/builders.json +10 -0
- package/copy-environment/index.js +54 -0
- package/copy-environment/schema.json +24 -0
- package/package.json +3 -2
- package/robots/index.js +43 -0
- package/robots/schema.json +21 -0
- package/version/schema.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -17,45 +17,14 @@ This package contains Architect builders used to build and test Angular applicat
|
|
|
17
17
|
|
|
18
18
|
## Builders
|
|
19
19
|
|
|
20
|
-
| Name
|
|
21
|
-
|
|
|
22
|
-
| version
|
|
20
|
+
| Name | Description |
|
|
21
|
+
| ---------------------------------------------------- | --------------------------------- |
|
|
22
|
+
| [version](./src/version/README.md) | Create build information file |
|
|
23
|
+
| [robots](./src/robots/README.md) | Create simplified robots.txt file |
|
|
24
|
+
| [copy-environment](./src/copy-environment/README.md) | Copy environment file |
|
|
23
25
|
|
|
24
26
|
_More builders can be added in the future._
|
|
25
27
|
|
|
26
|
-
## Quick start
|
|
27
|
-
|
|
28
|
-
1. Go to angular.json
|
|
29
|
-
|
|
30
|
-
```json
|
|
31
|
-
{
|
|
32
|
-
...,
|
|
33
|
-
"projects": {
|
|
34
|
-
"your-project-name": { // project will be different
|
|
35
|
-
...,
|
|
36
|
-
"architect": {
|
|
37
|
-
...,
|
|
38
|
-
"version": { // name can be different if you want
|
|
39
|
-
"builder": "ngx-devkit-builders:version",
|
|
40
|
-
"options": { // not needed
|
|
41
|
-
"outputFile": "src/environments/version.ts", // or src/assets/version.json
|
|
42
|
-
"fields": ["version", "date", "author", "git"], // or custom selection
|
|
43
|
-
"lint": "eslint", // or "tslint"
|
|
44
|
-
"variable": "VERSION", // or whatever you want
|
|
45
|
-
"verbose": false // or true
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
2. Run command
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
ng run your-project-name:version
|
|
57
|
-
```
|
|
58
|
-
|
|
59
28
|
## Compatibility
|
|
60
29
|
|
|
61
30
|
| Angular | ngx-app-version | Install |
|
|
@@ -65,7 +34,7 @@ ng run your-project-name:version
|
|
|
65
34
|
|
|
66
35
|
## License
|
|
67
36
|
|
|
68
|
-
Copyright © 2022 -
|
|
37
|
+
Copyright © 2022 - 2024 [Dominik Hladik](https://github.com/Celtian)
|
|
69
38
|
|
|
70
39
|
All contents are licensed under the [MIT license].
|
|
71
40
|
|
package/builders.json
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"builders": {
|
|
3
|
+
"copy-environment": {
|
|
4
|
+
"description": "Copy environment file",
|
|
5
|
+
"implementation": "./copy-environment",
|
|
6
|
+
"schema": "./copy-environment/schema.json"
|
|
7
|
+
},
|
|
8
|
+
"robots": {
|
|
9
|
+
"description": "Create simplified robots file",
|
|
10
|
+
"implementation": "./robots",
|
|
11
|
+
"schema": "./robots/schema.json"
|
|
12
|
+
},
|
|
3
13
|
"version": {
|
|
4
14
|
"description": "Create build information file",
|
|
5
15
|
"implementation": "./version",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const architect_1 = require("@angular-devkit/architect");
|
|
4
|
+
const core_1 = require("@angular-devkit/core");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
async function copyFiles({ sourceFile, targetFile, overwrite }) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
(0, fs_extra_1.copy)(sourceFile, targetFile, { overwrite }, () => {
|
|
9
|
+
reject();
|
|
10
|
+
});
|
|
11
|
+
resolve();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.default = (0, architect_1.createBuilder)(async ({ verbose, source, target, overwrite }, ctx) => {
|
|
15
|
+
ctx.logger.info('🚧 Creating robots file…');
|
|
16
|
+
const projectMetadata = await ctx.getProjectMetadata(ctx.target.project);
|
|
17
|
+
if (projectMetadata.projectType !== 'application') {
|
|
18
|
+
ctx.logger.error('❌ Project must be type of application');
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (ctx.target.configuration) {
|
|
24
|
+
ctx.logger.info(`Selected configuration "${ctx.target.configuration}"`);
|
|
25
|
+
}
|
|
26
|
+
const rootPath = (0, core_1.getSystemPath)((0, core_1.normalize)(ctx.workspaceRoot));
|
|
27
|
+
const environmentsFolder = `${rootPath}/${projectMetadata.sourceRoot}/environments`;
|
|
28
|
+
if (verbose)
|
|
29
|
+
ctx.logger.info(`Target folder is here "${environmentsFolder}"`);
|
|
30
|
+
const sourceFile = `${environmentsFolder}/${source}`;
|
|
31
|
+
const targetFile = `${environmentsFolder}/${target}`;
|
|
32
|
+
try {
|
|
33
|
+
await copyFiles({
|
|
34
|
+
sourceFile,
|
|
35
|
+
targetFile,
|
|
36
|
+
overwrite,
|
|
37
|
+
});
|
|
38
|
+
if (overwrite) {
|
|
39
|
+
ctx.logger.info(`✔️ Environment replaced in "${targetFile}"`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
ctx.logger.info(`✔️ Environment replaced in "${targetFile}" if not exists`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
ctx.logger.error(`❌ Failed to replace file "${targetFile}"`);
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"source": {
|
|
6
|
+
"description": "Relative path to source file",
|
|
7
|
+
"type": "string"
|
|
8
|
+
},
|
|
9
|
+
"target": {
|
|
10
|
+
"description": "Relative path to target file",
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"overwrite": {
|
|
14
|
+
"description": "Overwrite target",
|
|
15
|
+
"type": "boolean",
|
|
16
|
+
"default": false
|
|
17
|
+
},
|
|
18
|
+
"verbose": {
|
|
19
|
+
"description": "Extended logging output",
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"default": false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-devkit-builders",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Dominik Hladík",
|
|
6
6
|
"email": "dominik.hladik@seznam.cz",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"scripts": {},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@angular-devkit/architect": "^0.1700.8",
|
|
16
|
-
"@angular-devkit/core": "^17.0.8"
|
|
16
|
+
"@angular-devkit/core": "^17.0.8",
|
|
17
|
+
"fs-extra": "^11.2.0"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {},
|
|
19
20
|
"homepage": "https://github.com/Celtian/ngx-devkit-builders#readme",
|
package/robots/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const architect_1 = require("@angular-devkit/architect");
|
|
4
|
+
const core_1 = require("@angular-devkit/core");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const createRobots = (options) => {
|
|
7
|
+
const lines = ['User-agent: *'];
|
|
8
|
+
if (options.allow) {
|
|
9
|
+
lines.push('Allow: /');
|
|
10
|
+
if (options.sitemap) {
|
|
11
|
+
lines.push(`Sitemap: ${options.sitemap}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
lines.push('Disallow: /');
|
|
16
|
+
}
|
|
17
|
+
return lines.join('\n\n');
|
|
18
|
+
};
|
|
19
|
+
exports.default = (0, architect_1.createBuilder)(async ({ allow, sitemap, verbose }, ctx) => {
|
|
20
|
+
ctx.logger.info('🚧 Creating robots file…');
|
|
21
|
+
const projectMetadata = await ctx.getProjectMetadata(ctx.target.project);
|
|
22
|
+
if (projectMetadata.projectType !== 'application') {
|
|
23
|
+
ctx.logger.error('❌ Project must be type of application');
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (ctx.target.configuration) {
|
|
29
|
+
ctx.logger.info(`Selected configuration "${ctx.target.configuration}"`);
|
|
30
|
+
}
|
|
31
|
+
const rootPath = (0, core_1.getSystemPath)((0, core_1.normalize)(ctx.workspaceRoot));
|
|
32
|
+
const targetFile = `${rootPath}/${projectMetadata.sourceRoot}/robots.txt`;
|
|
33
|
+
if (verbose === true)
|
|
34
|
+
ctx.logger.info(`Target file is here "${targetFile}"`);
|
|
35
|
+
(0, fs_1.writeFileSync)(targetFile, createRobots({
|
|
36
|
+
allow,
|
|
37
|
+
sitemap,
|
|
38
|
+
}), { encoding: 'utf-8' });
|
|
39
|
+
ctx.logger.info(`✔️ Robots file successfully created in ${targetFile}`);
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"allow": {
|
|
6
|
+
"description": "Allow or disallow",
|
|
7
|
+
"type": "boolean",
|
|
8
|
+
"default": false
|
|
9
|
+
},
|
|
10
|
+
"sitemap": {
|
|
11
|
+
"description": "Sitemap.xml url",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"default": ""
|
|
14
|
+
},
|
|
15
|
+
"verbose": {
|
|
16
|
+
"description": "Extended logging output",
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"default": false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|