@atls/code-schematics 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/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./schematics"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MigrationEngineHost = void 0;
4
+ const node_pnp_engine_host_1 = require("./node-pnp-engine.host");
5
+ class MigrationEngineHost extends node_pnp_engine_host_1.NodePnpEngineHost {
6
+ _resolveCollectionPath(name) {
7
+ return name;
8
+ }
9
+ }
10
+ exports.MigrationEngineHost = MigrationEngineHost;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodePnpEngineHost = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const node_path_2 = require("node:path");
6
+ const node_path_3 = require("node:path");
7
+ const tools_1 = require("@angular-devkit/schematics/tools");
8
+ const tools_2 = require("@angular-devkit/schematics/tools");
9
+ const tools_3 = require("@angular-devkit/schematics/tools");
10
+ const tools_4 = require("@angular-devkit/schematics/tools");
11
+ const tools_5 = require("@angular-devkit/schematics/tools");
12
+ const tools_6 = require("@angular-devkit/schematics/tools");
13
+ const file_system_utility_1 = require("@angular-devkit/schematics/tools/file-system-utility");
14
+ class NodePnpEngineHost extends tools_4.FileSystemEngineHostBase {
15
+ constructor(paths) {
16
+ super();
17
+ this.paths = paths;
18
+ }
19
+ resolve(name, requester, references = new Set()) {
20
+ if (requester) {
21
+ if (references.has(requester)) {
22
+ references.add(requester);
23
+ throw new Error(`Circular schematic reference detected: ${JSON.stringify(Array.from(references))}`);
24
+ }
25
+ else {
26
+ references.add(requester);
27
+ }
28
+ }
29
+ const relativeBase = requester ? (0, node_path_1.dirname)(requester) : process.cwd();
30
+ let collectionPath;
31
+ if (name.startsWith('.')) {
32
+ name = (0, node_path_3.resolve)(relativeBase, name);
33
+ }
34
+ const resolveOptions = {
35
+ paths: (requester ? [(0, node_path_1.dirname)(requester), ...(this.paths || [])] : this.paths)?.filter(Boolean),
36
+ };
37
+ try {
38
+ const packageJsonPath = require.resolve((0, node_path_2.join)(name, 'package.json'), resolveOptions);
39
+ const { schematics } = require(packageJsonPath);
40
+ if (!schematics || typeof schematics !== 'string') {
41
+ throw new tools_6.NodePackageDoesNotSupportSchematics(name);
42
+ }
43
+ collectionPath = this.resolve(schematics, packageJsonPath, references);
44
+ }
45
+ catch (e) {
46
+ if (e.code !== 'MODULE_NOT_FOUND') {
47
+ throw e;
48
+ }
49
+ }
50
+ if (!collectionPath) {
51
+ try {
52
+ collectionPath = require.resolve(name, resolveOptions);
53
+ }
54
+ catch (e) {
55
+ if (e.code !== 'MODULE_NOT_FOUND') {
56
+ throw e;
57
+ }
58
+ }
59
+ }
60
+ if (!collectionPath) {
61
+ throw new tools_2.CollectionCannotBeResolvedException(name);
62
+ }
63
+ return collectionPath;
64
+ }
65
+ _resolveCollectionPath(name, requester) {
66
+ const collectionPath = this.resolve(name, requester);
67
+ (0, file_system_utility_1.readJsonFile)(collectionPath);
68
+ return collectionPath;
69
+ }
70
+ _resolveReferenceString(refString, parentPath) {
71
+ const ref = new tools_1.ExportStringRef(refString, parentPath);
72
+ if (!ref.ref) {
73
+ return null;
74
+ }
75
+ return { ref: ref.ref, path: ref.module };
76
+ }
77
+ _transformCollectionDescription(name, desc) {
78
+ if (!desc.schematics || typeof desc.schematics !== 'object') {
79
+ throw new tools_3.CollectionMissingSchematicsMapException(name);
80
+ }
81
+ return {
82
+ ...desc,
83
+ name,
84
+ };
85
+ }
86
+ _transformSchematicDescription(name, _collection, desc) {
87
+ if (!desc.factoryFn || !desc.path || !desc.description) {
88
+ throw new tools_5.SchematicMissingFieldsException(name);
89
+ }
90
+ return desc;
91
+ }
92
+ }
93
+ exports.NodePnpEngineHost = NodePnpEngineHost;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Schematics = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const node_path_2 = require("node:path");
6
+ const node_1 = require("@angular-devkit/core/node");
7
+ const tools_1 = require("@angular-devkit/schematics/tools");
8
+ const core_1 = require("@angular-devkit/core");
9
+ const migration_engine_host_1 = require("./migration-engine.host");
10
+ const node_pnp_engine_host_1 = require("./node-pnp-engine.host");
11
+ const utils_1 = require("./utils");
12
+ const utils_2 = require("./utils");
13
+ class Schematics {
14
+ constructor(cwd, force = false, dryRun = false) {
15
+ this.cwd = cwd;
16
+ this.force = force;
17
+ this.dryRun = dryRun;
18
+ }
19
+ async init(schematic, options = {}) {
20
+ const host = new core_1.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), this.cwd);
21
+ const workflow = new tools_1.NodeWorkflow(host, {
22
+ force: this.force,
23
+ dryRun: this.dryRun,
24
+ resolvePaths: [this.cwd],
25
+ schemaValidation: true,
26
+ engineHostCreator: ({ resolvePaths }) => new node_pnp_engine_host_1.NodePnpEngineHost(resolvePaths),
27
+ });
28
+ const collection = (0, utils_2.resolveSchematics)(this.cwd);
29
+ const events = [];
30
+ workflow.reporter.subscribe((event) => {
31
+ events.push(event);
32
+ });
33
+ await workflow
34
+ .execute({
35
+ collection,
36
+ schematic,
37
+ options: {
38
+ ...options,
39
+ cwd: this.cwd,
40
+ },
41
+ allowPrivate: true,
42
+ debug: true,
43
+ })
44
+ .toPromise();
45
+ return events;
46
+ }
47
+ async migrate(schematicName, migrationVersion, options = {}) {
48
+ const host = new core_1.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), this.cwd);
49
+ const workflow = new tools_1.NodeWorkflow(host, {
50
+ force: true,
51
+ dryRun: false,
52
+ engineHostCreator: ({ resolvePaths }) => new migration_engine_host_1.MigrationEngineHost(resolvePaths),
53
+ });
54
+ const events = [];
55
+ workflow.reporter.subscribe((event) => {
56
+ events.push(event);
57
+ });
58
+ const collections = (0, utils_1.expandCollections)(this.cwd, (0, utils_2.resolveSchematics)(this.cwd), schematicName);
59
+ const migrations = collections
60
+ .map((collection) => {
61
+ const schematic = collection.description.schematics[schematicName];
62
+ if (!schematic) {
63
+ return [];
64
+ }
65
+ const migrationsPath = (0, node_path_2.join)((0, node_path_1.dirname)(collection.description.path), (0, node_path_1.dirname)(schematic.schema), 'migrations.json');
66
+ const data = require(migrationsPath);
67
+ return Object.keys(data.schematics)
68
+ .map((key) => ({
69
+ collection: migrationsPath,
70
+ schematic: key,
71
+ migration: data.schematics[key],
72
+ }))
73
+ .filter((config) => config.migration.version > migrationVersion);
74
+ })
75
+ .flat();
76
+ for (const migration of migrations) {
77
+ await workflow
78
+ .execute({
79
+ collection: migration.collection,
80
+ schematic: migration.schematic,
81
+ debug: false,
82
+ options: {
83
+ ...options,
84
+ cwd: this.cwd,
85
+ },
86
+ })
87
+ .toPromise();
88
+ }
89
+ return events;
90
+ }
91
+ }
92
+ exports.Schematics = Schematics;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expandCollections = exports.expandCollection = exports.createCollection = void 0;
4
+ const node_1 = require("@angular-devkit/core/node");
5
+ const tools_1 = require("@angular-devkit/schematics/tools");
6
+ const core_1 = require("@angular-devkit/core");
7
+ const core_2 = require("@angular-devkit/core");
8
+ const core_3 = require("@angular-devkit/core");
9
+ const schematics_1 = require("@angular-devkit/schematics");
10
+ const createCollection = (root, collectionName) => {
11
+ const fsHost = new core_3.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), (0, core_1.normalize)(root));
12
+ const workflow = new tools_1.NodeWorkflow(fsHost, {
13
+ force: false,
14
+ dryRun: true,
15
+ packageManager: 'yarn',
16
+ root: (0, core_1.normalize)(root),
17
+ registry: new core_2.schema.CoreSchemaRegistry(schematics_1.formats.standardFormats),
18
+ });
19
+ return workflow.engine.createCollection(collectionName);
20
+ };
21
+ exports.createCollection = createCollection;
22
+ const expandCollection = (cwd, collectionName) => {
23
+ const collection = (0, exports.createCollection)(cwd, collectionName);
24
+ const collections = [collection];
25
+ if (collection.baseDescriptions) {
26
+ const baseCollections = collection.baseDescriptions
27
+ .map((base) => (0, exports.expandCollection)(cwd, base.name))
28
+ .flat();
29
+ return [...collections, ...baseCollections];
30
+ }
31
+ return collections;
32
+ };
33
+ exports.expandCollection = expandCollection;
34
+ const expandCollections = (cwd, collectionName, schematicName) => {
35
+ const collections = (0, exports.expandCollection)(cwd, collectionName).reverse();
36
+ const nested = collections.map((collection) => {
37
+ const schematic = collection.description.schematics[schematicName];
38
+ if (schematic && schematic.extends) {
39
+ const [extendsCollection, extendsSchematic] = schematic.extends.split(':');
40
+ return (0, exports.expandCollections)(cwd, extendsCollection, extendsSchematic);
41
+ }
42
+ return [];
43
+ });
44
+ return [...nested, collections].flat();
45
+ };
46
+ exports.expandCollections = expandCollections;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./collection.utils"), exports);
14
+ __exportStar(require("./resolve.utils"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSchematics = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const node_path_2 = require("node:path");
6
+ const dynamicRequire = eval('require');
7
+ const findPnpApiPath = (cwd) => {
8
+ if (process.versions.pnp) {
9
+ return require('module').findPnpApi(__filename).resolveRequest('pnpapi', null);
10
+ }
11
+ return (0, node_path_2.join)(cwd || process.cwd(), '.pnp.cjs');
12
+ };
13
+ const setupPnp = (cwd) => {
14
+ const pnpPath = findPnpApiPath(cwd);
15
+ dynamicRequire(pnpPath).setup();
16
+ };
17
+ const resolveSchematics = (cwd) => {
18
+ try {
19
+ return (0, node_path_2.join)((0, node_path_1.dirname)(dynamicRequire.resolve('@atls/schematics')), '..');
20
+ }
21
+ catch (error) {
22
+ setupPnp(cwd);
23
+ return (0, node_path_2.join)((0, node_path_1.dirname)(dynamicRequire.resolve('@atls/schematics')), '..');
24
+ }
25
+ };
26
+ exports.resolveSchematics = resolveSchematics;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@atls/code-schematics",
3
+ "version": "0.0.2",
4
+ "license": "BSD-3-Clause",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "yarn library build",
11
+ "build:worker": "rollup -c",
12
+ "prepack": "yarn run build",
13
+ "postpack": "rm -rf dist"
14
+ },
15
+ "dependencies": {
16
+ "@angular-devkit/core": "^13.1.1",
17
+ "@angular-devkit/schematics": "^13.1.1",
18
+ "@atls/schematics": "0.0.2"
19
+ },
20
+ "devDependencies": {
21
+ "rxjs": "6.6.7"
22
+ },
23
+ "publishConfig": {
24
+ "main": "dist/index.js",
25
+ "typings": "dist/index.d.ts"
26
+ },
27
+ "typings": "dist/index.d.ts"
28
+ }