@atls/code-schematics 1.0.0 → 2.0.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/index.d.ts +1 -0
  3. package/dist/generated/index.js +1 -0
  4. package/dist/generated/schematic-factory-export.d.ts +2 -0
  5. package/dist/generated/schematic-factory-export.js +6 -0
  6. package/dist/getters/index.d.ts +2 -0
  7. package/dist/getters/index.js +2 -0
  8. package/dist/getters/stream-report-callback.getter.d.ts +4 -0
  9. package/dist/getters/stream-report-callback.getter.js +20 -0
  10. package/dist/getters/stream-report-options.getter.d.ts +6 -0
  11. package/dist/getters/stream-report-options.getter.js +7 -0
  12. package/dist/helpers/events-log.helper.d.ts +2 -0
  13. package/dist/helpers/events-log.helper.js +20 -0
  14. package/dist/helpers/index.d.ts +3 -0
  15. package/dist/helpers/index.js +3 -0
  16. package/dist/helpers/prepare-tmp-dir.helper.d.ts +2 -0
  17. package/dist/helpers/prepare-tmp-dir.helper.js +8 -0
  18. package/dist/helpers/run-schematics.helper.d.ts +1 -0
  19. package/dist/helpers/run-schematics.helper.js +48 -0
  20. package/dist/helpers/write-tmp-schematic.helper.d.ts +2 -0
  21. package/dist/helpers/write-tmp-schematic.helper.js +11 -0
  22. package/dist/index.d.ts +4 -1
  23. package/dist/index.js +4 -1
  24. package/dist/schematic/index.d.ts +1 -0
  25. package/dist/schematic/index.js +1 -0
  26. package/dist/schematic/project/index.d.ts +1 -0
  27. package/dist/schematic/project/index.js +1 -0
  28. package/dist/schematic/project/project.factory.d.ts +2 -0
  29. package/dist/schematic/project/project.factory.js +11 -0
  30. package/dist/schematic/rules/index.d.ts +1 -0
  31. package/dist/schematic/rules/index.js +1 -0
  32. package/dist/schematic/rules/update-ts-config.rule.d.ts +2 -0
  33. package/dist/schematic/rules/update-ts-config.rule.js +7 -0
  34. package/dist/schematic/sources/generate-common.source.d.ts +2 -0
  35. package/dist/schematic/sources/generate-common.source.js +13 -0
  36. package/dist/schematic/sources/generate-project-specific.source.d.ts +2 -0
  37. package/dist/schematic/sources/generate-project-specific.source.js +19 -0
  38. package/dist/schematic/sources/index.d.ts +2 -0
  39. package/dist/schematic/sources/index.js +2 -0
  40. package/dist/schematic/utils/file.utils.d.ts +3 -0
  41. package/dist/schematic/utils/file.utils.js +6 -0
  42. package/dist/schematic/utils/gitignore.utils.d.ts +3 -0
  43. package/dist/schematic/utils/gitignore.utils.js +12 -0
  44. package/dist/schematic/utils/index.d.ts +5 -0
  45. package/dist/schematic/utils/index.js +5 -0
  46. package/dist/schematic/utils/json.utils.d.ts +6 -0
  47. package/dist/schematic/utils/json.utils.js +23 -0
  48. package/dist/schematic/utils/tsconfig.utils.d.ts +1 -0
  49. package/dist/schematic/utils/tsconfig.utils.js +5 -0
  50. package/dist/schematic/utils/yaml.utils.d.ts +5 -0
  51. package/dist/schematic/utils/yaml.utils.js +18 -0
  52. package/dist/scripts/build-steps/esbuild.build-step.d.ts +1 -0
  53. package/dist/scripts/build-steps/esbuild.build-step.js +17 -0
  54. package/dist/scripts/build-steps/index.d.ts +1 -0
  55. package/dist/scripts/build-steps/index.js +1 -0
  56. package/dist/scripts/exceptions/index.d.ts +1 -0
  57. package/dist/scripts/exceptions/index.js +1 -0
  58. package/dist/scripts/exceptions/undefined-build-result.exception.d.ts +3 -0
  59. package/dist/scripts/exceptions/undefined-build-result.exception.js +5 -0
  60. package/dist/scripts/getters/cjs-content.getter.d.ts +2 -0
  61. package/dist/scripts/getters/cjs-content.getter.js +4 -0
  62. package/dist/scripts/getters/encoded-content.getter.d.ts +1 -0
  63. package/dist/scripts/getters/encoded-content.getter.js +4 -0
  64. package/dist/scripts/getters/esbuild-config.getter.d.ts +2 -0
  65. package/dist/scripts/getters/esbuild-config.getter.js +32 -0
  66. package/dist/scripts/getters/generated-file-content.getter.d.ts +1 -0
  67. package/dist/scripts/getters/generated-file-content.getter.js +16 -0
  68. package/dist/scripts/getters/index.d.ts +4 -0
  69. package/dist/scripts/getters/index.js +4 -0
  70. package/dist/scripts/index.d.ts +1 -0
  71. package/dist/scripts/index.js +1 -0
  72. package/dist/scripts/schematic-build.script.d.ts +1 -0
  73. package/dist/scripts/schematic-build.script.js +72 -0
  74. package/dist/scripts/schematic-factory-build.script.d.ts +1 -0
  75. package/dist/scripts/schematic-factory-build.script.js +10 -0
  76. package/package.json +19 -4
  77. package/dist/migration-engine.host.d.ts +0 -4
  78. package/dist/migration-engine.host.js +0 -6
  79. package/dist/node-pnp-engine.host.d.ts +0 -16
  80. package/dist/node-pnp-engine.host.js +0 -89
  81. package/dist/schematics.d.ts +0 -9
  82. package/dist/schematics.js +0 -87
  83. package/dist/utils/collection.utils.d.ts +0 -6
  84. package/dist/utils/collection.utils.js +0 -40
  85. package/dist/utils/index.d.ts +0 -2
  86. package/dist/utils/index.js +0 -2
  87. package/dist/utils/resolve.utils.d.ts +0 -1
  88. package/dist/utils/resolve.utils.js +0 -22
