(opts: BuildOptions = {})
| 31 | * @param {Object} opts |
| 32 | */ |
| 33 | export 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 |
no test coverage detected