@ibyar/cli 2.1.2 → 2.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/bin/cli.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import { join } from 'path';
2
3
  import { exit } from 'process';
3
- const CLI_VERSION = '2.1.2';
4
+ import { readFileSync } from 'fs';
5
+ import { fileURLToPath } from 'url';
4
6
  const args = process.argv;
5
7
  const inputs = args.slice(2);
6
8
  const showHelp = inputs.includes('-h') || inputs.includes('--help');
@@ -9,7 +11,7 @@ const runBuild = inputs.includes('-b') || inputs.includes('--build');
9
11
  const generateTypes = inputs.includes('-gt') || inputs.includes('--generate-types');
10
12
  if (showHelp) {
11
13
  const help = `
12
- Version ${CLI_VERSION}
14
+ Version ${readPackageVersion()}
13
15
  Usage: ibyar [options]
14
16
 
15
17
  Examples:
@@ -34,7 +36,7 @@ Options:
34
36
  exit();
35
37
  }
36
38
  if (printVersion) {
37
- console.log(CLI_VERSION);
39
+ console.log(readPackageVersion());
38
40
  }
39
41
  if (runBuild) {
40
42
  import('../compiler/compiler.js').then(module => {
@@ -44,9 +46,16 @@ if (runBuild) {
44
46
  else {
45
47
  module.compileArgs();
46
48
  }
47
- });
49
+ }).catch(error => console.error(error));
48
50
  }
49
51
  if (generateTypes) {
50
52
  console.log('generate types not supported yet.');
51
53
  }
54
+ function readPackageVersion() {
55
+ const url = fileURLToPath(import.meta.url);
56
+ const path = join(url, '..', '..', 'package.json');
57
+ const string = readFileSync(path, 'utf-8').toString();
58
+ const { version } = JSON.parse(string);
59
+ return version;
60
+ }
52
61
  //# sourceMappingURL=cli.js.map
package/bin/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/bin/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,WAAW,GAAG,OAAO,C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CAAC;AACJ,CAAC;AAED,IAAI,aAAa,EAAE,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { exit } from 'process';\n\nconst CLI_VERSION = '2.1.2';\n\nconst args = process.argv;\nconst inputs = args.slice(2);\n\nconst showHelp = inputs.includes('-h') || inputs.includes('--help');\nconst printVersion = inputs.length === 1 && (inputs.includes('-v') || inputs.includes('--version'));\n\nconst runBuild = inputs.includes('-b') || inputs.includes('--build');\nconst generateTypes = inputs.includes('-gt') || inputs.includes('--generate-types');\n\nif (showHelp) {\n\tconst help =\n\t\t`\nVersion ${CLI_VERSION}\nUsage: ibyar [options]\n\nExamples:\n ibyar\n ibyar -b\n ibyar -b -w\n ibyar -gt\n ibyar -v\n ibyar --help\n\nOptions:\n -b --build compile the project source code with ibyar transformers\n\t-w\t\t--watch\t\t\t\tcompile and watch source files, used with --build\n -gt --generate-types generate \"web-types.json\" files, and typescript\n\t definitions '.d.ts' files. \n\t you can import this file later in your \"index.ts\" \n\t\t\t\t\t\t\t\tor \"polyfills.ts\" file, so any editor \"VS Code\" can\n\t\t\t\t\t\t\t\tsupport autocomplete easily,\n -h --help print help message\n -v --version output the version number`;\n\tconsole.log(help);\n\texit();\n}\n\n\nif (printVersion) {\n\tconsole.log(CLI_VERSION);\n}\n\nif (runBuild) {\n\timport('../compiler/compiler.js').then(module => {\n\t\tif (inputs.includes('-w') || inputs.includes('--watch')) {\n\t\t\tmodule.compileAndWatchArgs();\n\t\t} else {\n\t\t\tmodule.compileArgs();\n\t\t}\n\t});\n}\n\nif (generateTypes) {\n\tconsole.log('generate types not supported yet.');\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/bin/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC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mB,EAAE,CAAC;QAC9B,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,WAAW,EAAE,CAAC;QACtB,CAAC;IACF,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,IAAI,aAAa,EAAE,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,kBAAkB;IAC1B,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IACtD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAwB,CAAC;IAC9D,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { join } from 'path';\nimport { exit } from 'process';\nimport { readFileSync } from 'fs';\nimport { fileURLToPath } from 'url';\n\nconst args = process.argv;\nconst inputs = args.slice(2);\n\nconst showHelp = inputs.includes('-h') || inputs.includes('--help');\nconst printVersion = inputs.length === 1 && (inputs.includes('-v') || inputs.includes('--version'));\n\nconst runBuild = inputs.includes('-b') || inputs.includes('--build');\nconst generateTypes = inputs.includes('-gt') || inputs.includes('--generate-types');\n\nif (showHelp) {\n\tconst help =\n\t\t`\nVersion ${readPackageVersion()}\nUsage: ibyar [options]\n\nExamples:\n ibyar\n ibyar -b\n ibyar -b -w\n ibyar -gt\n ibyar -v\n ibyar --help\n\nOptions:\n -b --build compile the project source code with ibyar transformers\n\t-w\t\t--watch\t\t\t\tcompile and watch source files, used with --build\n -gt --generate-types generate \"web-types.json\" files, and typescript\n\t definitions '.d.ts' files. \n\t you can import this file later in your \"index.ts\" \n\t\t\t\t\t\t\t\tor \"polyfills.ts\" file, so any editor \"VS Code\" can\n\t\t\t\t\t\t\t\tsupport autocomplete easily,\n -h --help print help message\n -v --version output the version number`;\n\tconsole.log(help);\n\texit();\n}\n\n\nif (printVersion) {\n\tconsole.log(readPackageVersion());\n}\n\nif (runBuild) {\n\timport('../compiler/compiler.js').then(module => {\n\t\tif (inputs.includes('-w') || inputs.includes('--watch')) {\n\t\t\tmodule.compileAndWatchArgs();\n\t\t} else {\n\t\t\tmodule.compileArgs();\n\t\t}\n\t}).catch(error => console.error(error));\n}\n\nif (generateTypes) {\n\tconsole.log('generate types not supported yet.');\n}\n\nfunction readPackageVersion(): string {\n\tconst url = fileURLToPath(import.meta.url);\n\tconst path = join(url, '..', '..', 'package.json');\n\tconst string = readFileSync(path, 'utf-8').toString();\n\tconst { version } = JSON.parse(string) as { version: string };\n\treturn version;\n}\n"]}
@@ -1,9 +1,11 @@
1
1
  import '../directives/register.js';
