|
1 | | -import { createUnplugin } from "unplugin" |
2 | | -import { ReplexicaAttributeScope, ReplexicaCompiler, ReplexicaContentScope, ReplexicaSkipScope } from "./compiler"; |
3 | | -import { ReplexicaOutputProcessor } from "./output"; |
4 | | -import path from 'path'; |
5 | | -import { createNextPlugin } from "./plugins"; |
6 | | -import { ReplexicaConfig } from "./types"; |
| 1 | +import { nextPlugin } from "./plugins/next"; |
7 | 2 |
|
8 | | -const unplugin = createUnplugin<ReplexicaConfig>((options) => ({ |
9 | | - name: '@replexica/compiler', |
10 | | - enforce: 'pre', |
11 | | - transformInclude(id) { |
12 | | - // .tsx and .jsx files |
13 | | - return /\.(t|j)sx$/.test(id); |
14 | | - }, |
15 | | - transform(code, absoluteFilePath) { |
16 | | - try { |
17 | | - const relativeFilePath = path.relative(process.cwd(), absoluteFilePath); |
18 | | - |
19 | | - const compiler = ReplexicaCompiler |
20 | | - .fromCode(code, relativeFilePath) |
21 | | - .withScope(ReplexicaSkipScope) |
22 | | - .withScope(ReplexicaAttributeScope) |
23 | | - .withScope(ReplexicaContentScope) |
24 | | - .injectIntl(); |
25 | | - |
26 | | - const result = compiler.generate(); |
27 | | - |
28 | | - const outputProcessor = ReplexicaOutputProcessor.create(relativeFilePath, options); |
29 | | - outputProcessor.saveBuildData(compiler.data); |
30 | | - outputProcessor.saveFullSourceLocaleData(compiler.data); |
31 | | - outputProcessor.saveClientSourceLocaleData(compiler.data); |
32 | | - outputProcessor.saveStubLocaleData(); |
33 | | - |
34 | | - if (options.debug) { |
35 | | - outputProcessor.saveAst(compiler.ast); |
36 | | - outputProcessor.saveOutput(result.code); |
37 | | - } |
38 | | - |
39 | | - return { |
40 | | - code: result.code, |
41 | | - map: result.map, |
42 | | - }; |
43 | | - } catch (error: any) { |
44 | | - throw new ReplexicaError(error.message); |
45 | | - } |
46 | | - }, |
47 | | -})); |
48 | | - |
49 | | -class ReplexicaError extends Error { |
50 | | - |
51 | | -} |
52 | | -export * from './types'; |
53 | 3 | export default { |
54 | | - next: createNextPlugin(unplugin), |
| 4 | + next: nextPlugin, |
55 | 5 | }; |
0 commit comments