new-lang.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. console.log();
  3. process.on('exit', () => {
  4. console.log();
  5. });
  6. if (!process.argv[2]) {
  7. console.error('[language] is required!');
  8. process.exit(1);
  9. }
  10. var fs = require('fs');
  11. const path = require('path');
  12. const fileSave = require('file-save');
  13. const lang = process.argv[2];
  14. // const configPath = path.resolve(__dirname, '../../examples/i18n', lang);
  15. // 添加到 components.json
  16. const componentFile = require('../../examples/i18n/component.json');
  17. if (componentFile.some(item => item.lang === lang)) {
  18. console.error(`${lang} already exists.`);
  19. process.exit(1);
  20. }
  21. let componentNew = Object.assign({}, componentFile.filter(item => item.lang === 'en-US')[0], { lang });
  22. componentFile.push(componentNew);
  23. fileSave(path.join(__dirname, '../../examples/i18n/component.json'))
  24. .write(JSON.stringify(componentFile, null, ' '), 'utf8')
  25. .end('\n');
  26. // 添加到 page.json
  27. const pageFile = require('../../examples/i18n/page.json');
  28. let pageNew = Object.assign({}, pageFile.filter(item => item.lang === 'en-US')[0], { lang });
  29. pageFile.push(pageNew);
  30. fileSave(path.join(__dirname, '../../examples/i18n/page.json'))
  31. .write(JSON.stringify(pageFile, null, ' '), 'utf8')
  32. .end('\n');
  33. // 添加到 route.json
  34. const routeFile = require('../../examples/i18n/route.json');
  35. routeFile.push({ lang });
  36. fileSave(path.join(__dirname, '../../examples/i18n/route.json'))
  37. .write(JSON.stringify(routeFile, null, ' '), 'utf8')
  38. .end('\n');
  39. // 添加到 nav.config.json
  40. const navFile = require('../../examples/nav.config.json');
  41. navFile[lang] = navFile['en-US'];
  42. fileSave(path.join(__dirname, '../../examples/nav.config.json'))
  43. .write(JSON.stringify(navFile, null, ' '), 'utf8')
  44. .end('\n');
  45. // docs 下新建对应文件夹
  46. try {
  47. fs.statSync(path.resolve(__dirname, `../../examples/docs/${ lang }`));
  48. } catch (e) {
  49. fs.mkdirSync(path.resolve(__dirname, `../../examples/docs/${ lang }`));
  50. }
  51. console.log('DONE!');