2
2
  import ts from 'typescript/lib/tsserverlibrary.js';
3
+ export declare function getTransformers(program: ts.Program): ts.CustomTransformers;
3
4
  export declare function scanDirective(program: ts.Program): void;
4
5
  export declare function emitProgram(program: ts.Program): void;
5
6
  export declare function compileFiles(files: readonly string[], options: ts.CompilerOptions): void;
6
7
  export declare function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine): void;
8
+ export declare function getConfigPath(): string;
7
9
  export declare function compileArgs(): void;
8
10
  export declare function compileAndWatchArgs(): void;
9
11
  //# sourceMappingURL=compiler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAOnD,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAEhD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAa9C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,QAIjF;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAMjF;AAeD,wBAAgB,WAAW,SAO1B;AAED,wBAAgB,mBAAmB,SAOlC"}
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAOnD,wBAAgB,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAY1E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAEhD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAG9C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,QAIjF;AAoBD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAejF;AAID,wBAAgB,aAAa,WAW5B;AAED,wBAAgB,WAAW,SAO1B;AAED,wBAAgB,mBAAmB,SAOlC"}
@@ -1,16 +1,12 @@
1
1
  import '../directives/register.js';
2
2
  import ts from 'typescript/lib/tsserverlibrary.js';
3
3
  import { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';
4
- import { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directie.js';
4
+ import { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directive.js';
5
5
  import { beforeCompileComponentOptions } from '../transformer/before-component.js';
6
6
  import { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';
7
7
  import { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';
8
- export function scanDirective(program) {
9
- program.getSourceFiles().forEach(scanDirectivesTypeVisitor);
10
- }
11
- export function emitProgram(program) {
12
- scanDirective(program);
13
- program.emit(undefined, undefined, undefined, undefined, {
8
+ export function getTransformers(program) {
9
+ return {
14
10
  before: [
15
11
  beforeCompileDirectiveOptions(program),
16
12
  beforeCompileComponentOptions(program),
@@ -20,22 +16,46 @@ export function emitProgram(program) {
20
16
  afterDeclarationsCompileComponentOptions(program),
21
17
  afterDeclarationsCompileDirectiveOptions(program),
22
18
  ],
23
- });
19
+ };
20
+ }
21
+ export function scanDirective(program) {
22
+ program.getSourceFiles().forEach(scanDirectivesTypeVisitor);
23
+ }
24
+ export function emitProgram(program) {
25
+ scanDirective(program);
26
+ program.emit(undefined, undefined, undefined, undefined, getTransformers(program));
24
27
  }
25
28
  export function compileFiles(files, options) {
26
29
  const host = ts.createCompilerHost(options);
27
30
  const program = ts.createProgram(files, options, host);
28
31
  emitProgram(program);
29
32
  }
33
+ const formatHost = {
34
+ getCanonicalFileName: path => path,
35
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
36
+ getNewLine: () => ts.sys.newLine
37
+ };
38
+ function reportDiagnostic(diagnostic) {
39
+ console.error("Error", diagnostic.code, ":", ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));
40
+ }
41
+ /**
42
+ * Prints a diagnostic every time the watch status changes.
43
+ * This is mainly for messages like "Starting compilation" or "Compilation completed".
44
+ */
45
+ function reportWatchStatusChanged(diagnostic) {
46
+ console.info(ts.formatDiagnostic(diagnostic, formatHost));
47
+ }
30
48
  export function compileAndWatchFiles(configPath, cmd) {
31
- const host = ts.createWatchCompilerHost(configPath, cmd.options, ts.sys);
49
+ const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
50
+ const host = ts.createWatchCompilerHost(configPath, cmd.options, ts.sys, createProgram, reportDiagnostic, reportWatchStatusChanged, cmd.watchOptions);
32
51
  const programFactory = ts.createWatchProgram(host);
33
52
  const programBuilder = programFactory.getProgram();
34
53
  const program = programBuilder.getProgram();
35
54
  emitProgram(program);
36
55
  }
37
- function getConfigPath() {
38
- const configPath = ts.findConfigFile('./', /*searchPath*/ ts.sys.fileExists, 'tsconfig.json');
56
+ export function getConfigPath() {
57
+ const tsconfig = process.argv.slice(2).filter(arg => arg.includes('tsconfig'))[0];
58
+ const configPath = ts.findConfigFile('./', /*searchPath*/ ts.sys.fileExists, tsconfig ?? 'tsconfig.json');
39
59
  if (!configPath) {
40
60
  throw new Error("Could not find a valid 'tsconfig.json'.");
41
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,UAAU,aAAa,CAAC,OAAmB;IAChD,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAmB;IAC9C,aAAa,CAAC,OAAO,CAAC,CAAC;IACvB,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;QACxD,MAAM,EAAE;YACP,6BAA6B,CAAC,OAAO,CAAC;YACtC,6BAA6B,CAAC,OAAO,CAAC;SACtC;QACD,KAAK,EAAE,EAAE;QACT,iBAAiB,EAAE;YA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AAC;QACV,OAAO;IACR,CAAC;IACD,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,oBAAoB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import '../directives/register.js';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';\nimport { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directie.js';\nimport { beforeCompileComponentOptions } from '../transformer/before-component.js';\nimport { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';\nimport { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';\n\nexport function scanDirective(program: ts.Program) {\n\tprogram.getSourceFiles().forEach(scanDirectivesTypeVisitor);\n}\n\nexport function emitProgram(program: ts.Program) {\n\tscanDirective(program);\n\tprogram.emit(undefined, undefined, undefined, undefined, {\n\t\tbefore: [\n\t\t\tbeforeCompileDirectiveOptions(program),\n\t\t\tbeforeCompileComponentOptions(program),\n\t\t],\n\t\tafter: [],\n\t\tafterDeclarations: [\n\t\t\tafterDeclarationsCompileComponentOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t\tafterDeclarationsCompileDirectiveOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t],\n\t});\n}\n\nexport function compileFiles(files: readonly string[], options: ts.CompilerOptions) {\n\tconst host = ts.createCompilerHost(options);\n\tconst program = ts.createProgram(files, options, host);\n\temitProgram(program);\n}\n\nexport function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine) {\n\tconst host = ts.createWatchCompilerHost(configPath, cmd.options, ts.sys);\n\tconst programFactory = ts.createWatchProgram(host);\n\tconst programBuilder = programFactory.getProgram();\n\tconst program = programBuilder.getProgram();\n\temitProgram(program);\n}\n\n\nfunction getConfigPath() {\n\tconst configPath = ts.findConfigFile(\n\t\t'./',\t\t\t/*searchPath*/\n\t\tts.sys.fileExists,\n\t\t'tsconfig.json'\n\t);\n\tif (!configPath) {\n\t\tthrow new Error(\"Could not find a valid 'tsconfig.json'.\");\n\t}\n\treturn configPath;\n}\n\nexport function compileArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileFiles(cmd.fileNames, cmd.options);\n}\n\nexport function compileAndWatchArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileAndWatchFiles(configPath, cmd);\n}\n"]}
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,UAAU,eAAe,CAAC,OAAmB;IAClD,OAAO;QACN,MAAM,EAAE;YACP,6BAA6B,CAAC,OAAO,CAAC;YACtC,6BAA6B,CAAC,OAAO,CAAC;SACtC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C,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,oBAAoB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import '../directives/register.js';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';\nimport { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directive.js';\nimport { beforeCompileComponentOptions } from '../transformer/before-component.js';\nimport { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';\nimport { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';\n\nexport function getTransformers(program: ts.Program): ts.CustomTransformers {\n\treturn {\n\t\tbefore: [\n\t\t\tbeforeCompileDirectiveOptions(program),\n\t\t\tbeforeCompileComponentOptions(program),\n\t\t],\n\t\tafter: [],\n\t\tafterDeclarations: [\n\t\t\tafterDeclarationsCompileComponentOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t\tafterDeclarationsCompileDirectiveOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t],\n\t};\n}\n\nexport function scanDirective(program: ts.Program) {\n\tprogram.getSourceFiles().forEach(scanDirectivesTypeVisitor);\n}\n\nexport function emitProgram(program: ts.Program) {\n\tscanDirective(program);\n\tprogram.emit(undefined, undefined, undefined, undefined, getTransformers(program));\n}\n\nexport function compileFiles(files: readonly string[], options: ts.CompilerOptions) {\n\tconst host = ts.createCompilerHost(options);\n\tconst program = ts.createProgram(files, options, host);\n\temitProgram(program);\n}\n\nconst formatHost: ts.FormatDiagnosticsHost = {\n\tgetCanonicalFileName: path => path,\n\tgetCurrentDirectory: ts.sys.getCurrentDirectory,\n\tgetNewLine: () => ts.sys.newLine\n};\n\nfunction reportDiagnostic(diagnostic: ts.Diagnostic) {\n\tconsole.error(\"Error\", diagnostic.code, \":\", ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));\n}\n\n/**\n * Prints a diagnostic every time the watch status changes.\n * This is mainly for messages like \"Starting compilation\" or \"Compilation completed\".\n */\nfunction reportWatchStatusChanged(diagnostic: ts.Diagnostic) {\n\tconsole.info(ts.formatDiagnostic(diagnostic, formatHost));\n}\n\nexport function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine) {\n\tconst createProgram = ts.createSemanticDiagnosticsBuilderProgram;\n\tconst host = ts.createWatchCompilerHost(\n\t\tconfigPath,\n\t\tcmd.options,\n\t\tts.sys,\n\t\tcreateProgram,\n\t\treportDiagnostic,\n\t\treportWatchStatusChanged,\n\t\tcmd.watchOptions,\n\t);\n\tconst programFactory = ts.createWatchProgram(host);\n\tconst programBuilder = programFactory.getProgram();\n\tconst program = programBuilder.getProgram();\n\temitProgram(program);\n}\n\n\n\nexport function getConfigPath() {\n\tconst tsconfig = process.argv.slice(2).filter(arg => arg.includes('tsconfig'))[0];\n\tconst configPath = ts.findConfigFile(\n\t\t'./',\t\t\t/*searchPath*/\n\t\tts.sys.fileExists,\n\t\ttsconfig ?? 'tsconfig.json'\n\t);\n\tif (!configPath) {\n\t\tthrow new Error(\"Could not find a valid 'tsconfig.json'.\");\n\t}\n\treturn configPath;\n}\n\nexport function compileArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileFiles(cmd.fileNames, cmd.options);\n}\n\nexport function compileAndWatchArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileAndWatchFiles(configPath, cmd);\n}\n"]}
package/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  export * from './transformer/factory.js';
2
+ export * from './transformer/helpers.js';
3
+ export * from './transformer/modules.js';
2
4
  export * from './transformer/before-component.js';
5
+ export * from './transformer/before-directive.js';
3
6
  export * from './transformer/after-declarations-component.js';
7
+ export * from './transformer/after-declarations-directive.js';
8
+ export * from './directives/register.js';
4
9
  export * from './compiler/compiler.js';
5
10
  export * from './elements/tags.js';
11
+ export * from './webpack/loader.js';
12
+ import { loader } from './webpack/loader.js';
13
+ export default loader;
6
14
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAG9D,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,eAAe,MAAM,CAAC"}
package/index.js CHANGED
@@ -1,6 +1,14 @@
1
1
  export * from './transformer/factory.js';
2
+ export * from './transformer/helpers.js';
3
+ export * from './transformer/modules.js';
2
4
  export * from './transformer/before-component.js';
5
+ export * from './transformer/before-directive.js';
3
6
  export * from './transformer/after-declarations-component.js';
7
+ export * from './transformer/after-declarations-directive.js';
8
+ export * from './directives/register.js';
4
9
  export * from './compiler/compiler.js';
5
10
  export * from './elements/tags.js';
11
+ export * from './webpack/loader.js';
12
+ import { loader } from './webpack/loader.js';
13
+ export default loader;
6
14
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAG9D,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './transformer/factory.js';\nexport * from './transformer/before-component.js';\nexport * from './transformer/after-declarations-component.js';\n\n\nexport * from './compiler/compiler.js';\n\nexport * from './elements/tags.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,eAAe,MAAM,CAAC","sourcesContent":["export * from './transformer/factory.js';\nexport * from './transformer/helpers.js';\nexport * from './transformer/modules.js';\nexport * from './transformer/before-component.js';\nexport * from './transformer/before-directive.js';\nexport * from './transformer/after-declarations-component.js';\nexport * from './transformer/after-declarations-directive.js';\nexport * from './directives/register.js';\nexport * from './compiler/compiler.js';\nexport * from './elements/tags.js';\nexport * from './webpack/loader.js';\n\nimport { loader } from './webpack/loader.js';\nexport default loader;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibyar/cli",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "The Ibyar/Aurora CLI tool",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ibyar/aurora",
@@ -36,12 +36,12 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@ibyar/core": "^2.1.2",
40
- "@ibyar/decorators": "^2.1.2",
41
- "@ibyar/directives": "^2.1.2",
42
- "@ibyar/elements": "^2.1.2",
43
- "@ibyar/expressions": "^2.1.2",
44
- "@ibyar/pipes": "^2.1.2",
39
+ "@ibyar/core": "^2.2.0",
40
+ "@ibyar/decorators": "^2.2.0",
41
+ "@ibyar/directives": "^2.2.0",
42
+ "@ibyar/elements": "^2.2.0",
43
+ "@ibyar/expressions": "^2.2.0",
44
+ "@ibyar/pipes": "^2.2.0",
45
45
  "tslib": "^2.6.3",
46
46
  "typescript": "^5.5.2"
47
47
  },
@@ -74,5 +74,5 @@
74
74
  "shadow-dom",
75
75
  "typescript"
76
76
  ],
77
- "gitHead": "d08ac0cb17c5288fcf316e60fa831420afadc450"
77
+ "gitHead": "70db847b00908addff4aed9e7e4f545edb5f2526"
78
78
  }
@@ -0,0 +1,8 @@
1
+ import ts from 'typescript/lib/tsserverlibrary.js';
2
+ /**
3
+ * search for `@Directive({})` and update definition files
4
+ * @param program a ts program
5
+ * @returns a transformer factory of source file
6
+ */
7
+ export declare function afterDeclarationsCompileDirectiveOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
8
+ //# sourceMappingURL=after-declarations-directive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"after-declarations-directive.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAKnD;;;;GAIG;AACH,wBAAgB,wCAAwC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CA0BlH"}
@@ -0,0 +1,26 @@
1
+ import ts from 'typescript/lib/tsserverlibrary.js';
2
+ import { updateModuleTypeWithDirectives } from './factory.js';
3
+ import { moduleManger } from './modules.js';
4
+ /**
5
+ * search for `@Directive({})` and update definition files
6
+ * @param program a ts program
7
+ * @returns a transformer factory of source file
8
+ */
9
+ export function afterDeclarationsCompileDirectiveOptions(program) {
10
+ return (context) => {
11
+ return sourceFile => {
12
+ const moduleInfo = moduleManger.get(sourceFile.fileName);
13
+ if (!moduleInfo?.classes?.length) {
14
+ return sourceFile;
15
+ }
16
+ const classes = moduleInfo.classes.filter(c => c.type === 'directive');
17
+ if (!(classes.length > 0)) {
18
+ return sourceFile;
19
+ }
20
+ const statements = sourceFile.statements?.slice() ?? [];
21
+ statements.push(...updateModuleTypeWithDirectives(classes));
22
+ return ts.factory.updateSourceFile(sourceFile, statements, sourceFile.isDeclarationFile, sourceFile.typeReferenceDirectives, sourceFile.referencedFiles, sourceFile.hasNoDefaultLib, sourceFile.libReferenceDirectives);
23
+ };
24
+ };
25
+ }
26
+ //# sourceMappingURL=after-declarations-directive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"after-declarations-directive.js","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CAAC,OAAmB;IAC3E,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACzD,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;gBAClC,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;YACvE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC3B,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACxD,UAAU,CAAC,IAAI,CAAC,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,CACjC,UAAU,EACV,UAAU,EACV,UAAU,CAAC,iBAAiB,EAC5B,UAAU,CAAC,uBAAuB,EAClC,UAAU,CAAC,eAAe,EAC1B,UAAU,CAAC,eAAe,EAC1B,UAAU,CAAC,sBAAsB,CACjC,CAAC;QACH,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { updateModuleTypeWithDirectives } from './factory.js';\nimport { moduleManger } from './modules.js';\n\n\n/**\n * search for `@Directive({})` and update definition files\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function afterDeclarationsCompileDirectiveOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tconst moduleInfo = moduleManger.get(sourceFile.fileName);\n\t\t\tif (!moduleInfo?.classes?.length) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes = moduleInfo.classes.filter(c => c.type === 'directive');\n\t\t\tif (!(classes.length > 0)) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst statements = sourceFile.statements?.slice() ?? [];\n\t\t\tstatements.push(...updateModuleTypeWithDirectives(classes));\n\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\tsourceFile,\n\t\t\t\tstatements,\n\t\t\t\tsourceFile.isDeclarationFile,\n\t\t\t\tsourceFile.typeReferenceDirectives,\n\t\t\t\tsourceFile.referencedFiles,\n\t\t\t\tsourceFile.hasNoDefaultLib,\n\t\t\t\tsourceFile.libReferenceDirectives,\n\t\t\t);\n\t\t};\n\t};\n}\n"]}
@@ -38,7 +38,7 @@ export declare function updateModuleTypeWithComponentView(classes: ClassInfo[]):
38
38
  *
39
39
  * example:
40
40
  * ```ts
41
- * export type ɵɵ0Directives0ɵɵ = [{
41
+ * export type ɵɵ0IfDirective0ɵɵ = {
42
42
  * selector: '*if';
43
43
  * successor: '*else',
44
44
  * inputs: [
@@ -47,7 +47,7 @@ export declare function updateModuleTypeWithComponentView(classes: ClassInfo[]):
47
47
  * { name: 'elseTemplateRef', aliasName: 'else' },
48
48
  * ],
49
49
  * outputs: [],
50
- * }];
50
+ * };
51
51
  * ```
52
52
  * @param classes directive class information
53
53
  * @returns new array of statements
@@ -126,7 +126,7 @@ export function updateModuleTypeWithComponentView(classes) {
126
126
  *
127
127
  * example:
128
128
  * ```ts
129
- * export type ɵɵ0Directives0ɵɵ = [{
129
+ * export type ɵɵ0IfDirective0ɵɵ = {
130
130
  * selector: '*if';
131
131
  * successor: '*else',
132
132
  * inputs: [
@@ -135,7 +135,7 @@ export function updateModuleTypeWithComponentView(classes) {
135
135
  * { name: 'elseTemplateRef', aliasName: 'else' },
136
136
  * ],
137
137
  * outputs: [],
138
- * }];
138
+ * };
139
139
  * ```
140
140
  * @param classes directive class information
141
141
  * @returns new array of statements
@@ -1 +1 @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C,CAAC;QAC9C,CAAC;QACD,IAAI,iBAAiB,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YACrD,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC;QAClB,iBAAiB,GAAG,iBAAiB,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;aACxD,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;aAC1D,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,OAAO,kBAAkB,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IAC9F,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { ToCamelCase } from '@ibyar/core/node.js';\nimport { ClassInfo } from './modules.js';\n\n\nexport function convertToProperties(json: { [key: string]: any }): ts.ObjectLiteralElementLike[] {\n\tconst keys = Object.keys(json);\n\treturn keys.map(key => createProperty(key, json[key]));\n}\n\nexport function createProperty(name: string, value: any): ts.ObjectLiteralElementLike {\n\treturn ts.factory.createPropertyAssignment(name, createInitializer(value));\n}\n\nexport function createInitializer(value: any): ts.Expression {\n\tif (Array.isArray(value)) {\n\t\tconst elements = value.map(createInitializer);\n\t\treturn ts.factory.createArrayLiteralExpression(elements);\n\t}\n\tswitch (typeof value) {\n\t\tcase 'string': return ts.factory.createStringLiteral(value);\n\t\tcase 'number': return ts.factory.createNumericLiteral(value);\n\t\tcase 'bigint': return ts.factory.createBigIntLiteral(value.toString());\n\t\tcase 'boolean': return value ? ts.factory.createTrue() : ts.factory.createFalse();\n\t\tcase 'object': {\n\t\t\tif (!value) {\n\t\t\t\treturn ts.factory.createNull();\n\t\t\t}\n\t\t\tconst properties = convertToProperties(value);\n\t\t\treturn ts.factory.createObjectLiteralExpression(properties);\n\t\t};\n\t}\n\treturn ts.factory.createNull();\n}\n\n\nexport function createInterfaceType(viewName: string, extendsType: string) {\n\tconst identifier = ts.factory.createIdentifier(extendsType);\n\tconst expressionWithTypeArguments = ts.factory.createExpressionWithTypeArguments(identifier, undefined);\n\tconst heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [expressionWithTypeArguments]);\n\treturn ts.factory.createInterfaceDeclaration(undefined, viewName, undefined, [heritageClause], []);\n\t// const exportModifier: ts.ModifierSyntaxKind = ts.SyntaxKind.ExportKeyword;\n\t// const modifier = ts.factory.createModifier(exportModifier);\n\t// return ts.factory.createInterfaceDeclaration([modifier], viewName, undefined, [heritageClause], []);\n}\n\nexport function createTypeLiteral(typeName: string) {\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode(typeName)),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode(typeName)\n\t\t),\n\t];\n\treturn ts.factory.createTypeLiteralNode(members);\n}\n\n/**\n * create view constructor interface of Type `T`\n * \n * ```ts\n * interface ConstructorOfView<T> {\n * \tnew(): T;\n * \treadonly prototype: T;\n * }\n * ```\n */\nexport function createConstructorOfViewInterfaceDeclaration() {\n\tconst typeParameter = ts.factory.createTypeParameterDeclaration(undefined, 'T');\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode('T')),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode('T')\n\t\t),\n\t];\n\treturn ts.factory.createInterfaceDeclaration(undefined, 'ConstructorOfView', [typeParameter], undefined, members);\n}\n\nexport function createStaticPropertyViewType(typeName: string) {\n\tconst typeArgument = ts.factory.createTypeReferenceNode(typeName);\n\treturn ts.factory.createTypeReferenceNode('ConstructorOfView', [typeArgument]);\n}\n\n\nexport function generateStatements(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): ts.NodeArray<ts.Statement> {\n\treturn ts.createSourceFile('temp', sourceText, scriptTarget, false, scriptKind).statements;\n}\n\nexport function generateNode<T = ts.Node>(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): T {\n\treturn generateStatements(sourceText, scriptTarget, scriptKind)[0] as T;\n}\n\n/**\n * declare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'user-view': HTMLUserViewElement;\n\t}\n}\n */\n\nexport function updateGlobalHTMLElementTagNameMap(views: { tagName: string, viewName: string }[]): ts.NodeArray<ts.Statement> {\n\tconst sourceCode = `\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}\n\nexport function updateModuleTypeWithComponentView(classes: ClassInfo[]): ts.NodeArray<ts.Statement> {\n\tconst viewClassDeclarations = classes.map(c => {\n\t\tconst inputs = c.inputs.map(input => input.aliasName);\n\t\tconst outputs = c.outputs.map(input => input.aliasName).map(output => 'on' + ToCamelCase(output));\n\t\tconst attributes = [...inputs, ...outputs].map(s => `'${s}'`).join(' | ');\n\t\tconst interfaceBody = `\n\t\t\tpublic static observedAttributes: [${attributes}];\n\n\t\t\t${c.inputs.map(input => `public ${input.aliasName}${input.type ? `: ${input.type}` : ''};`).join('\\n')}\n\n\t\t\t${c.outputs.map(output => `public on${ToCamelCase(output.aliasName)}${output.type ? `: ${output.type}` : ''};`).join('\\n')}\n\t\t\t\n\t\t`;\n\t\t// need to fix @FormValue type;\n\t\treturn c.views.map(view => `\n\t\t\tdeclare class ${view.viewName} extends ${view.extendsType} {\n\t\t\t\t${interfaceBody.trim()}\n\t\t\t}\n\t\t\tdeclare interface ${view.viewName} extends ${view.formAssociated ? `BaseFormAssociatedComponent<${c.name}>, ` : ''}BaseComponent<${c.name}> {}\n\t\t`);\n\t});\n\tconst views = classes.flatMap(c => c.views.map(v => ({ tagName: v.selector, viewName: v.viewName })));\n\tconst sourceCode = `\n\t\timport { BaseComponent, BaseFormAssociatedComponent, ConstructorOfView } from '@ibyar/core';\n\t\t${viewClassDeclarations.join('\\n')}\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}\n\n/**\n * create new type with name `ɵɵ0Directives0ɵɵ`\n * \n * example:\n * ```ts\n * export type ɵɵ0Directives0ɵɵ = [{\n * \tselector: '*if';\n * \tsuccessor: '*else',\n * \tinputs: [\n * \t\t{ name: 'ifCondition', aliasName: 'if' },\n * \t\t{ name: 'thenTemplateRef', aliasName: 'then' },\n * \t\t{ name: 'elseTemplateRef', aliasName: 'else' },\n * \t],\n * \toutputs: [],\n * }];\n * ```\n * @param classes directive class information\n * @returns new array of statements\n */\nexport function updateModuleTypeWithDirectives(classes: ClassInfo[]): ts.NodeArray<ts.Statement> {\n\tconst nodes: string[] | undefined = classes.map(directive => {\n\t\tconst inputs: string[] = directive.inputs.map(input => `{name: '${input.name}', aliasName: '${input.aliasName}'}`);\n\t\tconst outputs: string[] = directive.outputs.map(output => `{name: '${output.name}', aliasName: '${output.aliasName}'}`);\n\t\tconst temp: string[] = [`selector: '${directive.name}'`];\n\t\tif (directive.successor) {\n\t\t\ttemp.push(`successor: '${directive.successor}'`);\n\t\t}\n\t\tif (directive.inputs.length > 0) {\n\t\t\ttemp.push(`inputs: [${inputs.join(',')}]`);\n\t\t}\n\t\tif (directive.outputs.length > 0) {\n\t\t\ttemp.push(`outputs: [${outputs.join(',')}]`);\n\t\t}\n\t\tlet directiveTypeName = directive.name.startsWith('*')\n\t\t\t? directive.name.substring(1)\n\t\t\t: directive.name;\n\t\tdirectiveTypeName = directiveTypeName.replaceAll('-', ' ')\n\t\t\t.split(' ')\n\t\t\t.map(str => str.charAt(0).toUpperCase() + str.substring(1))\n\t\t\t.join('');\n\t\treturn `export type ɵɵ0${ToCamelCase(directiveTypeName)}Directive0ɵɵ = {${temp.join(',')}};`;\n\t});\n\treturn generateStatements(nodes.join());\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/cli/transformer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,MAAM,UAAU,mBAAmB,CAAC,IAA4B;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,KAAU;IACtD,OAAO,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAU;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC9C,OAAO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js';\nimport { ClassInfo } from './modules.js';\n\n\nexport function convertToProperties(json: { [key: string]: any }): ts.ObjectLiteralElementLike[] {\n\tconst keys = Object.keys(json);\n\treturn keys.map(key => createProperty(key, json[key]));\n}\n\nexport function createProperty(name: string, value: any): ts.ObjectLiteralElementLike {\n\treturn ts.factory.createPropertyAssignment(name, createInitializer(value));\n}\n\nexport function createInitializer(value: any): ts.Expression {\n\tif (Array.isArray(value)) {\n\t\tconst elements = value.map(createInitializer);\n\t\treturn ts.factory.createArrayLiteralExpression(elements);\n\t}\n\tswitch (typeof value) {\n\t\tcase 'string': return ts.factory.createStringLiteral(value);\n\t\tcase 'number': return ts.factory.createNumericLiteral(value);\n\t\tcase 'bigint': return ts.factory.createBigIntLiteral(value.toString());\n\t\tcase 'boolean': return value ? ts.factory.createTrue() : ts.factory.createFalse();\n\t\tcase 'object': {\n\t\t\tif (!value) {\n\t\t\t\treturn ts.factory.createNull();\n\t\t\t}\n\t\t\tconst properties = convertToProperties(value);\n\t\t\treturn ts.factory.createObjectLiteralExpression(properties);\n\t\t};\n\t}\n\treturn ts.factory.createNull();\n}\n\n\nexport function createInterfaceType(viewName: string, extendsType: string) {\n\tconst identifier = ts.factory.createIdentifier(extendsType);\n\tconst expressionWithTypeArguments = ts.factory.createExpressionWithTypeArguments(identifier, undefined);\n\tconst heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [expressionWithTypeArguments]);\n\treturn ts.factory.createInterfaceDeclaration(undefined, viewName, undefined, [heritageClause], []);\n\t// const exportModifier: ts.ModifierSyntaxKind = ts.SyntaxKind.ExportKeyword;\n\t// const modifier = ts.factory.createModifier(exportModifier);\n\t// return ts.factory.createInterfaceDeclaration([modifier], viewName, undefined, [heritageClause], []);\n}\n\nexport function createTypeLiteral(typeName: string) {\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode(typeName)),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode(typeName)\n\t\t),\n\t];\n\treturn ts.factory.createTypeLiteralNode(members);\n}\n\n/**\n * create view constructor interface of Type `T`\n * \n * ```ts\n * interface ConstructorOfView<T> {\n * \tnew(): T;\n * \treadonly prototype: T;\n * }\n * ```\n */\nexport function createConstructorOfViewInterfaceDeclaration() {\n\tconst typeParameter = ts.factory.createTypeParameterDeclaration(undefined, 'T');\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode('T')),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode('T')\n\t\t),\n\t];\n\treturn ts.factory.createInterfaceDeclaration(undefined, 'ConstructorOfView', [typeParameter], undefined, members);\n}\n\nexport function createStaticPropertyViewType(typeName: string) {\n\tconst typeArgument = ts.factory.createTypeReferenceNode(typeName);\n\treturn ts.factory.createTypeReferenceNode('ConstructorOfView', [typeArgument]);\n}\n\n\nexport function generateStatements(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): ts.NodeArray<ts.Statement> {\n\treturn ts.createSourceFile('temp', sourceText, scriptTarget, false, scriptKind).statements;\n}\n\nexport function generateNode<T = ts.Node>(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): T {\n\treturn generateStatements(sourceText, scriptTarget, scriptKind)[0] as T;\n}\n\n/**\n * declare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'user-view': HTMLUserViewElement;\n\t}\n}\n */\n\nexport function updateGlobalHTMLElementTagNameMap(views: { tagName: string, viewName: string }[]): ts.NodeArray<ts.Statement> {\n\tconst sourceCode = `\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}\n\nexport function updateModuleTypeWithComponentView(classes: ClassInfo[]): ts.NodeArray<ts.Statement> {\n\tconst viewClassDeclarations = classes.map(c => {\n\t\tconst inputs = c.inputs.map(input => input.aliasName);\n\t\tconst outputs = c.outputs.map(input => input.aliasName).map(output => 'on' + ToCamelCase(output));\n\t\tconst attributes = [...inputs, ...outputs].map(s => `'${s}'`).join(' | ');\n\t\tconst interfaceBody = `\n\t\t\tpublic static observedAttributes: [${attributes}];\n\n\t\t\t${c.inputs.map(input => `public ${input.aliasName}${input.type ? `: ${input.type}` : ''};`).join('\\n')}\n\n\t\t\t${c.outputs.map(output => `public on${ToCamelCase(output.aliasName)}${output.type ? `: ${output.type}` : ''};`).join('\\n')}\n\t\t\t\n\t\t`;\n\t\t// need to fix @FormValue type;\n\t\treturn c.views.map(view => `\n\t\t\tdeclare class ${view.viewName} extends ${view.extendsType} {\n\t\t\t\t${interfaceBody.trim()}\n\t\t\t}\n\t\t\tdeclare interface ${view.viewName} extends ${view.formAssociated ? `BaseFormAssociatedComponent<${c.name}>, ` : ''}BaseComponent<${c.name}> {}\n\t\t`);\n\t});\n\tconst views = classes.flatMap(c => c.views.map(v => ({ tagName: v.selector, viewName: v.viewName })));\n\tconst sourceCode = `\n\t\timport { BaseComponent, BaseFormAssociatedComponent, ConstructorOfView } from '@ibyar/core';\n\t\t${viewClassDeclarations.join('\\n')}\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}\n\n/**\n * create new type with name `ɵɵ0Directives0ɵɵ`\n * \n * example:\n * ```ts\n * export type ɵɵ0IfDirective0ɵɵ = {\n * \tselector: '*if';\n * \tsuccessor: '*else',\n * \tinputs: [\n * \t\t{ name: 'ifCondition', aliasName: 'if' },\n * \t\t{ name: 'thenTemplateRef', aliasName: 'then' },\n * \t\t{ name: 'elseTemplateRef', aliasName: 'else' },\n * \t],\n * \toutputs: [],\n * };\n * ```\n * @param classes directive class information\n * @returns new array of statements\n */\nexport function updateModuleTypeWithDirectives(classes: ClassInfo[]): ts.NodeArray<ts.Statement> {\n\tconst nodes: string[] | undefined = classes.map(directive => {\n\t\tconst inputs: string[] = directive.inputs.map(input => `{name: '${input.name}', aliasName: '${input.aliasName}'}`);\n\t\tconst outputs: string[] = directive.outputs.map(output => `{name: '${output.name}', aliasName: '${output.aliasName}'}`);\n\t\tconst temp: string[] = [`selector: '${directive.name}'`];\n\t\tif (directive.successor) {\n\t\t\ttemp.push(`successor: '${directive.successor}'`);\n\t\t}\n\t\tif (directive.inputs.length > 0) {\n\t\t\ttemp.push(`inputs: [${inputs.join(',')}]`);\n\t\t}\n\t\tif (directive.outputs.length > 0) {\n\t\t\ttemp.push(`outputs: [${outputs.join(',')}]`);\n\t\t}\n\t\tlet directiveTypeName = directive.name.startsWith('*')\n\t\t\t? directive.name.substring(1)\n\t\t\t: directive.name;\n\t\tdirectiveTypeName = directiveTypeName.replaceAll('-', ' ')\n\t\t\t.split(' ')\n\t\t\t.map(str => str.charAt(0).toUpperCase() + str.substring(1))\n\t\t\t.join('');\n\t\treturn `export type ɵɵ0${ToCamelCase(directiveTypeName)}Directive0ɵɵ = {${temp.join(',')}};`;\n\t});\n\treturn generateStatements(nodes.join());\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/modules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAExD,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,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AAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAG3D,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,CAAiB;IAE7C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,GAAG,CAAiC;IAE5C,GAAG,CAAC,IAAI,EAAE,UAAU;IAGpB,KAAK,IAAI,IAAI;IAGb,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAG5B,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAGhH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAGxC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAGzB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAIzC,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAGjD,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAGhC,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC;CAGtC;AAED,eAAO,MAAM,YAAY,cAAqB,CAAC"}
@@ -8,12 +8,6 @@ class ModuleManger {
8
8
  }
9
9
  map = new Map();
10
10
  add(info) {
11
- if (info.classes?.length) {
12
- const old = this.map.get(info.path);
13
- if (old) {
14
- info.classes = info.classes.concat(old.classes ?? []);
15
- }
16
- }
17
11
  this.map.set(info.path, info);
18
12
  }
19
13
  clear() {
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../../../src/cli/transformer/modules.ts"],"names":[],"mappings":"AAuBA,MAAM,YAAY;IACjB,CAAC,MAAM,CAAC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iB;QACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,MAAM;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC","sourcesContent":["import type ts from 'typescript/lib/tsserverlibrary.js';\n\nexport type ViewInfo = {\n\tselector: string;\n\textendsType: string;\n\tviewName: string;\n\tinterFaceType: ts.InterfaceDeclaration;\n\tformAssociated: boolean;\n};\n\nexport type DecoratorInfo = { name: string, aliasName: string, type?: string };\n\nexport type ClassInfo = {\n\ttype: 'component' | 'directive';\n\tname: string,\n\tsuccessor?: string;\n\tviews: ViewInfo[];\n\tinputs: DecoratorInfo[];\n\toutputs: DecoratorInfo[];\n};\n\nexport type ModuleInfo = { path: string; classes?: ClassInfo[]; }\n\nclass ModuleManger implements Map<string, ModuleInfo> {\n\t[Symbol.iterator](): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map[Symbol.iterator]();\n\t}\n\t[Symbol.toStringTag]: string = 'Module Info';\n\n\tget size(): number {\n\t\treturn this.map.size;\n\t}\n\n\tprivate map = new Map<string, ModuleInfo>();\n\n\tadd(info: ModuleInfo) {\n\t\tif (info.classes?.length) {\n\t\t\tconst old = this.map.get(info.path);\n\t\t\tif (old) {\n\t\t\t\tinfo.classes = info.classes.concat(old.classes ?? []);\n\t\t\t}\n\t\t}\n\t\tthis.map.set(info.path, info);\n\t}\n\tclear(): void {\n\t\tthis.map.clear();\n\t}\n\tdelete(key: string): boolean {\n\t\treturn this.map.delete(key);\n\t}\n\tforEach(callbackfn: (value: ModuleInfo, key: string, map: Map<string, ModuleInfo>) => void, thisArg?: any): void {\n\t\tthis.map.forEach(callbackfn, thisArg);\n\t}\n\tget(key: string): ModuleInfo | undefined {\n\t\treturn this.map.get(key);\n\t}\n\thas(key: string): boolean {\n\t\treturn this.map.has(key);\n\t}\n\tset(key: string, value: ModuleInfo): this {\n\t\tthis.map.set(key, value);\n\t\treturn this;\n\t}\n\tentries(): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map.entries();\n\t}\n\tkeys(): IterableIterator<string> {\n\t\treturn this.map.keys();\n\t}\n\tvalues(): IterableIterator<ModuleInfo> {\n\t\treturn this.map.values();\n\t}\n}\n\nexport const moduleManger = new ModuleManger();\n"]}
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../../../src/cli/transformer/modules.ts"],"names":[],"mappings":"AAuBA,MAAM,YAAY;IACjB,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACpC,CAAC;IACD,CAAC,MAAM,CAAC,WAAW,CAAC,GAAW,aAAa,CAAC;IAE7C,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACtB,CAAC;IAEO,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE5C,GAAG,CAAC,IAAgB;QACnB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IACD,KAAK;QACJ,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IACD,MAAM,CAAC,GAAW;QACjB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,UAAkF,EAAE,OAAa;QACxG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,KAAiB;QACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,MAAM;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC","sourcesContent":["import type ts from 'typescript/lib/tsserverlibrary.js';\n\nexport type ViewInfo = {\n\tselector: string;\n\textendsType: string;\n\tviewName: string;\n\tinterFaceType: ts.InterfaceDeclaration;\n\tformAssociated: boolean;\n};\n\nexport type DecoratorInfo = { name: string, aliasName: string, type?: string };\n\nexport type ClassInfo = {\n\ttype: 'component' | 'directive';\n\tname: string,\n\tsuccessor?: string;\n\tviews: ViewInfo[];\n\tinputs: DecoratorInfo[];\n\toutputs: DecoratorInfo[];\n};\n\nexport type ModuleInfo = { path: string; classes?: ClassInfo[]; }\n\nclass ModuleManger implements Map<string, ModuleInfo> {\n\t[Symbol.iterator](): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map[Symbol.iterator]();\n\t}\n\t[Symbol.toStringTag]: string = 'Module Info';\n\n\tget size(): number {\n\t\treturn this.map.size;\n\t}\n\n\tprivate map = new Map<string, ModuleInfo>();\n\n\tadd(info: ModuleInfo) {\n\t\tthis.map.set(info.path, info);\n\t}\n\tclear(): void {\n\t\tthis.map.clear();\n\t}\n\tdelete(key: string): boolean {\n\t\treturn this.map.delete(key);\n\t}\n\tforEach(callbackfn: (value: ModuleInfo, key: string, map: Map<string, ModuleInfo>) => void, thisArg?: any): void {\n\t\tthis.map.forEach(callbackfn, thisArg);\n\t}\n\tget(key: string): ModuleInfo | undefined {\n\t\treturn this.map.get(key);\n\t}\n\thas(key: string): boolean {\n\t\treturn this.map.has(key);\n\t}\n\tset(key: string, value: ModuleInfo): this {\n\t\tthis.map.set(key, value);\n\t\treturn this;\n\t}\n\tentries(): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map.entries();\n\t}\n\tkeys(): IterableIterator<string> {\n\t\treturn this.map.keys();\n\t}\n\tvalues(): IterableIterator<ModuleInfo> {\n\t\treturn this.map.values();\n\t}\n}\n\nexport const moduleManger = new ModuleManger();\n"]}
@@ -0,0 +1,7 @@
1
+ import type * as webpack from 'webpack';
2
+ /**
3
+ * The entry point for ts-loader
4
+ */
5
+ export declare function initTypeScript(): void;
6
+ export declare function loader(this: webpack.LoaderContext<{}>, contents: string, inputSourceMap?: Record<string, any>): void;
7
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/cli/webpack/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AASxC;;GAEG;AAEH,wBAAgB,cAAc,SAY7B;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAoB7G"}
@@ -0,0 +1,47 @@
1
+ import { normalize } from 'path';
2
+ import ts from 'typescript/lib/tsserverlibrary.js';
3
+ import { getConfigPath, getTransformers, scanDirective } from '../compiler/compiler.js';
4
+ let host;
5
+ let program;
6
+ let orgWriteFile;
7
+ let transformers;
8
+ /**
9
+ * The entry point for ts-loader
10
+ */
11
+ export function initTypeScript() {
12
+ const configPath = getConfigPath();
13
+ const cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys);
14
+ if (!cmd) {
15
+ console.log(`can't parse command line `);
16
+ throw new Error('');
17
+ }
18
+ host = ts.createCompilerHost(cmd.options);
19
+ orgWriteFile = host.writeFile;
20
+ program = ts.createProgram(cmd.fileNames, cmd.options, host);
21
+ transformers = getTransformers(program);
22
+ scanDirective(program);
23
+ }
24
+ export function loader(contents, inputSourceMap) {
25
+ if (!program) {
26
+ try {
27
+ initTypeScript();
28
+ }
29
+ catch (e) {
30
+ this.callback(e);
31
+ }
32
+ }
33
+ let content, sourceMap;
34
+ host.writeFile = (fileName, contents) => {
35
+ if (fileName.endsWith('.map')) {
36
+ sourceMap = contents;
37
+ }
38
+ else if (fileName.endsWith('.js')) {
39
+ content = contents;
40
+ }
41
+ };
42
+ const filePath = normalize(this.resourcePath);
43
+ program.emit(program.getSourceFile(filePath), undefined, undefined, undefined, transformers);
44
+ this.callback(null, content, sourceMap);
45
+ host.writeFile = orgWriteFile;
46
+ }
47
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/cli/webpack/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExF,IAAI,IAAqB,CAAC;AAC1B,IAAI,OAAmB,CAAC;AACxB,IAAI,YAAkC,CAAC;AACvC,IAAI,YAAmC,CAAC;AAExC;;GAEG;AAEH,MAAM,UAAU,cAAc;IAC7B,MAAM,UAAU,GAAG,aAAa,EAAE,C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C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IAC7F,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC;AAC/B,CAAC","sourcesContent":["import { normalize } from 'path';\nimport type * as webpack from 'webpack';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { getConfigPath, getTransformers, scanDirective } from '../compiler/compiler.js';\n\nlet host: ts.CompilerHost;\nlet program: ts.Program;\nlet orgWriteFile: ts.WriteFileCallback;\nlet transformers: ts.CustomTransformers;\n\n/**\n * The entry point for ts-loader\n */\n\nexport function initTypeScript() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\tconsole.log(`can't parse command line `);\n\t\tthrow new Error('');\n\t}\n\thost = ts.createCompilerHost(cmd.options);\n\torgWriteFile = host.writeFile;\n\tprogram = ts.createProgram(cmd.fileNames, cmd.options, host);\n\ttransformers = getTransformers(program);\n\tscanDirective(program);\n}\n\nexport function loader(this: webpack.LoaderContext<{}>, contents: string, inputSourceMap?: Record<string, any>) {\n\tif (!program) {\n\t\ttry {\n\t\t\tinitTypeScript();\n\t\t} catch (e) {\n\t\t\tthis.callback(e as Error);\n\t\t}\n\t}\n\tlet content: string | undefined, sourceMap: string | undefined;\n\thost.writeFile = (fileName: string, contents: string) => {\n\t\tif (fileName.endsWith('.map')) {\n\t\t\tsourceMap = contents;\n\t\t} else if (fileName.endsWith('.js')) {\n\t\t\tcontent = contents;\n\t\t}\n\t};\n\tconst filePath = normalize(this.resourcePath);\n\tprogram.emit(program.getSourceFile(filePath), undefined, undefined, undefined, transformers);\n\tthis.callback(null, content, sourceMap);\n\thost.writeFile = orgWriteFile;\n}\n"]}