@intlayer/chokidar 7.2.3 → 7.3.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/README.md +2 -0
- package/dist/cjs/index.cjs +12 -12
- package/dist/cjs/listDictionariesPath.cjs +9 -0
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +9 -2
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transformFiles/extractDictionaryKey.cjs +16 -0
- package/dist/cjs/transformFiles/extractDictionaryKey.cjs.map +1 -0
- package/dist/cjs/transformFiles/index.cjs +6 -0
- package/dist/cjs/transformFiles/transformFiles.cjs +218 -0
- package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +16 -14
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -1
- package/dist/esm/index.mjs +10 -9
- package/dist/esm/listDictionariesPath.mjs +9 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +10 -3
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transformFiles/extractDictionaryKey.mjs +15 -0
- package/dist/esm/transformFiles/extractDictionaryKey.mjs.map +1 -0
- package/dist/esm/transformFiles/index.mjs +4 -0
- package/dist/esm/transformFiles/transformFiles.mjs +215 -0
- package/dist/esm/transformFiles/transformFiles.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +16 -14
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
- package/dist/types/index.d.ts +5 -3
- package/dist/types/listDictionariesPath.d.ts +6 -1
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/transformFiles/extractDictionaryKey.d.ts +5 -0
- package/dist/types/transformFiles/extractDictionaryKey.d.ts.map +1 -0
- package/dist/types/transformFiles/index.d.ts +3 -0
- package/dist/types/transformFiles/transformFiles.d.ts +16 -0
- package/dist/types/transformFiles/transformFiles.d.ts.map +1 -0
- package/package.json +21 -12
- package/dist/cjs/compiler/extractDictionaryKey.cjs +0 -38
- package/dist/cjs/compiler/extractDictionaryKey.cjs.map +0 -1
- package/dist/cjs/compiler/index.cjs +0 -225
- package/dist/cjs/compiler/index.cjs.map +0 -1
- package/dist/esm/compiler/extractDictionaryKey.mjs +0 -36
- package/dist/esm/compiler/extractDictionaryKey.mjs.map +0 -1
- package/dist/esm/compiler/index.mjs +0 -219
- package/dist/esm/compiler/index.mjs.map +0 -1
- package/dist/types/compiler/extractDictionaryKey.d.ts +0 -13
- package/dist/types/compiler/extractDictionaryKey.d.ts.map +0 -1
- package/dist/types/compiler/index.d.ts +0 -36
- package/dist/types/compiler/index.d.ts.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["extractedContent: Record<string, string>","replacements: Replacement[]","current: Node | undefined","name: string | undefined","sourceFile: SourceFile"],"sources":["../../../src/compiler/index.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\nimport {\n camelCaseToKebabCase,\n colorizePath,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { Node, Project, type SourceFile } from 'ts-morph';\nimport { writeContentDeclaration } from '../writeContentDeclaration';\nimport { detectFormatCommand } from '../writeContentDeclaration/detectFormatCommand';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\nconst ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\nconst generateKey = (text: string, existingKeys: Set<string>): string => {\n const maxWords = 5;\n let key = text\n .replace(/\\s+/g, ' ') // Normalize whitespace to single spaces\n .replace(/[^a-zA-Z0-9 ]/g, '') // Remove special chars\n .trim()\n .split(' ')\n .filter(Boolean)\n .slice(0, maxWords)\n .map((word, index) =>\n index === 0\n ? word.toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n )\n .join('');\n\n // Fallback for empty keys (e.g. only symbols)\n if (!key) key = 'content';\n\n // Handle duplicates\n if (existingKeys.has(key)) {\n let i = 1;\n while (existingKeys.has(`${key}${i}`)) i++;\n key = `${key}${i}`;\n }\n\n return key;\n};\n\ntype Replacement = {\n node: Node;\n key: string;\n type: 'jsx-text' | 'jsx-attribute' | 'string-literal';\n};\n\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n // 1. Must have some text\n if (!trimmed) return false;\n // 2. Must contain spaces (not a single camelCase/kebab-case word)\n if (!trimmed.includes(' ')) return false;\n // 3. Must start with a capital letter\n // We check the first non-whitespace character\n if (!/^[A-Z]/.test(trimmed)) return false;\n\n return true;\n};\n\n/**\n * 1. Extraction of content\n */\nexport const extractContent = (sourceFile: SourceFile) => {\n const extractedContent: Record<string, string> = {};\n const existingKeys = new Set<string>();\n const replacements: Replacement[] = [];\n\n const processText = (text: string, node: Node, type: Replacement['type']) => {\n if (!shouldExtract(text)) return;\n\n const key = generateKey(text.trim(), existingKeys);\n existingKeys.add(key);\n extractedContent[key] =\n type === 'jsx-text' ? text.replace(/\\s+/g, ' ').trim() : text.trim();\n replacements.push({ node, key, type });\n };\n\n sourceFile.forEachDescendant((node) => {\n // Case A: JSX Text (e.g., <h2>Title</h2>)\n if (Node.isJsxText(node)) {\n processText(node.getText(), node, 'jsx-text');\n }\n\n // Case B: JSX Attributes (e.g., placeholder=\"Search\")\n if (Node.isJsxAttribute(node)) {\n const name = node.getNameNode().getText();\n if (ATTRIBUTES_TO_EXTRACT.includes(name)) {\n const initializer = node.getInitializer();\n if (Node.isStringLiteral(initializer)) {\n processText(initializer.getLiteralValue(), node, 'jsx-attribute');\n }\n }\n }\n\n // Case C: String Literals in specific contexts\n if (Node.isStringLiteral(node)) {\n const parent = node.getParent();\n\n // 1. State initialization: useState('...')\n if (Node.isCallExpression(parent)) {\n const expression = parent.getExpression();\n if (\n Node.isIdentifier(expression) &&\n expression.getText() === 'useState'\n ) {\n processText(node.getLiteralValue(), node, 'string-literal');\n }\n }\n\n // 2. Ternary operators in JSX: { isTrue ? 'Text' : 'Other' }\n if (Node.isConditionalExpression(parent)) {\n // Check if this conditional is inside a JSX expression\n let current: Node | undefined = parent.getParent();\n let isInsideJsx = false;\n while (current) {\n if (Node.isJsxExpression(current)) {\n isInsideJsx = true;\n break;\n }\n if (Node.isBlock(current) || Node.isSourceFile(current)) break;\n current = current.getParent();\n }\n\n if (isInsideJsx) {\n processText(node.getLiteralValue(), node, 'string-literal');\n }\n }\n\n // 3. Array elements (simple heuristic: inside array literal)\n if (Node.isArrayLiteralExpression(parent)) {\n processText(node.getLiteralValue(), node, 'string-literal');\n }\n\n // 4. Object property values (e.g. { value: \"Text\" })\n if (Node.isPropertyAssignment(parent)) {\n const initializer = parent.getInitializer();\n if (initializer === node) {\n processText(node.getLiteralValue(), node, 'string-literal');\n }\n }\n\n // 5. Return statements\n if (Node.isReturnStatement(parent)) {\n processText(node.getLiteralValue(), node, 'string-literal');\n }\n }\n });\n\n return { extractedContent, replacements };\n};\n\n/**\n * 2. Write content declaration\n */\nexport const writeContent = async (\n extractedContent: Record<string, string>,\n componentKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n outputDir?: string\n) => {\n const { defaultLocale } = configuration.internationalization;\n const { baseDir } = configuration.content;\n\n const dirName = outputDir ? resolve(outputDir) : dirname(filePath);\n const ext = extname(filePath);\n const baseName = basename(filePath, ext);\n\n const contentFilePath = join(dirName, `${baseName}.content.ts`);\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n\n const dictionary: Dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n\n const relativeDir = relative(baseDir, dirName);\n\n await writeContentDeclaration(dictionary, configuration, {\n newDictionariesPath: relativeDir,\n });\n\n return contentFilePath;\n};\n\nconst isComponent = (node: Node): boolean => {\n let name: string | undefined;\n\n if (Node.isFunctionDeclaration(node)) {\n name = node.getName();\n } else if (Node.isFunctionExpression(node) || Node.isArrowFunction(node)) {\n const parent = node.getParent();\n if (Node.isVariableDeclaration(parent)) {\n name = parent.getName();\n }\n }\n\n if (!name) return false;\n // Check for PascalCase\n return /^[A-Z]/.test(name);\n};\n\n/**\n * 3. Transform component\n */\nexport const transformComponent = async (\n sourceFile: SourceFile,\n replacements: Replacement[],\n componentKey: string,\n packageName: string\n) => {\n if (replacements.length === 0) return;\n\n const componentsToInjectHook = new Map<Node, 'hook' | 'function'>();\n\n for (const { node, key, type } of replacements) {\n // Find the parent function/component\n let current = node.getParent();\n while (current) {\n if (\n (Node.isFunctionDeclaration(current) ||\n Node.isArrowFunction(current) ||\n Node.isFunctionExpression(current)) &&\n // Ensure body exists and is a block for injection\n // Using explicit casting/checking to avoid \"undefined\" type error\n (() => {\n const body = (current as any).getBody?.();\n return body && Node.isBlock(body);\n })()\n ) {\n // Determine if it's a component or helper\n const isComp = isComponent(current);\n const injectionType = isComp ? 'hook' : 'function';\n\n // Check if we already decided on a type for this component\n const existing = componentsToInjectHook.get(current);\n if (!existing) {\n componentsToInjectHook.set(current, injectionType);\n } else if (existing === 'function' && injectionType === 'hook') {\n // Upgrade to hook if detected as component by another usage?\n // Actually, isComponent checks the definition, so it shouldn't change.\n // But strictness matters.\n componentsToInjectHook.set(current, 'hook');\n }\n\n break;\n }\n current = current.getParent();\n }\n\n const replaceText = (isJsx: boolean) => {\n const needsValue =\n !isJsx &&\n (packageName === 'react-intlayer' || packageName === 'next-intlayer');\n return needsValue ? `content.${key}.value` : `content.${key}`;\n };\n\n if (type === 'jsx-text' && Node.isJsxText(node)) {\n node.replaceWithText(`{${replaceText(true)}}`);\n } else if (type === 'jsx-attribute' && Node.isJsxAttribute(node)) {\n node.setInitializer(`{${replaceText(false)}}`);\n } else if (type === 'string-literal' && Node.isStringLiteral(node)) {\n node.replaceWithText(replaceText(false));\n }\n }\n\n let injectedUseIntlayer = false;\n let injectedGetIntlayer = false;\n\n // Inject hook/function in all affected components\n for (const [componentBody, injectionType] of componentsToInjectHook) {\n const body = (componentBody as any).getBody();\n if (Node.isBlock(body)) {\n const text = body.getText();\n const statement =\n injectionType === 'hook'\n ? `const content = useIntlayer(\"${componentKey}\");`\n : `const content = getIntlayer(\"${componentKey}\");`;\n\n // Check if already injected (naive check)\n if (\n !text.includes(`useIntlayer(\"${componentKey}\")`) &&\n !text.includes(`getIntlayer(\"${componentKey}\")`)\n ) {\n body.insertStatements(0, statement);\n }\n\n if (injectionType === 'hook') injectedUseIntlayer = true;\n if (injectionType === 'function') injectedGetIntlayer = true;\n }\n }\n\n // Insert Imports\n const importSource =\n packageName === 'next-intlayer'\n ? sourceFile.getText().includes('\"use client\"') ||\n sourceFile.getText().includes(\"'use client'\")\n ? 'next-intlayer'\n : 'next-intlayer/server'\n : packageName;\n\n const existingImport = sourceFile.getImportDeclaration(\n (d) => d.getModuleSpecifierValue() === importSource\n );\n\n const namedImports = new Set<string>();\n if (injectedUseIntlayer) namedImports.add('useIntlayer');\n if (injectedGetIntlayer) namedImports.add('getIntlayer');\n\n if (namedImports.size > 0) {\n if (!existingImport) {\n sourceFile.addImportDeclaration({\n namedImports: Array.from(namedImports),\n moduleSpecifier: importSource,\n });\n } else {\n const currentNamedImports = existingImport\n .getNamedImports()\n .map((n) => n.getName());\n for (const name of namedImports) {\n if (!currentNamedImports.includes(name)) {\n existingImport.addNamedImport(name);\n }\n }\n }\n }\n\n await sourceFile.save();\n};\n\ntype ExtractIntlayer = {\n configOptions?: GetConfigurationOptions;\n outputDir?: string;\n};\n\nexport type PackageName =\n | 'next-intlayer'\n | 'react-intlayer'\n | 'vue-intlayer'\n | 'preact-intlayer'\n | 'solid-intlayer'\n | 'angular-intlayer'\n | 'svelte-intlayer'\n | 'express-intlayer';\n\nexport const extractIntlayer = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayer,\n project?: Project\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const { baseDir } = configuration.content;\n const appLogger = getAppLogger(configuration);\n\n // Use provided project or create new one (optimized)\n const _project =\n project ||\n new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n let sourceFile: SourceFile;\n try {\n sourceFile = _project.addSourceFileAtPath(filePath);\n } catch {\n // If file is already added, get it\n sourceFile = _project.getSourceFileOrThrow(filePath);\n }\n\n const baseName = extractDictionaryKey(filePath, sourceFile.getText());\n const componentKey = camelCaseToKebabCase(baseName);\n\n // 1. Extract content\n const { extractedContent, replacements } = extractContent(sourceFile);\n\n if (Object.keys(extractedContent).length === 0) {\n appLogger(`No extractable text found in ${baseName}`);\n // Cleanup if we created the project just for this file\n if (!project) {\n // _project.removeSourceFile(sourceFile); // Not strictly necessary if process exits, but good practice\n }\n return;\n }\n\n // 2. Write content declaration\n const contentFilePath = await writeContent(\n extractedContent,\n componentKey,\n filePath,\n configuration,\n options?.outputDir\n );\n const relativeContentFilePath = relative(\n configuration.content.baseDir,\n contentFilePath\n );\n\n appLogger(`Created content file: ${colorizePath(relativeContentFilePath)}`);\n\n // 3. Transform component\n await transformComponent(sourceFile, replacements, componentKey, packageName);\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n\n const relativeFilePath = relative(baseDir, filePath);\n\n appLogger(`Updated component: ${colorizePath(relativeFilePath)}`);\n\n // Cleanup to free memory if we are processing many files and passed a persistent project?\n // If 'project' is passed, we probably want to keep it?\n // Actually, for a CLI command running once, memory growth is acceptable if not too huge.\n // But removing source file is safer if not needed anymore.\n if (project) {\n sourceFile.forget(); // Remove from project to save memory\n }\n};\n\nexport const transformFiles = async (\n filePaths: string[],\n packageName: PackageName,\n options?: ExtractIntlayer\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n for (const filePath of filePaths) {\n try {\n await extractIntlayer(filePath, packageName, options, project);\n } catch (error) {\n appLogger(`Failed to transform ${filePath}: ${(error as Error).message}`);\n }\n }\n};\n"],"mappings":";;;;;;;;;AAeA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,eAAe,MAAc,iBAAsC;CAEvE,IAAI,MAAM,KACP,QAAQ,QAAQ,IAAI,CACpB,QAAQ,kBAAkB,GAAG,CAC7B,MAAM,CACN,MAAM,IAAI,CACV,OAAO,QAAQ,CACf,MAAM,GAPQ,EAOI,CAClB,KAAK,MAAM,UACV,UAAU,IACN,KAAK,aAAa,GAClB,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,CAAC,aAAa,CAC/D,CACA,KAAK,GAAG;AAGX,KAAI,CAAC,IAAK,OAAM;AAGhB,KAAI,aAAa,IAAI,IAAI,EAAE;EACzB,IAAI,IAAI;AACR,SAAO,aAAa,IAAI,GAAG,MAAM,IAAI,CAAE;AACvC,QAAM,GAAG,MAAM;;AAGjB,QAAO;;AAST,MAAa,iBAAiB,SAA0B;CACtD,MAAM,UAAU,KAAK,MAAM;AAE3B,KAAI,CAAC,QAAS,QAAO;AAErB,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAGnC,KAAI,CAAC,SAAS,KAAK,QAAQ,CAAE,QAAO;AAEpC,QAAO;;;;;AAMT,MAAa,kBAAkB,eAA2B;CACx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d;;CAIF,MAAM,kBAAkB,MAAM,aAC5B,kBACA,cACA,UACA,eACA,SAAS,UACV;AAMD,WAAU,yBAAyB,aALH,SAC9B,cAAc,QAAQ,SACtB,gBACD,CAEuE,GAAG;AAG3E,OAAM,mBAAmB,YAAY,cAAc,cAAc,YAAY;CAE7E,MAAM,gBAAgB,oBAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,WAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK;GACN,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM;;AAMxB,WAAU,sBAAsB,aAFP,SAAS,SAAS,SAAS,CAEU,GAAG;AAMjE,KAAI,QACF,YAAW,QAAQ;;AAIvB,MAAa,iBAAiB,OAC5B,WACA,aACA,YACG;CAEH,MAAM,YAAY,aADI,iBAAiB,SAAS,cAAc,CACjB;CAE7C,MAAM,UAAU,IAAI,QAAQ,EAC1B,6BAA6B,MAC9B,CAAC;AAEF,MAAK,MAAM,YAAY,UACrB,KAAI;AACF,QAAM,gBAAgB,UAAU,aAAa,SAAS,QAAQ;UACvD,OAAO;AACd,YAAU,uBAAuB,SAAS,IAAK,MAAgB,UAAU"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/compiler/extractDictionaryKey.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Attempt to detect an exported React component name in the file text.
|
|
4
|
-
* Looks for patterns like:
|
|
5
|
-
* - export const MyComponent = ...
|
|
6
|
-
* - export function MyComponent(...)
|
|
7
|
-
* - export default function MyComponent(...)
|
|
8
|
-
*/
|
|
9
|
-
declare const detectExportedComponentName: (fileText: string) => string | null;
|
|
10
|
-
declare const extractDictionaryKey: (filePath: string, fileText: string) => string;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { detectExportedComponentName, extractDictionaryKey };
|
|
13
|
-
//# sourceMappingURL=extractDictionaryKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractDictionaryKey.d.ts","names":[],"sources":["../../../src/compiler/extractDictionaryKey.ts"],"sourcesContent":[],"mappings":";;AASA;AAuCA;;;;;cAvCa;cAuCA"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { IntlayerConfig } from "@intlayer/types";
|
|
2
|
-
import { GetConfigurationOptions } from "@intlayer/config";
|
|
3
|
-
import { Node, Project, SourceFile } from "ts-morph";
|
|
4
|
-
|
|
5
|
-
//#region src/compiler/index.d.ts
|
|
6
|
-
type Replacement = {
|
|
7
|
-
node: Node;
|
|
8
|
-
key: string;
|
|
9
|
-
type: 'jsx-text' | 'jsx-attribute' | 'string-literal';
|
|
10
|
-
};
|
|
11
|
-
declare const shouldExtract: (text: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* 1. Extraction of content
|
|
14
|
-
*/
|
|
15
|
-
declare const extractContent: (sourceFile: SourceFile) => {
|
|
16
|
-
extractedContent: Record<string, string>;
|
|
17
|
-
replacements: Replacement[];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* 2. Write content declaration
|
|
21
|
-
*/
|
|
22
|
-
declare const writeContent: (extractedContent: Record<string, string>, componentKey: string, filePath: string, configuration: IntlayerConfig, outputDir?: string) => Promise<string>;
|
|
23
|
-
/**
|
|
24
|
-
* 3. Transform component
|
|
25
|
-
*/
|
|
26
|
-
declare const transformComponent: (sourceFile: SourceFile, replacements: Replacement[], componentKey: string, packageName: string) => Promise<void>;
|
|
27
|
-
type ExtractIntlayer = {
|
|
28
|
-
configOptions?: GetConfigurationOptions;
|
|
29
|
-
outputDir?: string;
|
|
30
|
-
};
|
|
31
|
-
type PackageName = 'next-intlayer' | 'react-intlayer' | 'vue-intlayer' | 'preact-intlayer' | 'solid-intlayer' | 'angular-intlayer' | 'svelte-intlayer' | 'express-intlayer';
|
|
32
|
-
declare const extractIntlayer: (filePath: string, packageName: PackageName, options?: ExtractIntlayer, project?: Project) => Promise<void>;
|
|
33
|
-
declare const transformFiles: (filePaths: string[], packageName: PackageName, options?: ExtractIntlayer) => Promise<void>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { PackageName, extractContent, extractIntlayer, shouldExtract, transformComponent, transformFiles, writeContent };
|
|
36
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/compiler/index.ts"],"sourcesContent":[],"mappings":";;;;;KAoDK,WAAA;QACG;EADH,GAAA,EAAA,MAAA;EAMQ,IAAA,EAAA,UAWZ,GAAA,eAAA,GAAA,gBAAA;AAKD,CAAA;AAA2C,cAhB9B,aAgB8B,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAAA,OAAA;;;;AA4F9B,cA5FA,cA2HZ,EAAA,CAAA,UAAA,EA3H0C,UA2H1C,EAAA,GAAA;EA9BmB,gBAAA,QAAA,CAAA,MAAA,EAAA,MAAA,CAAA;EAGH,YAAA,aAAA,EAAA;CACG;;AAgDpB;;AAEgB,cAvDH,YAuDG,EAAA,CAAA,gBAAA,EAtDI,MAsDJ,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,YAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,aAAA,EAnDC,cAmDD,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,GAlDI,OAkDJ,CAAA,MAAA,CAAA;;;AAyHd;AAOU,cAlIC,kBAkIU,EAAA,CAAA,UAAA,EAjIT,UAiIS,EAAA,YAAA,EAhIP,WAgIO,EAAA,EAAA,YAAA,EAAA,MAAA,EAAA,WAAA,EAAA,MAAA,EAAA,GA9HF,OA8HE,CAAA,IAAA,CAAA;AAUvB,KAfK,eAAA,GAiGJ;EAhFc,aAAA,CAAA,EAhBG,uBAgBH;EACH,SAAA,CAAA,EAAA,MAAA;CACA;AAAO,KAdP,WAAA,GAcO,eAAA,GAAA,gBAAA,GAAA,cAAA,GAAA,iBAAA,GAAA,gBAAA,GAAA,kBAAA,GAAA,iBAAA,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