@@ -0,0 +1,2 @@
1
+ export * from './stream-report-options.getter.js';
2
+ export * from './stream-report-callback.getter.js';
@@ -0,0 +1,2 @@
1
+ export * from "./stream-report-options.getter.js";
2
+ export * from "./stream-report-callback.getter.js";
@@ -0,0 +1,4 @@
1
+ import type { StreamReport } from '@yarnpkg/core';
2
+ type StreamReportCallbackType = Parameters<typeof StreamReport.start>[1];
3
+ export declare const getStreamReportCallback: (options: Record<string, string>) => Promise<StreamReportCallbackType>;
4
+ export {};
@@ -0,0 +1,20 @@
1
+ import { ppath } from '@yarnpkg/fslib';
2
+ import { xfs } from '@yarnpkg/fslib';
3
+ import { runSchematicHelper } from '../helpers/index.js';
4
+ import { writeTmpSchematicHelper } from '../helpers/index.js';
5
+ import { prepareTmpDir } from '../helpers/index.js';
6
+ export const getStreamReportCallback = async (options) => {
7
+ const streamReportCallback = async (report) => {
8
+ try {
9
+ const tmpDir = await xfs.mktempPromise();
10
+ const collectionPath = ppath.join(tmpDir, 'collection.json');
11
+ await writeTmpSchematicHelper(tmpDir);
12
+ await prepareTmpDir(tmpDir);
13
+ await runSchematicHelper('project', options, collectionPath);
14
+ }
15
+ catch (error) {
16
+ console.error(error);
17
+ }
18
+ };
19
+ return streamReportCallback;
20
+ };
@@ -0,0 +1,6 @@
1
+ import type { BaseCommand } from '@yarnpkg/cli';
2
+ import type { Configuration } from '@yarnpkg/core';
3
+ import type { StreamReport } from '@yarnpkg/core';
4
+ type StreamReportOptionsType = Parameters<typeof StreamReport.start>[0];
5
+ export declare const getStreamReportOptions: (command: BaseCommand, configuration: Configuration) => StreamReportOptionsType;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ export const getStreamReportOptions = (command, configuration) => {
2
+ const streamReportOptions = {
3
+ stdout: command.context.stdout,
4
+ configuration,
5
+ };
6
+ return streamReportOptions;
7
+ };
@@ -0,0 +1,2 @@
1
+ import type { DryRunEvent } from '@angular-devkit/schematics';
2
+ export declare const eventsLogHelper: (event: DryRunEvent) => void;
@@ -0,0 +1,20 @@
1
+ export const eventsLogHelper = (event) => {
2
+ const eventPath = event.path;
3
+ switch (event.kind) {
4
+ case 'error':
5
+ console.error(`ERROR! ${eventPath} ${event.description === 'alreadyExist' ? 'already exists' : 'does not exist'}.`);
6
+ break;
7
+ case 'update':
8
+ console.debug(`${'UPDATE'} ${eventPath} (${event.content.length} bytes)`);
9
+ break;
10
+ case 'create':
11
+ console.debug(`${'CREATE'} ${eventPath} (${event.content.length} bytes)`);
12
+ break;
13
+ case 'delete':
14
+ console.debug(`${'DELETE'} ${eventPath}`);
15
+ break;
16
+ case 'rename':
17
+ console.debug(`${'RENAME'} ${eventPath} => ${event.to}`);
18
+ break;
19
+ }
20
+ };
@@ -0,0 +1,3 @@
1
+ export * from './run-schematics.helper.js';
2
+ export * from './write-tmp-schematic.helper.js';
3
+ export * from './prepare-tmp-dir.helper.js';
@@ -0,0 +1,3 @@
1
+ export * from "./run-schematics.helper.js";
2
+ export * from "./write-tmp-schematic.helper.js";
3
+ export * from "./prepare-tmp-dir.helper.js";
@@ -0,0 +1,2 @@
1
+ import type { PortablePath } from '@yarnpkg/fslib';
2
+ export declare const prepareTmpDir: (tmpDir: PortablePath) => Promise<void>;
@@ -0,0 +1,8 @@
1
+ import { ppath } from '@yarnpkg/fslib';
2
+ import { xfs } from '@yarnpkg/fslib';
3
+ export const prepareTmpDir = async (tmpDir) => {
4
+ const projectRoot = process.cwd();
5
+ await xfs.copyFilePromise(ppath.join(projectRoot, '.pnp.cjs'), ppath.join(tmpDir, '.pnp.cjs'));
6
+ await xfs.symlinkPromise(ppath.join(projectRoot, 'package.json'), ppath.join(tmpDir, 'package.json'));
7
+ await xfs.symlinkPromise(ppath.join(projectRoot, 'runtime'), ppath.join(tmpDir, 'runtime'));
8
+ };
@@ -0,0 +1 @@
1
+ export declare const runSchematicHelper: (schematicName: string, options: Record<string, string>, collectionPath: string) => Promise<0 | 1>;
@@ -0,0 +1,48 @@
1
+ import { UnsuccessfulWorkflowExecution } from '@angular-devkit/schematics';
2
+ import { NodeWorkflow } from '@angular-devkit/schematics/tools';
3
+ import { eventsLogHelper } from './events-log.helper.js';
4
+ export const runSchematicHelper = async (schematicName, options, collectionPath) => {
5
+ const dryRun = false;
6
+ const debug = true;
7
+ let nothingDone = true;
8
+ const workflow = new NodeWorkflow(process.cwd(), {
9
+ force: false,
10
+ dryRun,
11
+ resolvePaths: [process.cwd(), import.meta.dirname],
12
+ packageManager: 'yarn',
13
+ });
14
+ workflow.reporter.subscribe((event) => {
15
+ nothingDone = false;
16
+ eventsLogHelper(event);
17
+ });
18
+ try {
19
+ await workflow
20
+ .execute({
21
+ collection: collectionPath,
22
+ schematic: schematicName,
23
+ options,
24
+ allowPrivate: true,
25
+ debug,
26
+ })
27
+ .toPromise();
28
+ if (nothingDone) {
29
+ console.info('Nothing to be done.');
30
+ }
31
+ else if (dryRun) {
32
+ console.info('Dry run enabled. No files written to disk.');
33
+ }
34
+ return 0;
35
+ }
36
+ catch (err) {
37
+ if (err instanceof UnsuccessfulWorkflowExecution) {
38
+ console.debug('The Schematic workflow failed. See above.');
39
+ }
40
+ else if (debug && err instanceof Error) {
41
+ console.debug(`An error occured:\n${err.stack}`);
42
+ }
43
+ else {
44
+ console.debug(`Error: ${err instanceof Error ? err.message : err}`);
45
+ }
46
+ return 1;
47
+ }
48
+ };
@@ -0,0 +1,2 @@
1
+ import type { PortablePath } from '@yarnpkg/fslib';
2
+ export declare const writeTmpSchematicHelper: (tmpDir: PortablePath) => Promise<void>;
@@ -0,0 +1,11 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import { ppath } from '@yarnpkg/fslib';
3
+ import { writeSchematicFactory } from '../generated/index.js';
4
+ export const writeTmpSchematicHelper = async (tmpDir) => {
5
+ const { writeFiles } = await import('@atls/code-runtime');
6
+ await writeFiles(tmpDir);
7
+ const projectDir = ppath.join(tmpDir, 'project');
8
+ await mkdir(projectDir, { recursive: true });
9
+ await writeSchematicFactory(ppath.join(projectDir, 'project.factory.cjs'));
10
+ console.info('All Schematic files writed to the tmp!');
11
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export * from './schematics.js';
1
+ export * from './getters/index.js';
2
+ export * from './helpers/index.js';
3
+ export * from './generated/index.js';
4
+ export * from './scripts/index.js';
package/dist/index.js CHANGED
@@ -1 +1,4 @@
1
- export * from "./schematics.js";
1
+ export * from "./getters/index.js";
2
+ export * from "./helpers/index.js";
3
+ export * from "./generated/index.js";
4
+ export * from "./scripts/index.js";
@@ -0,0 +1 @@
1
+ export * from './project/index.js';
@@ -0,0 +1 @@
1
+ export * from "./project/index.js";
@@ -0,0 +1 @@
1
+ export * from './project.factory.js';
@@ -0,0 +1 @@
1
+ export * from "./project.factory.js";
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '@angular-devkit/schematics';
2
+ export declare const main: (options: Record<string, string>) => Rule;
@@ -0,0 +1,11 @@
1
+ import { MergeStrategy } from '@angular-devkit/schematics';
2
+ import { chain } from '@angular-devkit/schematics';
3
+ import { mergeWith } from '@angular-devkit/schematics';
4
+ import { updateTsConfigRule } from '../rules/index.js';
5
+ import { generateCommonSource } from '../sources/index.js';
6
+ import { generateProjectSpecificSource } from '../sources/index.js';
7
+ export const main = (options) => chain([
8
+ updateTsConfigRule,
9
+ mergeWith(generateCommonSource(options), MergeStrategy.Overwrite),
10
+ mergeWith(generateProjectSpecificSource(options), MergeStrategy.Overwrite),
11
+ ]);
@@ -0,0 +1 @@
1
+ export * from './update-ts-config.rule.js';
@@ -0,0 +1 @@
1
+ export * from "./update-ts-config.rule.js";
@@ -0,0 +1,2 @@
1
+ import { updateTsConfigInTree } from '../utils/tsconfig.utils.js';
2
+ export declare const updateTsConfigRule: () => Promise<ReturnType<typeof updateTsConfigInTree>>;
@@ -0,0 +1,7 @@
1
+ import { updateTsConfigInTree } from '../utils/tsconfig.utils.js';
2
+ export const updateTsConfigRule = async () => {
3
+ const { tsConfig } = await import('@atls/code-runtime');
4
+ return updateTsConfigInTree({
5
+ ...tsConfig.compilerOptions,
6
+ });
7
+ };
@@ -0,0 +1,2 @@
1
+ import type { Source } from '@angular-devkit/schematics';
2
+ export declare const generateCommonSource: (options: Record<string, string>) => Source;
@@ -0,0 +1,13 @@
1
+ import { strings } from '@angular-devkit/core';
2
+ import { apply } from '@angular-devkit/schematics';
3
+ import { template } from '@angular-devkit/schematics';
4
+ import { move } from '@angular-devkit/schematics';
5
+ import { url } from '@angular-devkit/schematics';
6
+ export const generateCommonSource = (options) => apply(url('../templates/common'), [
7
+ template({
8
+ ...strings,
9
+ ...options,
10
+ dot: '.',
11
+ }),
12
+ move('./'),
13
+ ]);
@@ -0,0 +1,2 @@
1
+ import type { Source } from '@angular-devkit/schematics';
2
+ export declare const generateProjectSpecificSource: (options: Record<string, string>) => Source;
@@ -0,0 +1,19 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { strings } from '@angular-devkit/core';
4
+ import { apply } from '@angular-devkit/schematics';
5
+ import { url } from '@angular-devkit/schematics';
6
+ import { template } from '@angular-devkit/schematics';
7
+ import { move } from '@angular-devkit/schematics';
8
+ export const generateProjectSpecificSource = (options) => {
9
+ const { name: projectName } = JSON.parse(readFileSync(join(options.cwd, 'package.json'), 'utf-8'));
10
+ return apply(url(join('../templates', options.type)), [
11
+ template({
12
+ ...strings,
13
+ ...options,
14
+ projectName,
15
+ dot: '.',
16
+ }),
17
+ move('./'),
18
+ ]);
19
+ };
@@ -0,0 +1,2 @@
1
+ export * from './generate-common.source.js';
2
+ export * from './generate-project-specific.source.js';
@@ -0,0 +1,2 @@
1
+ export * from "./generate-common.source.js";
2
+ export * from "./generate-project-specific.source.js";
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '@angular-devkit/schematics';
2
+ import type { SchematicContext } from '@angular-devkit/schematics';
3
+ export declare const updateFileInTree: (path: string, callback: (file: string, context: SchematicContext) => string) => Rule;
@@ -0,0 +1,6 @@
1
+ export const updateFileInTree = (path, callback) => (host, context) => {
2
+ if (host.exists(path)) {
3
+ host.overwrite(path, callback(host.read(path).toString('utf-8'), context));
4
+ }
5
+ return host;
6
+ };
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '@angular-devkit/schematics';
2
+ import type { SchematicContext } from '@angular-devkit/schematics';
3
+ export declare const updateGitIgnoreInTree: (callback: (lines: Array<string>, context: SchematicContext) => Array<string>) => Rule;
@@ -0,0 +1,12 @@
1
+ const GITIGNORE_PATH = '.gitignore';
2
+ export const updateGitIgnoreInTree = (callback) => (host, context) => {
3
+ if (!host.exists(GITIGNORE_PATH)) {
4
+ host.create(GITIGNORE_PATH, '');
5
+ }
6
+ const gitignoreBuffer = host.read(GITIGNORE_PATH);
7
+ if (!gitignoreBuffer)
8
+ return host;
9
+ const content = gitignoreBuffer.toString('utf-8').split('\n');
10
+ host.overwrite(GITIGNORE_PATH, Array.from(callback(content, context)).join('\n'));
11
+ return host;
12
+ };
@@ -0,0 +1,5 @@
1
+ export * from './gitignore.utils.js';
2
+ export * from './tsconfig.utils.js';
3
+ export * from './json.utils.js';
4
+ export * from './yaml.utils.js';
5
+ export * from './file.utils.js';
@@ -0,0 +1,5 @@
1
+ export * from "./gitignore.utils.js";
2
+ export * from "./tsconfig.utils.js";
3
+ export * from "./json.utils.js";
4
+ export * from "./yaml.utils.js";
5
+ export * from "./file.utils.js";
@@ -0,0 +1,6 @@
1
+ import type { Rule } from '@angular-devkit/schematics';
2
+ import type { SchematicContext } from '@angular-devkit/schematics';
3
+ import type { Tree } from '@angular-devkit/schematics';
4
+ export declare const serializeJson: (json: string) => string;
5
+ export declare const readJsonInTree: (host: Tree, path: string) => void;
6
+ export declare const updateJsonInTree: <T = any, O = T>(path: string, callback: (json: T, context: SchematicContext) => O) => Rule;
@@ -0,0 +1,23 @@
1
+ import stripJsonComments from 'strip-json-comments';
2
+ export const serializeJson = (json) => `${JSON.stringify(json, null, 2)}\n`;
3
+ export const readJsonInTree = (host, path) => {
4
+ if (!host.exists(path)) {
5
+ throw new Error(`Cannot find ${path}`);
6
+ }
7
+ const contents = stripJsonComments(host.read(path)?.toString('utf-8') || '');
8
+ try {
9
+ return JSON.parse(contents);
10
+ }
11
+ catch (e) {
12
+ const error = e;
13
+ throw new Error(`Cannot parse ${path}: ${error.message}`);
14
+ }
15
+ };
16
+ export const updateJsonInTree = (path, callback) => (host, context) => {
17
+ if (!host.exists(path)) {
18
+ host.create(path, serializeJson(callback({}, context)));
19
+ return host;
20
+ }
21
+ host.overwrite(path, serializeJson(callback(readJsonInTree(host, path), context)));
22
+ return host;
23
+ };
@@ -0,0 +1 @@
1
+ export declare const updateTsConfigInTree: (compilerOptions: object) => import("@angular-devkit/schematics").Rule;
@@ -0,0 +1,5 @@
1
+ import { updateJsonInTree } from './json.utils.js';
2
+ export const updateTsConfigInTree = (compilerOptions) => updateJsonInTree('tsconfig.json', (tsconfig) => ({
3
+ ...tsconfig,
4
+ compilerOptions,
5
+ }));
@@ -0,0 +1,5 @@
1
+ import type { Rule } from '@angular-devkit/schematics';
2
+ import type { SchematicContext } from '@angular-devkit/schematics';
3
+ import type { Tree } from '@angular-devkit/schematics';
4
+ export declare const readYamlInTree: <T = any>(host: Tree, path: string) => T;
5
+ export declare const updateYamlInTree: <T = any, O = T>(path: string, callback: (yaml: T, context: SchematicContext) => O) => Rule;
@@ -0,0 +1,18 @@
1
+ import { load } from 'js-yaml';
2
+ import { dump } from 'js-yaml';
3
+ export const readYamlInTree = (host, path) => {
4
+ if (!host.exists(path)) {
5
+ throw new Error(`Cannot find ${path}`);
6
+ }
7
+ return load(host.read(path).toString('utf-8'));
8
+ };
9
+ export const updateYamlInTree = (path, callback) => (host, context) => {
10
+ if (!host.exists(path)) {
11
+ return host;
12
+ }
13
+ host.overwrite(path, dump(callback(readYamlInTree(host, path), context), {
14
+ noArrayIndent: true,
15
+ lineWidth: -1,
16
+ }));
17
+ return host;
18
+ };
@@ -0,0 +1 @@
1
+ export declare const esbuildBuildStep: () => Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { writeFile } from 'fs/promises';
2
+ import esbuild from 'esbuild';
3
+ import { UndefinedBuildRedultException } from '../exceptions/index.js';
4
+ import { getEsbuildConfig } from '../getters/index.js';
5
+ import { getCjsContent } from '../getters/index.js';
6
+ import { getEncodedContent } from '../getters/index.js';
7
+ import { getGeneratedFileContent } from '../getters/index.js';
8
+ export const esbuildBuildStep = async () => {
9
+ const esbuildConfig = getEsbuildConfig();
10
+ const result = await esbuild.build(esbuildConfig);
11
+ if (!result.outputFiles)
12
+ throw new UndefinedBuildRedultException();
13
+ const cjsContent = getCjsContent(result);
14
+ const encodedContent = getEncodedContent(cjsContent);
15
+ const generatedFileContent = getGeneratedFileContent(encodedContent);
16
+ await writeFile('src/generated/schematic-factory-export.ts', generatedFileContent);
17
+ };
@@ -0,0 +1 @@
1
+ export * from './esbuild.build-step.js';
@@ -0,0 +1 @@
1
+ export * from "./esbuild.build-step.js";
@@ -0,0 +1 @@
1
+ export * from './undefined-build-result.exception.js';
@@ -0,0 +1 @@
1
+ export * from "./undefined-build-result.exception.js";
@@ -0,0 +1,3 @@
1
+ export declare class UndefinedBuildRedultException extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,5 @@
1
+ export class UndefinedBuildRedultException extends Error {
2
+ constructor() {
3
+ super('SchematicFactory build result is undefined');
4
+ }
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { BuildResult } from 'esbuild';
2
+ export declare const getCjsContent: (buildResult: BuildResult) => string;
@@ -0,0 +1,4 @@
1
+ export const getCjsContent = (buildResult) => {
2
+ const cjsContent = buildResult.outputFiles[0].text;
3
+ return cjsContent;
4
+ };
@@ -0,0 +1 @@
1
+ export declare const getEncodedContent: (cjsContent: string) => string;
@@ -0,0 +1,4 @@
1
+ export const getEncodedContent = (cjsContent) => {
2
+ const encodedContent = Buffer.from(cjsContent).toString('base64');
3
+ return encodedContent;
4
+ };
@@ -0,0 +1,2 @@
1
+ import type { BuildOptions } from 'esbuild';
2
+ export declare const getEsbuildConfig: () => BuildOptions;
@@ -0,0 +1,32 @@
1
+ import { resolve } from 'node:path';
2
+ import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
3
+ export const getEsbuildConfig = () => {
4
+ const esbuildConfig = {
5
+ logLevel: 'error',
6
+ entryPoints: ['src/schematic/index.ts'],
7
+ bundle: true,
8
+ write: false,
9
+ format: 'cjs',
10
+ platform: 'node',
11
+ sourcemap: false,
12
+ target: 'esnext',
13
+ external: ['node:*', '@atls/code-runtime'],
14
+ plugins: [
15
+ pnpPlugin({
16
+ onResolve: async (args) => {
17
+ if (args.path.includes('.ts')) {
18
+ return {
19
+ path: resolve(args.resolveDir, args.path.replace(/\.js/, '')),
20
+ external: false,
21
+ };
22
+ }
23
+ return {
24
+ namespace: args.path,
25
+ external: false,
26
+ };
27
+ },
28
+ }),
29
+ ],
30
+ };
31
+ return esbuildConfig;
32
+ };
@@ -0,0 +1 @@
1
+ export declare const getGeneratedFileContent: (encodedContent: string) => string;
@@ -0,0 +1,16 @@
1
+ const WRITE_SCHEMATIC_FACTORY_FUNCTION = `export const writeSchematicFactory = async (path: string) => {
2
+ const content = Buffer.from(schematicFactoryCjsBase64, "base64").toString("utf-8");
3
+ const fs = await import('fs/promises')
4
+ await fs.writeFile(path, content);
5
+ };
6
+ `;
7
+ export const getGeneratedFileContent = (encodedContent) => {
8
+ const generatedFileContent = `// Auto-generated file
9
+ /* eslint-disable */
10
+
11
+ export const schematicFactoryCjsBase64 = "${encodedContent}";
12
+
13
+ ${WRITE_SCHEMATIC_FACTORY_FUNCTION}
14
+ `;
15
+ return generatedFileContent;
16
+ };
@@ -0,0 +1,4 @@
1
+ export * from './esbuild-config.getter.js';
2
+ export * from './cjs-content.getter.js';
3
+ export * from './encoded-content.getter.js';
4
+ export * from './generated-file-content.getter.js';
@@ -0,0 +1,4 @@
1
+ export * from "./esbuild-config.getter.js";
2
+ export * from "./cjs-content.getter.js";
3
+ export * from "./encoded-content.getter.js";
4
+ export * from "./generated-file-content.getter.js";
@@ -0,0 +1 @@
1
+ export * from './schematic-build.script.js';
@@ -0,0 +1 @@
1
+ export * from "./schematic-build.script.js";
@@ -0,0 +1 @@
1
+ export declare function generateSchematic(schematicDir: string, outputFile: string): Promise<void>;
@@ -0,0 +1,72 @@
1
+ import { readdir } from 'fs/promises';
2
+ import { mkdir } from 'fs/promises';
3
+ import { writeFile } from 'fs/promises';
4
+ import { readFile } from 'fs/promises';
5
+ import { join } from 'path';
6
+ import { dirname } from 'path';
7
+ async function buildFileStructure(dirPath) {
8
+ const result = {};
9
+ const entries = await readdir(dirPath, { withFileTypes: true });
10
+ for (const entry of entries) {
11
+ const fullPath = join(dirPath, entry.name);
12
+ if (entry.isDirectory()) {
13
+ result[entry.name] = await buildFileStructure(fullPath);
14
+ }
15
+ else {
16
+ const content = await readFile(fullPath, 'utf-8');
17
+ result[entry.name] = Buffer.from(content).toString('base64');
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ function generateModuleContent(structure) {
23
+ const createStructureCode = (obj, indent = '') => {
24
+ let code = '';
25
+ for (const [key, value] of Object.entries(obj)) {
26
+ if (typeof value === 'string') {
27
+ code += `${indent}'${key}': '${value}',\n`;
28
+ }
29
+ else {
30
+ code += `${indent}'${key}': {\n`;
31
+ code += createStructureCode(value, `${indent} `);
32
+ code += `${indent}},\n`;
33
+ }
34
+ }
35
+ return code;
36
+ };
37
+ return `// Auto-generated file
38
+ /* eslint-disable */
39
+ export const assetsStructure = {
40
+ ${createStructureCode(structure, ' ')}
41
+ }
42
+
43
+ export async function writeFiles(baseDir: string) {
44
+ const { join } = await import('path')
45
+ const { mkdir, writeFile } = await import('fs/promises')
46
+
47
+ async function writeRecursive(obj: any, currentPath: string) {
48
+ for (const [key, value] of Object.entries(obj)) {
49
+ const fullPath = join(currentPath, key)
50
+
51
+ if (typeof value === 'string') {
52
+ await writeFile(
53
+ fullPath,
54
+ Buffer.from(value, 'base64').toString('utf-8')
55
+ )
56
+ } else {
57
+ await mkdir(fullPath, { recursive: true })
58
+ await writeRecursive(value, fullPath)
59
+ }
60
+ }
61
+ }
62
+
63
+ await writeRecursive(assetsStructure, baseDir)
64
+ }
65
+ `;
66
+ }
67
+ export async function generateSchematic(schematicDir, outputFile) {
68
+ const structure = await buildFileStructure(schematicDir);
69
+ const moduleContent = generateModuleContent(structure);
70
+ await mkdir(dirname(outputFile), { recursive: true });
71
+ await writeFile(outputFile, moduleContent);
72
+ }
@@ -0,0 +1 @@
1
+ export {};