@baseplate-dev/core-generators 0.1.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.
- package/LICENSE +390 -0
- package/dist/constants/core-packages.d.ts +21 -0
- package/dist/constants/core-packages.d.ts.map +1 -0
- package/dist/constants/core-packages.js +26 -0
- package/dist/constants/core-packages.js.map +1 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +2 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/node.d.ts +3 -0
- package/dist/constants/node.d.ts.map +1 -0
- package/dist/constants/node.js +3 -0
- package/dist/constants/node.js.map +1 -0
- package/dist/generators/docker/docker-compose/docker-compose.generator.d.ts +17 -0
- package/dist/generators/docker/docker-compose/docker-compose.generator.d.ts.map +1 -0
- package/dist/generators/docker/docker-compose/docker-compose.generator.js +83 -0
- package/dist/generators/docker/docker-compose/docker-compose.generator.js.map +1 -0
- package/dist/generators/docker/docker-compose/postgres.d.ts +8 -0
- package/dist/generators/docker/docker-compose/postgres.d.ts.map +1 -0
- package/dist/generators/docker/docker-compose/postgres.js +22 -0
- package/dist/generators/docker/docker-compose/postgres.js.map +1 -0
- package/dist/generators/docker/docker-compose/redis.d.ts +8 -0
- package/dist/generators/docker/docker-compose/redis.d.ts.map +1 -0
- package/dist/generators/docker/docker-compose/redis.js +21 -0
- package/dist/generators/docker/docker-compose/redis.js.map +1 -0
- package/dist/generators/docker/docker-compose/types.d.ts +5 -0
- package/dist/generators/docker/docker-compose/types.d.ts.map +1 -0
- package/dist/generators/docker/docker-compose/types.js +2 -0
- package/dist/generators/docker/docker-compose/types.js.map +1 -0
- package/dist/generators/docker/index.d.ts +2 -0
- package/dist/generators/docker/index.d.ts.map +1 -0
- package/dist/generators/docker/index.js +2 -0
- package/dist/generators/docker/index.js.map +1 -0
- package/dist/generators/index.d.ts +3 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +3 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/node/_composers/index.d.ts +2 -0
- package/dist/generators/node/_composers/index.d.ts.map +1 -0
- package/dist/generators/node/_composers/index.js +2 -0
- package/dist/generators/node/_composers/index.js.map +1 -0
- package/dist/generators/node/_composers/node.d.ts +4 -0
- package/dist/generators/node/_composers/node.d.ts.map +1 -0
- package/dist/generators/node/_composers/node.js +18 -0
- package/dist/generators/node/_composers/node.js.map +1 -0
- package/dist/generators/node/eslint/eslint.generator.d.ts +33 -0
- package/dist/generators/node/eslint/eslint.generator.d.ts.map +1 -0
- package/dist/generators/node/eslint/eslint.generator.js +110 -0
- package/dist/generators/node/eslint/eslint.generator.js.map +1 -0
- package/dist/generators/node/eslint/generated/ts-templates.d.ts +9 -0
- package/dist/generators/node/eslint/generated/ts-templates.d.ts.map +1 -0
- package/dist/generators/node/eslint/generated/ts-templates.js +14 -0
- package/dist/generators/node/eslint/generated/ts-templates.js.map +1 -0
- package/dist/generators/node/eslint/react-rules.d.ts +2 -0
- package/dist/generators/node/eslint/react-rules.d.ts.map +1 -0
- package/dist/generators/node/eslint/react-rules.js +59 -0
- package/dist/generators/node/eslint/react-rules.js.map +1 -0
- package/dist/generators/node/eslint/templates/eslint.config.js +219 -0
- package/dist/generators/node/eslint/vitest-rules.d.ts +2 -0
- package/dist/generators/node/eslint/vitest-rules.d.ts.map +1 -0
- package/dist/generators/node/eslint/vitest-rules.js +17 -0
- package/dist/generators/node/eslint/vitest-rules.js.map +1 -0
- package/dist/generators/node/index.d.ts +9 -0
- package/dist/generators/node/index.d.ts.map +1 -0
- package/dist/generators/node/index.js +9 -0
- package/dist/generators/node/index.js.map +1 -0
- package/dist/generators/node/node/node.generator.d.ts +72 -0
- package/dist/generators/node/node/node.generator.d.ts.map +1 -0
- package/dist/generators/node/node/node.generator.js +149 -0
- package/dist/generators/node/node/node.generator.js.map +1 -0
- package/dist/generators/node/node/package-dependencies-container.d.ts +41 -0
- package/dist/generators/node/node/package-dependencies-container.d.ts.map +1 -0
- package/dist/generators/node/node/package-dependencies-container.js +104 -0
- package/dist/generators/node/node/package-dependencies-container.js.map +1 -0
- package/dist/generators/node/node-git-ignore/node-git-ignore.generator.d.ts +15 -0
- package/dist/generators/node/node-git-ignore/node-git-ignore.generator.d.ts.map +1 -0
- package/dist/generators/node/node-git-ignore/node-git-ignore.generator.js +75 -0
- package/dist/generators/node/node-git-ignore/node-git-ignore.generator.js.map +1 -0
- package/dist/generators/node/prettier/prettier.generator.d.ts +33 -0
- package/dist/generators/node/prettier/prettier.generator.d.ts.map +1 -0
- package/dist/generators/node/prettier/prettier.generator.js +191 -0
- package/dist/generators/node/prettier/prettier.generator.js.map +1 -0
- package/dist/generators/node/ts-utils/generated/ts-import-maps.d.ts +21 -0
- package/dist/generators/node/ts-utils/generated/ts-import-maps.d.ts.map +1 -0
- package/dist/generators/node/ts-utils/generated/ts-import-maps.js +22 -0
- package/dist/generators/node/ts-utils/generated/ts-import-maps.js.map +1 -0
- package/dist/generators/node/ts-utils/generated/ts-templates.d.ts +7 -0
- package/dist/generators/node/ts-utils/generated/ts-templates.d.ts.map +1 -0
- package/dist/generators/node/ts-utils/generated/ts-templates.js +32 -0
- package/dist/generators/node/ts-utils/generated/ts-templates.js.map +1 -0
- package/dist/generators/node/ts-utils/templates/arrays.ts +13 -0
- package/dist/generators/node/ts-utils/templates/normalize-types.ts +12 -0
- package/dist/generators/node/ts-utils/templates/nulls.ts +33 -0
- package/dist/generators/node/ts-utils/templates/string.ts +11 -0
- package/dist/generators/node/ts-utils/ts-utils.generator.d.ts +17 -0
- package/dist/generators/node/ts-utils/ts-utils.generator.d.ts.map +1 -0
- package/dist/generators/node/ts-utils/ts-utils.generator.js +48 -0
- package/dist/generators/node/ts-utils/ts-utils.generator.js.map +1 -0
- package/dist/generators/node/typescript/compiler-types.d.ts +178 -0
- package/dist/generators/node/typescript/compiler-types.d.ts.map +1 -0
- package/dist/generators/node/typescript/compiler-types.js +70 -0
- package/dist/generators/node/typescript/compiler-types.js.map +1 -0
- package/dist/generators/node/typescript/typescript.generator.d.ts +117 -0
- package/dist/generators/node/typescript/typescript.generator.d.ts.map +1 -0
- package/dist/generators/node/typescript/typescript.generator.js +198 -0
- package/dist/generators/node/typescript/typescript.generator.js.map +1 -0
- package/dist/generators/node/vitest/generated/ts-templates.d.ts +9 -0
- package/dist/generators/node/vitest/generated/ts-templates.d.ts.map +1 -0
- package/dist/generators/node/vitest/generated/ts-templates.js +15 -0
- package/dist/generators/node/vitest/generated/ts-templates.js.map +1 -0
- package/dist/generators/node/vitest/templates/global-setup.ts +5 -0
- package/dist/generators/node/vitest/templates/vitest.config.ts +5 -0
- package/dist/generators/node/vitest/vitest.generator.d.ts +26 -0
- package/dist/generators/node/vitest/vitest.generator.d.ts.map +1 -0
- package/dist/generators/node/vitest/vitest.generator.js +93 -0
- package/dist/generators/node/vitest/vitest.generator.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/project.d.ts +5 -0
- package/dist/providers/project.d.ts.map +1 -0
- package/dist/providers/project.js +3 -0
- package/dist/providers/project.js.map +1 -0
- package/dist/providers/scopes.d.ts +3 -0
- package/dist/providers/scopes.d.ts.map +1 -0
- package/dist/providers/scopes.js +4 -0
- package/dist/providers/scopes.js.map +1 -0
- package/dist/renderers/index.d.ts +2 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +2 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/typescript/actions/index.d.ts +4 -0
- package/dist/renderers/typescript/actions/index.d.ts.map +1 -0
- package/dist/renderers/typescript/actions/index.js +4 -0
- package/dist/renderers/typescript/actions/index.js.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-fragment-action.d.ts +12 -0
- package/dist/renderers/typescript/actions/render-ts-fragment-action.d.ts.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-fragment-action.js +25 -0
- package/dist/renderers/typescript/actions/render-ts-fragment-action.js.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-template-file-action.d.ts +32 -0
- package/dist/renderers/typescript/actions/render-ts-template-file-action.d.ts.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-template-file-action.js +65 -0
- package/dist/renderers/typescript/actions/render-ts-template-file-action.js.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-template-group-action.d.ts +58 -0
- package/dist/renderers/typescript/actions/render-ts-template-group-action.d.ts.map +1 -0
- package/dist/renderers/typescript/actions/render-ts-template-group-action.js +69 -0
- package/dist/renderers/typescript/actions/render-ts-template-group-action.js.map +1 -0
- package/dist/renderers/typescript/extractor/extract-ts-template-variables.d.ts +18 -0
- package/dist/renderers/typescript/extractor/extract-ts-template-variables.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/extract-ts-template-variables.js +38 -0
- package/dist/renderers/typescript/extractor/extract-ts-template-variables.js.map +1 -0
- package/dist/renderers/typescript/extractor/index.d.ts +2 -0
- package/dist/renderers/typescript/extractor/index.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/index.js +2 -0
- package/dist/renderers/typescript/extractor/index.js.map +1 -0
- package/dist/renderers/typescript/extractor/organize-ts-template-imports.d.ts +26 -0
- package/dist/renderers/typescript/extractor/organize-ts-template-imports.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/organize-ts-template-imports.js +175 -0
- package/dist/renderers/typescript/extractor/organize-ts-template-imports.js.map +1 -0
- package/dist/renderers/typescript/extractor/preprocess-code-for-extraction-hack.d.ts +17 -0
- package/dist/renderers/typescript/extractor/preprocess-code-for-extraction-hack.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/preprocess-code-for-extraction-hack.js +46 -0
- package/dist/renderers/typescript/extractor/preprocess-code-for-extraction-hack.js.map +1 -0
- package/dist/renderers/typescript/extractor/templates/imports-file.d.ts +2 -0
- package/dist/renderers/typescript/extractor/templates/imports-file.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/templates/imports-file.js +35 -0
- package/dist/renderers/typescript/extractor/templates/imports-file.js.map +1 -0
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.d.ts +167 -0
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.js +279 -0
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.js.map +1 -0
- package/dist/renderers/typescript/extractor/write-ts-project-exports.d.ts +96 -0
- package/dist/renderers/typescript/extractor/write-ts-project-exports.d.ts.map +1 -0
- package/dist/renderers/typescript/extractor/write-ts-project-exports.js +139 -0
- package/dist/renderers/typescript/extractor/write-ts-project-exports.js.map +1 -0
- package/dist/renderers/typescript/fragments/creators.d.ts +29 -0
- package/dist/renderers/typescript/fragments/creators.d.ts.map +1 -0
- package/dist/renderers/typescript/fragments/creators.js +53 -0
- package/dist/renderers/typescript/fragments/creators.js.map +1 -0
- package/dist/renderers/typescript/fragments/index.d.ts +4 -0
- package/dist/renderers/typescript/fragments/index.d.ts.map +1 -0
- package/dist/renderers/typescript/fragments/index.js +3 -0
- package/dist/renderers/typescript/fragments/index.js.map +1 -0
- package/dist/renderers/typescript/fragments/types.d.ts +65 -0
- package/dist/renderers/typescript/fragments/types.d.ts.map +1 -0
- package/dist/renderers/typescript/fragments/types.js +2 -0
- package/dist/renderers/typescript/fragments/types.js.map +1 -0
- package/dist/renderers/typescript/fragments/utils.d.ts +51 -0
- package/dist/renderers/typescript/fragments/utils.d.ts.map +1 -0
- package/dist/renderers/typescript/fragments/utils.js +134 -0
- package/dist/renderers/typescript/fragments/utils.js.map +1 -0
- package/dist/renderers/typescript/import-maps/index.d.ts +4 -0
- package/dist/renderers/typescript/import-maps/index.d.ts.map +1 -0
- package/dist/renderers/typescript/import-maps/index.js +3 -0
- package/dist/renderers/typescript/import-maps/index.js.map +1 -0
- package/dist/renderers/typescript/import-maps/transform-ts-imports-with-map.d.ts +19 -0
- package/dist/renderers/typescript/import-maps/transform-ts-imports-with-map.d.ts.map +1 -0
- package/dist/renderers/typescript/import-maps/transform-ts-imports-with-map.js +54 -0
- package/dist/renderers/typescript/import-maps/transform-ts-imports-with-map.js.map +1 -0
- package/dist/renderers/typescript/import-maps/ts-import-map.d.ts +10 -0
- package/dist/renderers/typescript/import-maps/ts-import-map.d.ts.map +1 -0
- package/dist/renderers/typescript/import-maps/ts-import-map.js +39 -0
- package/dist/renderers/typescript/import-maps/ts-import-map.js.map +1 -0
- package/dist/renderers/typescript/import-maps/types.d.ts +28 -0
- package/dist/renderers/typescript/import-maps/types.d.ts.map +1 -0
- package/dist/renderers/typescript/import-maps/types.js +2 -0
- package/dist/renderers/typescript/import-maps/types.js.map +1 -0
- package/dist/renderers/typescript/imports/builder.d.ts +49 -0
- package/dist/renderers/typescript/imports/builder.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/builder.js +47 -0
- package/dist/renderers/typescript/imports/builder.js.map +1 -0
- package/dist/renderers/typescript/imports/index.d.ts +8 -0
- package/dist/renderers/typescript/imports/index.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/index.js +7 -0
- package/dist/renderers/typescript/imports/index.js.map +1 -0
- package/dist/renderers/typescript/imports/merge-ts-import-declarations.d.ts +20 -0
- package/dist/renderers/typescript/imports/merge-ts-import-declarations.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/merge-ts-import-declarations.js +114 -0
- package/dist/renderers/typescript/imports/merge-ts-import-declarations.js.map +1 -0
- package/dist/renderers/typescript/imports/normalize-module-specifier.d.ts +40 -0
- package/dist/renderers/typescript/imports/normalize-module-specifier.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/normalize-module-specifier.js +133 -0
- package/dist/renderers/typescript/imports/normalize-module-specifier.js.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/get-import-sort-group.d.ts +31 -0
- package/dist/renderers/typescript/imports/sort-imports/get-import-sort-group.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/get-import-sort-group.js +169 -0
- package/dist/renderers/typescript/imports/sort-imports/get-import-sort-group.js.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/index.d.ts +2 -0
- package/dist/renderers/typescript/imports/sort-imports/index.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/index.js +2 -0
- package/dist/renderers/typescript/imports/sort-imports/index.js.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/sort-import-declarations.d.ts +32 -0
- package/dist/renderers/typescript/imports/sort-imports/sort-import-declarations.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/sort-imports/sort-import-declarations.js +72 -0
- package/dist/renderers/typescript/imports/sort-imports/sort-import-declarations.js.map +1 -0
- package/dist/renderers/typescript/imports/ts-morph-operations.d.ts +42 -0
- package/dist/renderers/typescript/imports/ts-morph-operations.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/ts-morph-operations.js +145 -0
- package/dist/renderers/typescript/imports/ts-morph-operations.js.map +1 -0
- package/dist/renderers/typescript/imports/ts-path-maps.d.ts +18 -0
- package/dist/renderers/typescript/imports/ts-path-maps.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/ts-path-maps.js +39 -0
- package/dist/renderers/typescript/imports/ts-path-maps.js.map +1 -0
- package/dist/renderers/typescript/imports/types.d.ts +73 -0
- package/dist/renderers/typescript/imports/types.d.ts.map +1 -0
- package/dist/renderers/typescript/imports/types.js +2 -0
- package/dist/renderers/typescript/imports/types.js.map +1 -0
- package/dist/renderers/typescript/index.d.ts +9 -0
- package/dist/renderers/typescript/index.d.ts.map +1 -0
- package/dist/renderers/typescript/index.js +9 -0
- package/dist/renderers/typescript/index.js.map +1 -0
- package/dist/renderers/typescript/renderers/file.d.ts +18 -0
- package/dist/renderers/typescript/renderers/file.d.ts.map +1 -0
- package/dist/renderers/typescript/renderers/file.js +91 -0
- package/dist/renderers/typescript/renderers/file.js.map +1 -0
- package/dist/renderers/typescript/renderers/index.d.ts +3 -0
- package/dist/renderers/typescript/renderers/index.d.ts.map +1 -0
- package/dist/renderers/typescript/renderers/index.js +3 -0
- package/dist/renderers/typescript/renderers/index.js.map +1 -0
- package/dist/renderers/typescript/renderers/template.d.ts +21 -0
- package/dist/renderers/typescript/renderers/template.d.ts.map +1 -0
- package/dist/renderers/typescript/renderers/template.js +132 -0
- package/dist/renderers/typescript/renderers/template.js.map +1 -0
- package/dist/renderers/typescript/templates/creators.d.ts +10 -0
- package/dist/renderers/typescript/templates/creators.d.ts.map +1 -0
- package/dist/renderers/typescript/templates/creators.js +9 -0
- package/dist/renderers/typescript/templates/creators.js.map +1 -0
- package/dist/renderers/typescript/templates/index.d.ts +3 -0
- package/dist/renderers/typescript/templates/index.d.ts.map +1 -0
- package/dist/renderers/typescript/templates/index.js +3 -0
- package/dist/renderers/typescript/templates/index.js.map +1 -0
- package/dist/renderers/typescript/templates/types.d.ts +119 -0
- package/dist/renderers/typescript/templates/types.d.ts.map +1 -0
- package/dist/renderers/typescript/templates/types.js +43 -0
- package/dist/renderers/typescript/templates/types.js.map +1 -0
- package/dist/renderers/typescript/utils/index.d.ts +2 -0
- package/dist/renderers/typescript/utils/index.d.ts.map +1 -0
- package/dist/renderers/typescript/utils/index.js +2 -0
- package/dist/renderers/typescript/utils/index.js.map +1 -0
- package/dist/renderers/typescript/utils/ts-code-utils.d.ts +200 -0
- package/dist/renderers/typescript/utils/ts-code-utils.d.ts.map +1 -0
- package/dist/renderers/typescript/utils/ts-code-utils.js +431 -0
- package/dist/renderers/typescript/utils/ts-code-utils.js.map +1 -0
- package/dist/utils/extract-packages.d.ts +8 -0
- package/dist/utils/extract-packages.d.ts.map +1 -0
- package/dist/utils/extract-packages.js +10 -0
- package/dist/utils/extract-packages.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/writers/index.d.ts +2 -0
- package/dist/writers/index.d.ts.map +1 -0
- package/dist/writers/index.js +2 -0
- package/dist/writers/index.js.map +1 -0
- package/dist/writers/json.d.ts +21 -0
- package/dist/writers/json.d.ts.map +1 -0
- package/dist/writers/json.js +14 -0
- package/dist/writers/json.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { flattenImportsAndHoistedFragments } from '../fragments/utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Escapes the replacement string to avoid conflicts with special replacement patterns.
|
|
4
|
+
*
|
|
5
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement.
|
|
6
|
+
*
|
|
7
|
+
* @param replacement - The replacement string to escape.
|
|
8
|
+
* @returns The escaped replacement string.
|
|
9
|
+
*/
|
|
10
|
+
function escapeReplacement(replacement) {
|
|
11
|
+
return replacement.replaceAll('$', '$$$$');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render a template to a code fragment.
|
|
15
|
+
* @param template - The template to render.
|
|
16
|
+
* @param variables - The variables to render the template with.
|
|
17
|
+
* @param options - The options for the render.
|
|
18
|
+
* @returns The rendered code fragment.
|
|
19
|
+
*/
|
|
20
|
+
export function renderTsTemplateToTsCodeFragment(template, variables, options = {}) {
|
|
21
|
+
// strip any ts-nocheck from header
|
|
22
|
+
let renderedTemplate = template.replace(/^\/\/ @ts-nocheck\n/m, '');
|
|
23
|
+
// Replace variables with their values
|
|
24
|
+
const prefix = options.prefix ?? 'TPL_';
|
|
25
|
+
const includeMetadata = options.includeMetadata ?? false;
|
|
26
|
+
if (Object.keys(variables).some((key) => !/^[A-Z0-9_]+$/.test(key) || !key.startsWith(prefix))) {
|
|
27
|
+
throw new Error(`Template variable keys must be uppercase alphanumeric and start with the prefix ${prefix}`);
|
|
28
|
+
}
|
|
29
|
+
const variableKeys = new Set(Object.keys(variables));
|
|
30
|
+
const blockMarkers = new Map();
|
|
31
|
+
const inlineMarkers = new Map();
|
|
32
|
+
const tsxMarkers = new Map();
|
|
33
|
+
const commentMarkers = new Map();
|
|
34
|
+
// --- Pass 1: Replace block placeholders with unique markers ---
|
|
35
|
+
const blockRegex = new RegExp(`^([ \\t]*)(${prefix}[A-Z0-9_]+);$`, 'gm');
|
|
36
|
+
renderedTemplate = renderedTemplate.replace(blockRegex, (match, leading, key) => {
|
|
37
|
+
if (!(key in variables)) {
|
|
38
|
+
throw new Error(`Template variable not found: ${key}`);
|
|
39
|
+
}
|
|
40
|
+
const marker = `__BLOCK_MARKER_${blockMarkers.size}__`; // Unique marker
|
|
41
|
+
blockMarkers.set(marker, { key, leading, value: variables[key] });
|
|
42
|
+
variableKeys.delete(key); // Mark as used
|
|
43
|
+
return `${leading}${marker}`; // Replace with marker, preserving leading whitespace
|
|
44
|
+
});
|
|
45
|
+
// --- Pass 2: Replace TSX placeholders with unique markers ---
|
|
46
|
+
const tsxRegex = new RegExp(`<(${prefix}[A-Z0-9_]+) />`, 'g');
|
|
47
|
+
renderedTemplate = renderedTemplate.replace(tsxRegex, (match, key) => {
|
|
48
|
+
if (!(key in variables)) {
|
|
49
|
+
throw new Error(`Template variable not found: ${key}`);
|
|
50
|
+
}
|
|
51
|
+
const marker = `__TSX_MARKER_${tsxMarkers.size}__`; // Unique marker
|
|
52
|
+
tsxMarkers.set(marker, { key, value: variables[key] });
|
|
53
|
+
variableKeys.delete(key); // Mark as used
|
|
54
|
+
return marker; // Replace with marker, preserving leading whitespace
|
|
55
|
+
});
|
|
56
|
+
// --- Pass 3: Replace comment placeholders with unique markers ---
|
|
57
|
+
const commentRegex = new RegExp(`\\/\\* (${prefix}[A-Z0-9_]+) \\*\\/`, 'g');
|
|
58
|
+
renderedTemplate = renderedTemplate.replace(commentRegex, (match, key) => {
|
|
59
|
+
if (!(key in variables)) {
|
|
60
|
+
throw new Error(`Template variable not found: ${key}`);
|
|
61
|
+
}
|
|
62
|
+
const marker = `__COMMENT_MARKER_${commentMarkers.size}__`; // Unique marker
|
|
63
|
+
commentMarkers.set(marker, { key, value: variables[key] });
|
|
64
|
+
variableKeys.delete(key); // Mark as used
|
|
65
|
+
return marker; // Replace with marker
|
|
66
|
+
});
|
|
67
|
+
// --- Pass 4: Replace inline placeholders with unique markers ---
|
|
68
|
+
// This regex ensures the TPL_ variable is not immediately followed by another valid variable character
|
|
69
|
+
const inlineRegex = new RegExp(`(${prefix}[A-Z0-9_]+)([^A-Z0-9_]|$)`, 'g');
|
|
70
|
+
renderedTemplate = renderedTemplate.replace(inlineRegex, (match, key, followingCharacter) => {
|
|
71
|
+
if (!(key in variables)) {
|
|
72
|
+
throw new Error(`Template variable not found: ${key}`);
|
|
73
|
+
}
|
|
74
|
+
// HACK: handle specific scenario where the variable is followed by a comma and the variable
|
|
75
|
+
// value itself is an empty string which would result in invalid syntax, e.g. { TEST, } => { , }
|
|
76
|
+
const value = variables[key];
|
|
77
|
+
const contents = typeof value === 'string' ? value : value.contents;
|
|
78
|
+
const shouldRemoveComma = followingCharacter === ',' && contents.trim() === '';
|
|
79
|
+
const marker = `__INLINE_MARKER_${inlineMarkers.size}__`; // Unique marker
|
|
80
|
+
inlineMarkers.set(marker, { key, value });
|
|
81
|
+
variableKeys.delete(key); // Mark as used
|
|
82
|
+
return `${marker}${shouldRemoveComma ? '' : followingCharacter}`; // Replace with marker
|
|
83
|
+
});
|
|
84
|
+
// --- Check for unused variables ---
|
|
85
|
+
if (variableKeys.size > 0) {
|
|
86
|
+
throw new Error(`Template variables were unused in template: ${[...variableKeys].join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
// --- Pass 5: Resolve markers ---
|
|
89
|
+
// Resolve block markers
|
|
90
|
+
for (const [marker, { key, leading, value }] of blockMarkers.entries()) {
|
|
91
|
+
const contents = typeof value === 'string' ? value : value.contents;
|
|
92
|
+
const replacement = includeMetadata
|
|
93
|
+
? `${leading}/* ${key}:START */\n${contents}\n${leading}/* ${key}:END */` // Preserve indentation for end comment too
|
|
94
|
+
: contents; // Note: leading whitespace is handled by the marker's position
|
|
95
|
+
// Use replace instead of replaceAll as markers are unique
|
|
96
|
+
renderedTemplate = renderedTemplate.replace(marker, escapeReplacement(replacement));
|
|
97
|
+
}
|
|
98
|
+
// Resolve TSX markers
|
|
99
|
+
for (const [marker, { key, value }] of tsxMarkers.entries()) {
|
|
100
|
+
const contents = typeof value === 'string' ? value : value.contents;
|
|
101
|
+
const replacement = includeMetadata
|
|
102
|
+
? `{/* ${key}:START */}\n${contents}\n{/* ${key}:END */}`
|
|
103
|
+
: contents;
|
|
104
|
+
// Use replace instead of replaceAll as markers are unique
|
|
105
|
+
renderedTemplate = renderedTemplate.replace(marker, escapeReplacement(replacement));
|
|
106
|
+
}
|
|
107
|
+
// Resolve comment markers
|
|
108
|
+
for (const [marker, { key, value }] of commentMarkers.entries()) {
|
|
109
|
+
const contents = typeof value === 'string' ? value : value.contents;
|
|
110
|
+
const replacement = includeMetadata
|
|
111
|
+
? `/* ${key}:COMMENT:START */\n${contents}\n/* ${key}:COMMENT:END */`
|
|
112
|
+
: contents;
|
|
113
|
+
// Use replace instead of replaceAll as markers are unique
|
|
114
|
+
renderedTemplate = renderedTemplate.replace(marker, escapeReplacement(replacement));
|
|
115
|
+
}
|
|
116
|
+
// Resolve inline markers
|
|
117
|
+
for (const [marker, { key, value }] of inlineMarkers.entries()) {
|
|
118
|
+
const contents = typeof value === 'string' ? value : value.contents;
|
|
119
|
+
const replacement = includeMetadata
|
|
120
|
+
? `/* ${key}:START */ ${contents.trim()} /* ${key}:END */`
|
|
121
|
+
: contents;
|
|
122
|
+
// Use replace instead of replaceAll as markers are unique
|
|
123
|
+
renderedTemplate = renderedTemplate.replace(marker, escapeReplacement(replacement));
|
|
124
|
+
}
|
|
125
|
+
const { imports, hoistedFragments } = flattenImportsAndHoistedFragments(Object.values(variables).filter((val) => typeof val !== 'string'));
|
|
126
|
+
return {
|
|
127
|
+
contents: renderedTemplate,
|
|
128
|
+
imports,
|
|
129
|
+
hoistedFragments,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/renderers/typescript/renderers/template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,MAAM,uBAAuB,CAAC;AAa1E;;;;;;;GAOG;AACH,SAAS,iBAAiB,CAAC,WAAmB;IAC5C,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC9C,QAAgB,EAChB,SAAsD,EACtD,UAAmC,EAAE;IAErC,mCAAmC;IACnC,IAAI,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;IACpE,sCAAsC;IACtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC;IACxC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;IACzD,IACE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CACzB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAC9D,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,mFAAmF,MAAM,EAAE,CAC5F,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,IAAI,GAAG,EAGzB,CAAC;IACJ,MAAM,aAAa,GAAG,IAAI,GAAG,EAG1B,CAAC;IACJ,MAAM,UAAU,GAAG,IAAI,GAAG,EAGvB,CAAC;IACJ,MAAM,cAAc,GAAG,IAAI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M,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;QACpE,MAAM,WAAW,GAAG,eAAe;YACjC,CAAC,CAAC,MAAM,GAAG,aAAa,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS;YAC1D,CAAC,CAAC,QAAQ,CAAC;QAEb,0DAA0D;QAC1D,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CACzC,MAAM,EACN,iBAAiB,CAAC,WAAW,CAAC,CAC/B,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,iCAAiC,CACrE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAClE,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,OAAO;QACP,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProviderType } from '@baseplate-dev/sync';
|
|
2
|
+
import { TsTemplateVariableMap } from './types.js';
|
|
3
|
+
import { TsTemplateFile } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a code file template.
|
|
6
|
+
* @param template - The template to create.
|
|
7
|
+
* @returns The created code file template.
|
|
8
|
+
*/
|
|
9
|
+
export declare function tsCodeFileTemplate<TVariables extends TsTemplateVariableMap, TImportProviders extends Record<string, ProviderType> = Record<never, ProviderType>>(template: TsTemplateFile<TVariables, TImportProviders>): TsTemplateFile<TVariables, TImportProviders>;
|
|
10
|
+
//# sourceMappingURL=creators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"creators.d.ts","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/creators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,SAAS,qBAAqB,EACxC,gBAAgB,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAC5D,KAAK,EACL,YAAY,CACb,EAED,QAAQ,EAAE,cAAc,CAAC,UAAU,EAAE,gBAAgB,CAAC,GACrD,cAAc,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAE9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"creators.js","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/creators.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAOhC,QAAsD;IAEtD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { InferProviderType, ProviderType, TemplateFileBase } from '@baseplate-dev/sync';
|
|
2
|
+
import { TsCodeFragment } from '../fragments/types.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export declare const TS_TEMPLATE_TYPE = "ts";
|
|
5
|
+
export declare const tsTemplateFileMetadataSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
generator: z.ZodString;
|
|
9
|
+
template: z.ZodString;
|
|
10
|
+
}, {
|
|
11
|
+
type: z.ZodLiteral<"ts">;
|
|
12
|
+
/**
|
|
13
|
+
* The group of templates that this template belongs to.
|
|
14
|
+
*/
|
|
15
|
+
group: z.ZodOptional<z.ZodString>;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the export group that this template belongs to. Export groups
|
|
18
|
+
* allow you to group templates together that share the same import provider.
|
|
19
|
+
*/
|
|
20
|
+
exportGroup: z.ZodOptional<z.ZodString>;
|
|
21
|
+
/**
|
|
22
|
+
* The exports of the file that are unique across the project.
|
|
23
|
+
*/
|
|
24
|
+
projectExports: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
25
|
+
/**
|
|
26
|
+
* Whether the export is a type only export.
|
|
27
|
+
*/
|
|
28
|
+
isTypeOnly: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
/**
|
|
30
|
+
* The exported name of the export within the file. Use 'default' for default exports.
|
|
31
|
+
*/
|
|
32
|
+
exportName: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
isTypeOnly?: boolean | undefined;
|
|
35
|
+
exportName?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
isTypeOnly?: boolean | undefined;
|
|
38
|
+
exportName?: string | undefined;
|
|
39
|
+
}>>>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the template is only exporting types and we should not attempt to extract
|
|
42
|
+
* the contents of the template.
|
|
43
|
+
*/
|
|
44
|
+
projectExportsOnly: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
}>, "strip", z.ZodTypeAny, {
|
|
46
|
+
type: "ts";
|
|
47
|
+
name: string;
|
|
48
|
+
generator: string;
|
|
49
|
+
template: string;
|
|
50
|
+
group?: string | undefined;
|
|
51
|
+
exportGroup?: string | undefined;
|
|
52
|
+
projectExports?: Record<string, {
|
|
53
|
+
isTypeOnly?: boolean | undefined;
|
|
54
|
+
exportName?: string | undefined;
|
|
55
|
+
}> | undefined;
|
|
56
|
+
projectExportsOnly?: boolean | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
type: "ts";
|
|
59
|
+
name: string;
|
|
60
|
+
generator: string;
|
|
61
|
+
template: string;
|
|
62
|
+
group?: string | undefined;
|
|
63
|
+
exportGroup?: string | undefined;
|
|
64
|
+
projectExports?: Record<string, {
|
|
65
|
+
isTypeOnly?: boolean | undefined;
|
|
66
|
+
exportName?: string | undefined;
|
|
67
|
+
}> | undefined;
|
|
68
|
+
projectExportsOnly?: boolean | undefined;
|
|
69
|
+
}>;
|
|
70
|
+
export type TsTemplateFileMetadata = z.infer<typeof tsTemplateFileMetadataSchema>;
|
|
71
|
+
export interface TsTemplateVariable {
|
|
72
|
+
}
|
|
73
|
+
export type TsTemplateVariableMap = Record<string, TsTemplateVariable>;
|
|
74
|
+
export interface TsTemplateFile<TVariables extends TsTemplateVariableMap = Record<never, TsTemplateVariable>, TImportMapProviders extends Record<string, ProviderType> = Record<never, ProviderType>> extends TemplateFileBase {
|
|
75
|
+
/**
|
|
76
|
+
* The variables for the template.
|
|
77
|
+
*/
|
|
78
|
+
variables: TVariables;
|
|
79
|
+
/**
|
|
80
|
+
* The prefix to use for the template variables.
|
|
81
|
+
* @default 'TPL_'
|
|
82
|
+
*/
|
|
83
|
+
prefix?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Import map providers that will be used to resolve imports for the template.
|
|
86
|
+
*/
|
|
87
|
+
importMapProviders?: TImportMapProviders;
|
|
88
|
+
/**
|
|
89
|
+
* The exports of the file that are unique across the project.
|
|
90
|
+
*/
|
|
91
|
+
projectExports?: Record<string, {
|
|
92
|
+
isTypeOnly?: boolean;
|
|
93
|
+
exportName?: string;
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
export type TsTemplateFileVariableValue = TsCodeFragment | string;
|
|
97
|
+
export type InferTsTemplateVariablesFromMap<TMap extends TsTemplateVariableMap> = {
|
|
98
|
+
[T in keyof TMap]: TsTemplateFileVariableValue;
|
|
99
|
+
};
|
|
100
|
+
export type InferImportMapProvidersFromProviderTypeMap<T extends Record<string, ProviderType> | undefined> = Exclude<{
|
|
101
|
+
[K in keyof T]: InferProviderType<T[K]>;
|
|
102
|
+
}, undefined>;
|
|
103
|
+
export declare function createTsTemplateFile<TVariables extends TsTemplateVariableMap = Record<never, TsTemplateVariable>, TImportMapProviders extends Record<string, ProviderType> = Record<never, ProviderType>>(file: TsTemplateFile<TVariables, TImportMapProviders>): TsTemplateFile<TVariables, TImportMapProviders>;
|
|
104
|
+
interface TsTemplateGroupEntry {
|
|
105
|
+
destination: string;
|
|
106
|
+
template: TsTemplateFile;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A group of text template files.
|
|
110
|
+
*/
|
|
111
|
+
export interface TsTemplateGroup<T extends Record<string, TsTemplateGroupEntry> = Record<string, TsTemplateGroupEntry>> {
|
|
112
|
+
/**
|
|
113
|
+
* The templates in the group.
|
|
114
|
+
*/
|
|
115
|
+
templates: T;
|
|
116
|
+
}
|
|
117
|
+
export declare function createTsTemplateGroup<T extends Record<string, TsTemplateGroupEntry>>(group: TsTemplateGroup<T>): TsTemplateGroup<T>;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,eAAO,MAAM,4BAA4B;UANzB,EAAG,SAAS;UAEe,EAAG,SAAS;eAKpD,EAA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CAAC;CACxC,EACD,SAAS,CACV,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,UAAU,SAAS,qBAAqB,GAAG,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAC5E,mBAAmB,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAC/D,KAAK,EACL,YAAY,CACb,EAED,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,mBAAmB,CAAC,GACpD,cAAc,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAEjD;AAED,UAAU,oBAAoB;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,MAAM,CACrD,MAAM,EACN,oBAAoB,CACrB;IAED;;OAEG;IACH,SAAS,EAAE,CAAC,CAAC;CACd;AAED,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC9C,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAE/C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { templateFileMetadataBaseSchema, } from '@baseplate-dev/sync';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { CASE_VALIDATORS } from '@baseplate-dev/utils';
|
|
4
|
+
export const TS_TEMPLATE_TYPE = 'ts';
|
|
5
|
+
export const tsTemplateFileMetadataSchema = templateFileMetadataBaseSchema.extend({
|
|
6
|
+
type: z.literal(TS_TEMPLATE_TYPE),
|
|
7
|
+
/**
|
|
8
|
+
* The group of templates that this template belongs to.
|
|
9
|
+
*/
|
|
10
|
+
group: CASE_VALIDATORS.KEBAB_CASE.optional(),
|
|
11
|
+
/**
|
|
12
|
+
* The name of the export group that this template belongs to. Export groups
|
|
13
|
+
* allow you to group templates together that share the same import provider.
|
|
14
|
+
*/
|
|
15
|
+
exportGroup: CASE_VALIDATORS.KEBAB_CASE.optional(),
|
|
16
|
+
/**
|
|
17
|
+
* The exports of the file that are unique across the project.
|
|
18
|
+
*/
|
|
19
|
+
projectExports: z
|
|
20
|
+
.record(z.string(), z.object({
|
|
21
|
+
/**
|
|
22
|
+
* Whether the export is a type only export.
|
|
23
|
+
*/
|
|
24
|
+
isTypeOnly: z.boolean().optional(),
|
|
25
|
+
/**
|
|
26
|
+
* The exported name of the export within the file. Use 'default' for default exports.
|
|
27
|
+
*/
|
|
28
|
+
exportName: z.string().optional(),
|
|
29
|
+
}))
|
|
30
|
+
.optional(),
|
|
31
|
+
/**
|
|
32
|
+
* Whether the template is only exporting types and we should not attempt to extract
|
|
33
|
+
* the contents of the template.
|
|
34
|
+
*/
|
|
35
|
+
projectExportsOnly: z.boolean().optional(),
|
|
36
|
+
});
|
|
37
|
+
export function createTsTemplateFile(file) {
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
export function createTsTemplateGroup(group) {
|
|
41
|
+
return group;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/renderers/typescript/templates/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,MAAM,CAAC,MAAM,4BAA4B,GACvC,8BAA8B,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACjC;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,QAAQ,EAAE;IAC5C;;;OAGG;IACH,WAAW,EAAE,eAAe,CAAC,UAAU,CAAC,QAAQ,EAAE;IAClD;;OAEG;IACH,cAAc,EAAE,CAAC;SACd,MAAM,CACL,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,MAAM,CAAC;QACP;;WAEG;QACH,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAClC;;WAEG;QACH,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAClC,CAAC,CACH;SACA,QAAQ,EAAE;IACb;;;OAGG;IACH,kBAAkB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAwDL,MAAM,UAAU,oBAAoB,CAOlC,IAAqD;IAErD,OAAO,IAAI,CAAC;AACd,CAAC;AAsBD,MAAM,UAAU,qBAAqB,CAEnC,KAAyB;IACzB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/renderers/typescript/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renderers/typescript/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { TsCodeFragmentOptions } from '../fragments/creators.js';
|
|
2
|
+
import type { TsCodeFragment, TsHoistedFragment } from '../fragments/types.js';
|
|
3
|
+
import type { TsImportDeclarationBuilder } from '../imports/builder.js';
|
|
4
|
+
import type { TsImportDeclaration } from '../imports/types.js';
|
|
5
|
+
export declare function mergeFragmentImportsAndHoistedFragments(fragments: TsCodeFragment[], options?: {
|
|
6
|
+
imports?: TsImportDeclaration[];
|
|
7
|
+
hoistedFragments?: TsHoistedFragment[];
|
|
8
|
+
}): {
|
|
9
|
+
imports: TsImportDeclaration[];
|
|
10
|
+
hoistedFragments: TsHoistedFragment[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Utility functions for working with TypeScript code fragments.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TsCodeUtils: {
|
|
16
|
+
/**
|
|
17
|
+
* Create a code fragment from a string.
|
|
18
|
+
* @param contents - The contents of the code fragment.
|
|
19
|
+
* @returns The code fragment.
|
|
20
|
+
*/
|
|
21
|
+
frag(contents: string, imports?: TsImportDeclaration[] | TsImportDeclaration, options?: TsCodeFragmentOptions): TsCodeFragment;
|
|
22
|
+
/**
|
|
23
|
+
* Create an import builder.
|
|
24
|
+
* @param namedImports - The named imports to add to the import builder.
|
|
25
|
+
* @returns The import builder.
|
|
26
|
+
*/
|
|
27
|
+
importBuilder(namedImports?: string[]): TsImportDeclarationBuilder;
|
|
28
|
+
/**
|
|
29
|
+
* Create a default import declaration.
|
|
30
|
+
* @param name - The name of the import.
|
|
31
|
+
* @param importFrom - The module to import from.
|
|
32
|
+
* @returns The import declaration.
|
|
33
|
+
*/
|
|
34
|
+
defaultImport(name: string, importFrom: string): TsImportDeclaration;
|
|
35
|
+
/**
|
|
36
|
+
* Shortcut function for creating a fragment that imports a named import from a module.
|
|
37
|
+
* @param name - The name of the import.
|
|
38
|
+
* @param importFrom - The module to import from.
|
|
39
|
+
* @returns The import fragment.
|
|
40
|
+
*/
|
|
41
|
+
importFragment(name: string, importFrom: string): TsCodeFragment;
|
|
42
|
+
/**
|
|
43
|
+
* Shortcut function for creating a fragment that imports a named type from a module.
|
|
44
|
+
* @param name - The name of the type.
|
|
45
|
+
* @param importFrom - The module to import from.
|
|
46
|
+
* @returns The import fragment.
|
|
47
|
+
*/
|
|
48
|
+
typeImportFragment(name: string, importFrom: string): TsCodeFragment;
|
|
49
|
+
/**
|
|
50
|
+
* Shortcut function for creating a fragment that imports a default import from a module.
|
|
51
|
+
* @param name - The name of the import.
|
|
52
|
+
* @param importFrom - The module to import from.
|
|
53
|
+
* @returns The import fragment.
|
|
54
|
+
*/
|
|
55
|
+
defaultImportFragment(name: string, importFrom: string): TsCodeFragment;
|
|
56
|
+
/**
|
|
57
|
+
* Merge a map of code fragments into a single code fragment. We by default use
|
|
58
|
+
* maps to ensure that the order of the fragments is deterministic since the
|
|
59
|
+
* code fragments are merged by the order of the keys.
|
|
60
|
+
*
|
|
61
|
+
* @param fragments - The code fragments to merge.
|
|
62
|
+
* @param separator - The separator to use between the fragments.
|
|
63
|
+
* @returns The merged code fragment.
|
|
64
|
+
*/
|
|
65
|
+
mergeFragments(fragments: Map<string, TsCodeFragment | string | undefined> | Record<string, TsCodeFragment | string | undefined>, separator?: string): TsCodeFragment;
|
|
66
|
+
/**
|
|
67
|
+
* Merge an array of code fragments into a single code fragment.
|
|
68
|
+
*
|
|
69
|
+
* NOTE: Be careful about using this function since the order of the fragments may not
|
|
70
|
+
* be deterministic so fragments should be presorted before using.
|
|
71
|
+
*
|
|
72
|
+
* @param fragments - The code fragments to merge.
|
|
73
|
+
* @param separator - The separator to use between the fragments.
|
|
74
|
+
* @returns The merged code fragment.
|
|
75
|
+
*/
|
|
76
|
+
mergeFragmentsPresorted(fragments: (TsCodeFragment | string)[], separator?: string): TsCodeFragment;
|
|
77
|
+
/**
|
|
78
|
+
* Format a string as a comment.
|
|
79
|
+
* @param text - The text to format.
|
|
80
|
+
* @returns The formatted text.
|
|
81
|
+
*/
|
|
82
|
+
formatAsComment(text: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Format a string with content.
|
|
85
|
+
* @param formatString - The string to format.
|
|
86
|
+
* @param args - The arguments to format the string with.
|
|
87
|
+
* @returns The formatted string.
|
|
88
|
+
*/
|
|
89
|
+
formatFragment(formatString: string, args: Record<string, TsCodeFragment | string>, imports?: TsImportDeclaration[] | TsImportDeclaration, options?: {
|
|
90
|
+
hoistedFragments?: TsHoistedFragment[];
|
|
91
|
+
}): TsCodeFragment;
|
|
92
|
+
/**
|
|
93
|
+
* Merge an object of code fragments into a single code fragment.
|
|
94
|
+
*
|
|
95
|
+
* Keys are sorted by default for persistence.
|
|
96
|
+
*
|
|
97
|
+
* @param obj - The object to merge.
|
|
98
|
+
* @param options - The options for the merge.
|
|
99
|
+
* @returns The merged code fragment.
|
|
100
|
+
*/
|
|
101
|
+
mergeFragmentsAsObject(objOrMap: Record<string, TsCodeFragment | string | undefined> | Map<string, TsCodeFragment | string | undefined>, options?: {
|
|
102
|
+
wrapWithParenthesis?: boolean;
|
|
103
|
+
disableSort?: boolean;
|
|
104
|
+
caseSensitive?: boolean;
|
|
105
|
+
}): TsCodeFragment;
|
|
106
|
+
mergeFragmentsAsObjectPresorted(objOrMap: Record<string, TsCodeFragment | string | undefined> | Map<string, TsCodeFragment | string | undefined>, options?: {
|
|
107
|
+
wrapWithParenthesis?: boolean;
|
|
108
|
+
}): TsCodeFragment;
|
|
109
|
+
/**
|
|
110
|
+
* Merge a map of code fragments into interface content. The fragments are sorted by key
|
|
111
|
+
* to ensure deterministic output.
|
|
112
|
+
*
|
|
113
|
+
* Add quotes around property keys that should be escaped and optional properties should be
|
|
114
|
+
* marked with a question mark, e.g. 'complex-key'? for an optional property named complex-key.
|
|
115
|
+
*
|
|
116
|
+
* @param fragments - The code fragments to merge.
|
|
117
|
+
* @param options - The options for the merge.
|
|
118
|
+
* @returns The merged code fragment as interface content.
|
|
119
|
+
*/
|
|
120
|
+
mergeFragmentsAsInterfaceContent(objOrMap: Record<string, TsCodeFragment | string | undefined> | Map<string, TsCodeFragment | string | undefined>, options?: {
|
|
121
|
+
disableSort?: boolean;
|
|
122
|
+
caseSensitive?: boolean;
|
|
123
|
+
}): TsCodeFragment;
|
|
124
|
+
/**
|
|
125
|
+
* Merge an array of code fragments into an array literal.
|
|
126
|
+
*
|
|
127
|
+
* @param fragments - The code fragments to merge.
|
|
128
|
+
* @returns The merged code fragment as an array literal.
|
|
129
|
+
*/
|
|
130
|
+
mergeFragmentsAsArrayPresorted(fragments: (string | TsCodeFragment)[]): TsCodeFragment;
|
|
131
|
+
/**
|
|
132
|
+
* Merge a map of code fragments into an array literal. The fragments are sorted by key
|
|
133
|
+
* to ensure deterministic output.
|
|
134
|
+
*
|
|
135
|
+
* @param fragments - The code fragments to merge.
|
|
136
|
+
* @returns The merged code fragment as an array literal.
|
|
137
|
+
*/
|
|
138
|
+
mergeFragmentsAsArray(objOrMap: Record<string, TsCodeFragment | string> | Map<string, TsCodeFragment | string>): TsCodeFragment;
|
|
139
|
+
/**
|
|
140
|
+
* Wrap a code fragment with a string.
|
|
141
|
+
* @param fragment - The code fragment to wrap.
|
|
142
|
+
* @param wrapper - The string to wrap the code fragment with.
|
|
143
|
+
* @returns The wrapped code fragment.
|
|
144
|
+
*/
|
|
145
|
+
wrapFragment(fragment: TsCodeFragment, wrapper: string): TsCodeFragment;
|
|
146
|
+
/**
|
|
147
|
+
* Creates a template string function that processes template literals with embedded expressions.
|
|
148
|
+
* Similar to the standard template literals, but handles TsCodeFragment objects and collects their imports.
|
|
149
|
+
*
|
|
150
|
+
* @param strings The string parts of the template
|
|
151
|
+
* @param expressions The expressions to be interpolated between the string parts
|
|
152
|
+
* @returns A new TsCodeFragment with the combined content and collected imports
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* const name = 'world';
|
|
156
|
+
* const greeting = tsCodeFragment('Hello');
|
|
157
|
+
* const result = template`${greeting}, ${name}!`;
|
|
158
|
+
* // result.contents will be "Hello, world!"
|
|
159
|
+
* // result.imports will include any imports from the greeting fragment
|
|
160
|
+
*/
|
|
161
|
+
template(strings: TemplateStringsArray, ...expressions: (TsCodeFragment | string)[]): TsCodeFragment;
|
|
162
|
+
templateWithImports(imports?: TsImportDeclaration[] | TsImportDeclaration): (strings: TemplateStringsArray, ...expressions: (TsCodeFragment | string)[]) => TsCodeFragment;
|
|
163
|
+
/**
|
|
164
|
+
* Merge fragments into a JSX element.
|
|
165
|
+
*
|
|
166
|
+
* Attribute values depending on their type are handled differently:
|
|
167
|
+
*
|
|
168
|
+
* - `string`: The value is used as is and automatically escaped if it contains double quotes.
|
|
169
|
+
* - `boolean`: The attribute is added to the JSX element if true, e.g.
|
|
170
|
+
* <Component showBlink /> if showBlink is true. If false, the attribute is
|
|
171
|
+
* not added.
|
|
172
|
+
* - `TsCodeFragment`: The value is used as is inside { } braces, e.g.
|
|
173
|
+
* <Component foo={<div>bar</div>} />.
|
|
174
|
+
*
|
|
175
|
+
* @param name - The name of the JSX element.
|
|
176
|
+
* @param attributes - The attributes of the JSX element.
|
|
177
|
+
* @param imports - Optional imports to add to the fragment.
|
|
178
|
+
* @returns The merged code fragment as a JSX element.
|
|
179
|
+
*/
|
|
180
|
+
mergeFragmentsAsJsxElement(name: string, attributes: Record<string, TsCodeFragment | string | boolean | undefined>, imports?: TsImportDeclaration[] | TsImportDeclaration): TsCodeFragment;
|
|
181
|
+
/**
|
|
182
|
+
* Extract a snippet from a template string of the form:
|
|
183
|
+
*
|
|
184
|
+
* ```
|
|
185
|
+
* // <key>:START
|
|
186
|
+
* <snippet>
|
|
187
|
+
* // <key>:END
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* Note: This is a temporary carry-over from the old TS system. In the future,
|
|
191
|
+
* we will aim to have auto-generated properly typed template snippets.
|
|
192
|
+
*
|
|
193
|
+
* @param template - The template string.
|
|
194
|
+
* @param key - The key to extract.
|
|
195
|
+
* @returns The extracted snippet.
|
|
196
|
+
*/
|
|
197
|
+
extractTemplateSnippet(template: string, key: string): string;
|
|
198
|
+
};
|
|
199
|
+
export declare const tsTemplate: (strings: TemplateStringsArray, ...expressions: (TsCodeFragment | string)[]) => TsCodeFragment;
|
|
200
|
+
//# sourceMappingURL=ts-code-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-code-utils.d.ts","sourceRoot":"","sources":["../../../../src/renderers/typescript/utils/ts-code-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE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