ngx-devkit-builders 0.0.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Celtian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <p align="center">
2
+ <a href="https://github.com/Celtian/ngx-devkit-builders" target="blank"><img src="assets/logo.svg?sanitize=true" alt="" width="120"></a>
3
+ <h1 align="center">NgxDevkit</h1>
4
+ </p>
5
+
6
+ [![npm version](https://badge.fury.io/js/ngx-devkit-builders.svg)](https://badge.fury.io/js/ngx-devkit-builders)
7
+ [![Package License](https://img.shields.io/npm/l/ngx-devkit-builders.svg)](https://www.npmjs.com/ngx-devkit-builders)
8
+ [![NPM Downloads](https://img.shields.io/npm/dm/ngx-devkit-builders.svg)](https://www.npmjs.com/ngx-devkit-builders)
9
+ [![Build & Publish](https://github.com/celtian/ngx-devkit-builders/workflows/Build%20&%20Publish/badge.svg)](https://github.com/celtian/ngx-devkit-builders/actions)
10
+ [![stars](https://badgen.net/github/stars/celtian/ngx-devkit-builders)](https://github.com/celtian/ngx-devkit-builders/)
11
+ [![forks](https://badgen.net/github/forks/celtian/ngx-devkit-builders)](https://github.com/celtian/ngx-devkit-builders/)
12
+ [![HitCount](http://hits.dwyl.com/celtian/ngx-devkit-builders.svg)](http://hits.dwyl.com/celtian/ngx-devkit-builders)
13
+
14
+ This package contains Architect builders used to build and test Angular applications and libraries.
15
+
16
+ > ✓ _Angular 15 compatible_
17
+
18
+ ## Builders
19
+
20
+ | Name | Description |
21
+ | ------- | ----------------------------- |
22
+ | version | Create build information file |
23
+
24
+ _More builders can be added in the future._
25
+
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
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ 2. Run command
52
+
53
+ ```
54
+ ng run your-project-name:version
55
+ ```
56
+
57
+ ## License
58
+
59
+ Copyright &copy; 2022 [Dominik Hladik](https://github.com/Celtian)
60
+
61
+ All contents are licensed under the [MIT license].
62
+
63
+ [mit license]: LICENSE
package/builders.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "builders": {
3
+ "version": {
4
+ "description": "Create build information file",
5
+ "implementation": "./version",
6
+ "schema": "./version/schema.json"
7
+ }
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "ngx-devkit-builders",
3
+ "version": "0.0.2",
4
+ "author": {
5
+ "name": "Dominik Hladík",
6
+ "email": "dominik.hladik@seznam.cz",
7
+ "url": "https://github.com/Celtian"
8
+ },
9
+ "private": false,
10
+ "license": "MIT",
11
+ "description": "Custom Angular builders",
12
+ "builders": "builders.json",
13
+ "scripts": {},
14
+ "dependencies": {
15
+ "@angular-devkit/architect": "^0.1500.3",
16
+ "@angular-devkit/core": "^15.0.3"
17
+ },
18
+ "devDependencies": {},
19
+ "homepage": "https://github.com/Celtian/ngx-devkit-builders#readme",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Celtian/ngx-devkit-builders.git"
23
+ },
24
+ "keywords": [
25
+ "angular",
26
+ "ngx",
27
+ "builder",
28
+ "devkit"
29
+ ],
30
+ "bugs": {
31
+ "url": "https://github.com/Celtian/ngx-devkit-builders/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=12"
35
+ },
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org"
38
+ },
39
+ "peerDependencies": {
40
+ "@angular/core": ">=12",
41
+ "@angular/cli": ">=12"
42
+ }
43
+ }
@@ -0,0 +1,48 @@
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
+ exports.default = (0, architect_1.createBuilder)(({ outputFile, fields, lint }, ctx) => {
7
+ ctx.logger.info('Creating version information file');
8
+ try {
9
+ const rootPath = (0, core_1.getSystemPath)((0, core_1.normalize)(ctx.workspaceRoot));
10
+ const encoding = 'utf-8';
11
+ const fileToPatch = `${rootPath}/${outputFile}`;
12
+ const packageJsonContent = (0, fs_1.readFileSync)(`${rootPath}/package.json`, encoding);
13
+ let head = (0, fs_1.readFileSync)(`${rootPath}/.git/HEAD`, encoding).toString().trim();
14
+ if (head.split(':').length > 1) {
15
+ head = head.split(':')[1].trim();
16
+ }
17
+ const commit = head ? (0, fs_1.readFileSync)(`${rootPath}/.git/${head}`, encoding).toString().trim() : undefined;
18
+ const branch = head?.split('/')?.pop();
19
+ const packageJson = JSON.parse(packageJsonContent);
20
+ const git = branch || commit ? { branch, commit } : undefined;
21
+ const json = JSON.stringify({
22
+ version: fields.includes('version') ? packageJson.version : undefined,
23
+ date: fields.includes('date') ? new Date().toISOString() : undefined,
24
+ author: fields.includes('author') ? packageJson.author : undefined,
25
+ git: fields.includes('git') ? git : undefined
26
+ }, null, 2);
27
+ const rawFormat = outputFile?.split('.')?.pop();
28
+ const format = ['json', 'ts'].includes(rawFormat) ? rawFormat : 'json';
29
+ if (format === 'ts') {
30
+ (0, fs_1.writeFileSync)(fileToPatch, `// IMPORTANT: THIS FILE IS AUTO GENERATED!
31
+ /* ${lint === 'tslint' ? 'tslint:disable' : 'eslint-disable'} */
32
+ export const VERSION = ${json};
33
+ /* ${lint === 'tslint' ? 'tslint:enable' : 'eslint-enable'} */
34
+ `, { encoding: 'utf-8' });
35
+ }
36
+ else {
37
+ (0, fs_1.writeFileSync)(fileToPatch, json, { encoding });
38
+ }
39
+ }
40
+ catch (error) {
41
+ return {
42
+ success: false
43
+ };
44
+ }
45
+ return {
46
+ success: true
47
+ };
48
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "outputFile": {
6
+ "description": "File where version information will be created",
7
+ "type": "string",
8
+ "default": "src/environments/version.ts"
9
+ },
10
+ "fields": {
11
+ "description": "Array of fields which will be included",
12
+ "type": "array",
13
+ "items": {
14
+ "type": "string",
15
+ "enum": ["version", "date", "author", "git"]
16
+ },
17
+ "default": ["version", "date", "author", "git"]
18
+ },
19
+ "lint": {
20
+ "description": "Linter which will be disabled inside generated file",
21
+ "type": "string",
22
+ "enum": ["eslint", "tslint"],
23
+ "default": "eslint"
24
+ }
25
+ }
26
+ }