MCPcopy Create free account
hub / github.com/GrapesJS/cli / buildLocale

Function buildLocale

src/build.ts:33–60  ·  view source on GitHub ↗
(opts: BuildOptions = {})

Source from the content-addressed store, hash-verified

31 * @param {Object} opts
32 */
33export const buildLocale = async (opts: BuildOptions = {}) => {
34 const { localePath } = opts;
35 if (!fs.existsSync(rootResolve(localePath))) return;
36 printRow('Start building locale files...', { lineDown: 0 });
37
38 await rimraf('locale');
39
40 const localDst = rootResolve('locale');
41 copyRecursiveSync(rootResolve(localePath), localDst);
42
43 // Create locale/index.js file
44 let result = '';
45 fs.readdirSync(localDst).forEach(file => {
46 const name = file.split('.')[0];
47 result += `export { default as ${name} } from './${name}'\n`;
48 });
49 fs.writeFileSync(`${localDst}/index.js`, result);
50
51 // Compile files
52 const babelOpts = { ...babelConfig(buildWebpackArgs(opts) as any) };
53 fs.readdirSync(localDst).forEach(file => {
54 const filePath = `${localDst}/${file}`;
55 const compiled = transformFileSync(filePath, babelOpts).code;
56 fs.writeFileSync(filePath, compiled);
57 });
58
59 printRow('Locale files building completed successfully!');
60}
61
62/**
63 * Build TS declaration file

Callers 1

buildWebpackFunction · 0.85

Calls 5

rootResolveFunction · 0.90
printRowFunction · 0.90
copyRecursiveSyncFunction · 0.90
babelConfigFunction · 0.90
buildWebpackArgsFunction · 0.90

Tested by

no test coverage detected