@oinone/cli 7.2.4 → 7.2.6

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.
Files changed (222) hide show
  1. package/README.md +100 -71
  2. package/README_zh-CN.md +100 -71
  3. package/bin/cli.js +48 -472
  4. package/bin/commands/cache.js +70 -0
  5. package/bin/commands/create/enterprise.js +81 -0
  6. package/bin/commands/create/index.js +128 -0
  7. package/bin/commands/create/project.js +81 -0
  8. package/bin/commands/create/prompts.js +126 -0
  9. package/bin/commands/create/static-resources.js +159 -0
  10. package/bin/commands/create/template.js +38 -0
  11. package/bin/commands/create/update-check.js +44 -0
  12. package/bin/commands/create/version-source.js +32 -0
  13. package/bin/commands/create.js +1 -0
  14. package/bin/commands/doctor.js +51 -0
  15. package/bin/config.js +54 -0
  16. package/bin/i18n.js +60 -0
  17. package/bin/locales/en-US.json +81 -0
  18. package/bin/locales/zh-CN.json +81 -0
  19. package/bin/utils/oinone-version.js +60 -0
  20. package/package.json +6 -3
  21. package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/vue.config.js +1 -1
  22. package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/vue.config.js +1 -1
  23. package/template-6.4.0-enterprise/.eslintignore +0 -5
  24. package/template-6.4.0-enterprise/.eslintrc.json +0 -72
  25. package/template-6.4.0-enterprise/_package.json +0 -47
  26. package/template-6.4.0-enterprise/npmrc +0 -3
  27. package/template-6.4.0-enterprise/packages/ss-admin-widget/package.json +0 -25
  28. package/template-6.4.0-enterprise/packages/ss-admin-widget/rollup.config.js +0 -73
  29. package/template-6.4.0-enterprise/packages/ss-admin-widget/tsconfig.json +0 -45
  30. package/template-6.4.0-enterprise/packages/ss-boot/package.json +0 -66
  31. package/template-6.4.0-enterprise/packages/ss-boot/src/main.ts +0 -69
  32. package/template-6.4.0-enterprise/packages/ss-boot/tsconfig.json +0 -44
  33. package/template-6.4.0-enterprise/packages/ss-boot/vue.config.js +0 -84
  34. package/template-6.4.0-enterprise/packages/ss-oinone/package.json +0 -29
  35. package/template-6.4.0-enterprise/packages/ss-oinone/rollup.config.js +0 -82
  36. package/template-6.4.0-enterprise/packages/ss-oinone/tsconfig.json +0 -42
  37. package/template-6.4.0-enterprise/packages/ss-project/package.json +0 -30
  38. package/template-6.4.0-enterprise/packages/ss-project/rollup.config.js +0 -83
  39. package/template-6.4.0-enterprise/packages/ss-project/tsconfig.json +0 -42
  40. package/template-6.4.0-enterprise/scripts/build/postbuild.js +0 -42
  41. package/template-6.4.0-enterprise/scripts/build/prebuild-only.js +0 -48
  42. package/template-7.2.0-community/.prettierrc.json +0 -8
  43. package/template-7.2.0-community/README.md +0 -59
  44. package/template-7.2.0-community/gitignore +0 -58
  45. package/template-7.2.0-community/lerna.json +0 -12
  46. package/template-7.2.0-community/packages/ss-admin-widget/index.ts +0 -1
  47. package/template-7.2.0-community/packages/ss-admin-widget/scripts/postpublish.js +0 -13
  48. package/template-7.2.0-community/packages/ss-admin-widget/scripts/prepublish-only.js +0 -24
  49. package/template-7.2.0-community/packages/ss-admin-widget/src/index.ts +0 -1
  50. package/template-7.2.0-community/packages/ss-admin-widget/src/shim-translate.d.ts +0 -10
  51. package/template-7.2.0-community/packages/ss-admin-widget/src/shim-vue.d.ts +0 -6
  52. package/template-7.2.0-community/packages/ss-boot/.env +0 -1
  53. package/template-7.2.0-community/packages/ss-boot/.env.example +0 -6
  54. package/template-7.2.0-community/packages/ss-boot/public/favicon.ico +0 -0
  55. package/template-7.2.0-community/packages/ss-boot/public/index.html +0 -83
  56. package/template-7.2.0-community/packages/ss-boot/public/manifest.js +0 -5
  57. package/template-7.2.0-community/packages/ss-boot/src/shim-translate.d.ts +0 -10
  58. package/template-7.2.0-community/packages/ss-boot/src/shim-vue.d.ts +0 -6
  59. package/template-7.2.0-community/packages/ss-oinone/index.ts +0 -1
  60. package/template-7.2.0-community/packages/ss-oinone/scripts/postpublish.js +0 -13
  61. package/template-7.2.0-community/packages/ss-oinone/scripts/prepublish-only.js +0 -24
  62. package/template-7.2.0-community/packages/ss-oinone/src/index.ts +0 -1
  63. package/template-7.2.0-community/packages/ss-oinone/src/shim-translate.d.ts +0 -10
  64. package/template-7.2.0-community/packages/ss-oinone/src/shim-vue.d.ts +0 -6
  65. package/template-7.2.0-community/packages/ss-project/index.ts +0 -1
  66. package/template-7.2.0-community/packages/ss-project/scripts/postpublish.js +0 -13
  67. package/template-7.2.0-community/packages/ss-project/scripts/prepublish-only.js +0 -24
  68. package/template-7.2.0-community/packages/ss-project/src/index.ts +0 -1
  69. package/template-7.2.0-community/packages/ss-project/src/shim-translate.d.ts +0 -10
  70. package/template-7.2.0-community/packages/ss-project/src/shim-vue.d.ts +0 -6
  71. package/template-7.2.0-community/pnpm-workspace.yaml +0 -3
  72. package/template-7.2.0-community/scripts/build/inset-tsconfig.js +0 -68
  73. package/template-7.2.0-community/scripts/build/package-name.js +0 -25
  74. package/template-7.2.0-community/scripts/clean.mjs +0 -22
  75. package/template-7.2.0-enterprise/.prettierrc.json +0 -8
  76. package/template-7.2.0-enterprise/README.md +0 -59
  77. package/template-7.2.0-enterprise/_package.json +0 -57
  78. package/template-7.2.0-enterprise/eslint.config.ts +0 -23
  79. package/template-7.2.0-enterprise/gitignore +0 -58
  80. package/template-7.2.0-enterprise/lerna.json +0 -12
  81. package/template-7.2.0-enterprise/npmrc +0 -3
  82. package/template-7.2.0-enterprise/packages/ss-admin-widget/index.ts +0 -1
  83. package/template-7.2.0-enterprise/packages/ss-admin-widget/package.json +0 -27
  84. package/template-7.2.0-enterprise/packages/ss-admin-widget/rollup.config.js +0 -14
  85. package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/postpublish.js +0 -13
  86. package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/prepublish-only.js +0 -24
  87. package/template-7.2.0-enterprise/packages/ss-admin-widget/src/index.ts +0 -1
  88. package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-translate.d.ts +0 -10
  89. package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-vue.d.ts +0 -6
  90. package/template-7.2.0-enterprise/packages/ss-admin-widget/tsconfig.json +0 -14
  91. package/template-7.2.0-enterprise/packages/ss-boot/.env +0 -1
  92. package/template-7.2.0-enterprise/packages/ss-boot/.env.example +0 -6
  93. package/template-7.2.0-enterprise/packages/ss-boot/package.json +0 -64
  94. package/template-7.2.0-enterprise/packages/ss-boot/public/favicon.ico +0 -0
  95. package/template-7.2.0-enterprise/packages/ss-boot/public/index.html +0 -83
  96. package/template-7.2.0-enterprise/packages/ss-boot/public/manifest.js +0 -5
  97. package/template-7.2.0-enterprise/packages/ss-boot/src/main.ts +0 -66
  98. package/template-7.2.0-enterprise/packages/ss-boot/src/shim-translate.d.ts +0 -10
  99. package/template-7.2.0-enterprise/packages/ss-boot/src/shim-vue.d.ts +0 -6
  100. package/template-7.2.0-enterprise/packages/ss-boot/tsconfig.json +0 -27
  101. package/template-7.2.0-enterprise/packages/ss-boot/vue.config.js +0 -87
  102. package/template-7.2.0-enterprise/packages/ss-oinone/index.ts +0 -1
  103. package/template-7.2.0-enterprise/packages/ss-oinone/package.json +0 -30
  104. package/template-7.2.0-enterprise/packages/ss-oinone/rollup.config.js +0 -14
  105. package/template-7.2.0-enterprise/packages/ss-oinone/scripts/postpublish.js +0 -13
  106. package/template-7.2.0-enterprise/packages/ss-oinone/scripts/prepublish-only.js +0 -24
  107. package/template-7.2.0-enterprise/packages/ss-oinone/src/index.ts +0 -1
  108. package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-translate.d.ts +0 -10
  109. package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-vue.d.ts +0 -6
  110. package/template-7.2.0-enterprise/packages/ss-oinone/tsconfig.json +0 -14
  111. package/template-7.2.0-enterprise/packages/ss-project/index.ts +0 -1
  112. package/template-7.2.0-enterprise/packages/ss-project/package.json +0 -30
  113. package/template-7.2.0-enterprise/packages/ss-project/rollup.config.js +0 -14
  114. package/template-7.2.0-enterprise/packages/ss-project/scripts/postpublish.js +0 -13
  115. package/template-7.2.0-enterprise/packages/ss-project/scripts/prepublish-only.js +0 -24
  116. package/template-7.2.0-enterprise/packages/ss-project/src/index.ts +0 -1
  117. package/template-7.2.0-enterprise/packages/ss-project/src/shim-translate.d.ts +0 -10
  118. package/template-7.2.0-enterprise/packages/ss-project/src/shim-vue.d.ts +0 -6
  119. package/template-7.2.0-enterprise/packages/ss-project/tsconfig.json +0 -14
  120. package/template-7.2.0-enterprise/pnpm-workspace.yaml +0 -3
  121. package/template-7.2.0-enterprise/scripts/build/inset-tsconfig.js +0 -68
  122. package/template-7.2.0-enterprise/scripts/build/package-name.js +0 -25
  123. package/template-7.2.0-enterprise/scripts/clean.mjs +0 -22
  124. /package/{template-6.4.0-community → template-6.4.0}/.eslintignore +0 -0
  125. /package/{template-6.4.0-community → template-6.4.0}/.eslintrc.json +0 -0
  126. /package/{template-6.4.0-community → template-6.4.0}/.prettierrc.json +0 -0
  127. /package/{template-6.4.0-community → template-6.4.0}/README.md +0 -0
  128. /package/{template-6.4.0-community → template-6.4.0}/_package.json +0 -0
  129. /package/{template-6.4.0-community → template-6.4.0}/gitignore +0 -0
  130. /package/{template-6.4.0-community → template-6.4.0}/lerna.json +0 -0
  131. /package/{template-6.4.0-community → template-6.4.0}/npmrc +0 -0
  132. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/index.ts +0 -0
  133. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/package.json +0 -0
  134. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/rollup.config.js +0 -0
  135. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/scripts/postpublish.js +0 -0
  136. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/scripts/prepublish-only.js +0 -0
  137. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/index.ts +0 -0
  138. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/shim-translate.d.ts +0 -0
  139. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/shim-vue.d.ts +0 -0
  140. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/tsconfig.json +0 -0
  141. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/.env +0 -0
  142. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/.env.example +0 -0
  143. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/package.json +0 -0
  144. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/public/favicon.ico +0 -0
  145. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/public/index.html +0 -0
  146. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/public/manifest.js +0 -0
  147. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/main.ts +0 -0
  148. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/shim-translate.d.ts +0 -0
  149. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/shim-vue.d.ts +0 -0
  150. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/tsconfig.json +0 -0
  151. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/index.ts +0 -0
  152. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/package.json +0 -0
  153. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/rollup.config.js +0 -0
  154. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/scripts/postpublish.js +0 -0
  155. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/scripts/prepublish-only.js +0 -0
  156. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/index.ts +0 -0
  157. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/shim-translate.d.ts +0 -0
  158. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/shim-vue.d.ts +0 -0
  159. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/tsconfig.json +0 -0
  160. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/index.ts +0 -0
  161. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/package.json +0 -0
  162. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/rollup.config.js +0 -0
  163. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/scripts/postpublish.js +0 -0
  164. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/scripts/prepublish-only.js +0 -0
  165. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/index.ts +0 -0
  166. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/shim-translate.d.ts +0 -0
  167. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/shim-vue.d.ts +0 -0
  168. /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/tsconfig.json +0 -0
  169. /package/{template-6.4.0-community → template-6.4.0}/pnpm-workspace.yaml +0 -0
  170. /package/{template-6.4.0-community → template-6.4.0}/scripts/build/inset-tsconfig.js +0 -0
  171. /package/{template-6.4.0-community → template-6.4.0}/scripts/build/package-name.js +0 -0
  172. /package/{template-6.4.0-community → template-6.4.0}/scripts/build/postbuild.js +0 -0
  173. /package/{template-6.4.0-community → template-6.4.0}/scripts/build/prebuild-only.js +0 -0
  174. /package/{template-6.4.0-community → template-6.4.0}/scripts/clean.mjs +0 -0
  175. /package/{template-6.4.0-enterprise → template-7.2.0}/.prettierrc.json +0 -0
  176. /package/{template-6.4.0-enterprise → template-7.2.0}/README.md +0 -0
  177. /package/{template-7.2.0-community → template-7.2.0}/_package.json +0 -0
  178. /package/{template-7.2.0-community → template-7.2.0}/eslint.config.ts +0 -0
  179. /package/{template-6.4.0-enterprise → template-7.2.0}/gitignore +0 -0
  180. /package/{template-6.4.0-enterprise → template-7.2.0}/lerna.json +0 -0
  181. /package/{template-7.2.0-community → template-7.2.0}/npmrc +0 -0
  182. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/index.ts +0 -0
  183. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/package.json +0 -0
  184. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/rollup.config.js +0 -0
  185. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/scripts/postpublish.js +0 -0
  186. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/scripts/prepublish-only.js +0 -0
  187. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/index.ts +0 -0
  188. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/shim-translate.d.ts +0 -0
  189. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/shim-vue.d.ts +0 -0
  190. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/tsconfig.json +0 -0
  191. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/.env +0 -0
  192. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/.env.example +0 -0
  193. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/package.json +0 -0
  194. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/public/favicon.ico +0 -0
  195. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/public/index.html +0 -0
  196. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/public/manifest.js +0 -0
  197. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/src/main.ts +0 -0
  198. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/src/shim-translate.d.ts +0 -0
  199. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/src/shim-vue.d.ts +0 -0
  200. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/tsconfig.json +0 -0
  201. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/index.ts +0 -0
  202. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-oinone/package.json +0 -0
  203. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-oinone/rollup.config.js +0 -0
  204. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/scripts/postpublish.js +0 -0
  205. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/scripts/prepublish-only.js +0 -0
  206. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/index.ts +0 -0
  207. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/shim-translate.d.ts +0 -0
  208. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/shim-vue.d.ts +0 -0
  209. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-oinone/tsconfig.json +0 -0
  210. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/index.ts +0 -0
  211. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-project/package.json +0 -0
  212. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-project/rollup.config.js +0 -0
  213. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/scripts/postpublish.js +0 -0
  214. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/scripts/prepublish-only.js +0 -0
  215. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/index.ts +0 -0
  216. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/shim-translate.d.ts +0 -0
  217. /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/shim-vue.d.ts +0 -0
  218. /package/{template-7.2.0-community → template-7.2.0}/packages/ss-project/tsconfig.json +0 -0
  219. /package/{template-6.4.0-enterprise → template-7.2.0}/pnpm-workspace.yaml +0 -0
  220. /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/build/inset-tsconfig.js +0 -0
  221. /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/build/package-name.js +0 -0
  222. /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/clean.mjs +0 -0
package/bin/cli.js CHANGED
@@ -1,491 +1,67 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { program } = require('commander');
4
- const inquirer = require('inquirer');
5
- const fs = require('fs-extra');
6
- const path = require('path');
7
4
  const chalk = require('chalk');
8
- const ora = require('ora');
9
- const https = require('https');
10
- const os = require('os');
11
- const AdmZip = require('adm-zip');
12
- const cliProgress = require('cli-progress');
13
5
  const packageJson = require('../package.json');
6
+ const { setLang, t } = require('./i18n');
14
7
 
15
- const downloadAndExtractZip = (url, targetDir) => {
16
- return new Promise((resolve, reject) => {
17
- const req = https.request(url, { method: 'HEAD' }, (headRes) => {
18
- // 必须调用 resume() 消费响应数据,否则 Node 19+ 默认开启 keepAlive 会导致 socket 保持连接,进程卡住 60 秒
19
- headRes.resume();
20
-
21
- if (headRes.statusCode !== 200) {
22
- reject(new Error(`Failed to fetch file info: ${headRes.statusCode}`));
23
- return;
24
- }
25
-
26
- let etag = headRes.headers['etag'];
27
- if (etag) {
28
- etag = etag.replace(/"/g, ''); // Clean quotes
29
- } else {
30
- etag = headRes.headers['last-modified'] ? Buffer.from(headRes.headers['last-modified']).toString('hex') : 'default';
31
- }
32
-
33
- const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
34
- fs.ensureDirSync(cacheDir);
35
-
36
- const cachedZipPath = path.join(cacheDir, `static-resources-${etag}.zip`);
37
-
38
- if (fs.existsSync(cachedZipPath)) {
39
- console.log(chalk.cyan('⚡ Zap! Using cached static resources...'));
40
- try {
41
- const zip = new AdmZip(cachedZipPath);
42
- zip.extractAllTo(targetDir, true);
43
- resolve();
44
- } catch (err) {
45
- fs.unlinkSync(cachedZipPath);
46
- reject(err);
47
- }
48
- return;
49
- }
50
-
51
- const file = fs.createWriteStream(cachedZipPath);
52
-
53
- https.get(url, (response) => {
54
- if (response.statusCode !== 200) {
55
- response.resume(); // 消费响应数据释放 socket
56
- reject(new Error(`Failed to download: ${response.statusCode}`));
57
- return;
58
- }
59
-
60
- const totalBytes = parseInt(response.headers['content-length'], 10);
61
- let isMB = false;
62
- let totalDisplay = 0;
63
- let unit = 'KB';
64
-
65
- if (totalBytes > 10 * 1024 * 1024) {
66
- isMB = true;
67
- unit = 'MB';
68
- totalDisplay = (totalBytes / (1024 * 1024)).toFixed(2);
69
- } else {
70
- totalDisplay = Math.round(totalBytes / 1024);
71
- }
72
-
73
- let downloadedBytes = 0;
74
- let startTime = Date.now();
75
-
76
- const progressBar = new cliProgress.SingleBar({
77
- format: chalk.cyan('🚀 Fetching awesomeness ') + `[{bar}] {percentage}% | ⏳ {eta}s left | 📦 {value}/{total} ${unit} | 💨 {speed} {speedUnit}/s`,
78
- barCompleteChar: '\u2588',
79
- barIncompleteChar: '\u2591',
80
- hideCursor: true,
81
- forceRedraw: true
82
- });
83
-
84
- progressBar.start(Number(totalDisplay), 0, { speed: '0.00', speedUnit: 'KB' });
85
-
86
- response.on('data', (chunk) => {
87
- downloadedBytes += chunk.length;
88
- let downloadedDisplay = 0;
89
- if (isMB) {
90
- downloadedDisplay = Number((downloadedBytes / (1024 * 1024)).toFixed(2));
91
- } else {
92
- downloadedDisplay = Math.round(downloadedBytes / 1024);
93
- }
94
-
95
- const currentTime = Date.now();
96
- const elapsedSeconds = (currentTime - startTime) / 1000;
97
- let speed = 0;
98
- let speedUnit = 'KB';
99
-
100
- if (elapsedSeconds > 0) {
101
- const speedInBytes = downloadedBytes / elapsedSeconds;
102
- if (speedInBytes > 1024 * 1024) {
103
- speed = speedInBytes / (1024 * 1024);
104
- speedUnit = 'MB';
105
- } else {
106
- speed = speedInBytes / 1024;
107
- speedUnit = 'KB';
108
- }
109
- }
110
-
111
- progressBar.update(downloadedDisplay, { speed: speed.toFixed(2), speedUnit });
112
- });
113
-
114
- response.pipe(file);
115
- file.on('finish', () => {
116
- progressBar.stop();
117
- file.close();
118
- try {
119
- const zip = new AdmZip(cachedZipPath);
120
- zip.extractAllTo(targetDir, true);
121
- resolve();
122
- } catch (err) {
123
- if (fs.existsSync(cachedZipPath)) fs.unlinkSync(cachedZipPath);
124
- reject(err);
125
- }
126
- });
127
- }).on('error', (err) => {
128
- if (fs.existsSync(cachedZipPath)) fs.unlink(cachedZipPath, () => {});
129
- reject(err);
130
- });
131
- });
132
-
133
- req.on('error', (err) => {
134
- reject(err);
135
- });
136
-
137
- req.end();
138
- });
139
- };
8
+ const createAction = require('./commands/create');
9
+ const setupCacheCommand = require('./commands/cache');
10
+ const doctorAction = require('./commands/doctor');
140
11
 
141
12
  program
142
- .version(packageJson.version)
143
- .description('Oinone Frontend Template CLI')
144
- .helpOption('-h, --help', 'display help for command');
13
+ .name('oinone-frontend')
14
+ .description(t('cli.description'))
15
+ .version(packageJson.version, '-v, --version', t('cli.versionOption'))
16
+ .helpOption('-h, --help', t('cli.helpOption'));
145
17
 
146
- // Cache Command
147
- const cacheCmd = program
148
- .command('cache')
149
- .description('Manage the local static resources cache')
150
- .action(() => {
151
- // If just "cache" is typed without subcommands, show cache help
152
- cacheCmd.help();
153
- });
18
+ program
19
+ .option('-l, --lang <lang>', 'Specify language (zh-CN or en-US)')
20
+ ;
154
21
 
155
- cacheCmd
156
- .command('clean')
157
- .description('Clean the local static resources cache')
158
- .action(() => {
159
- const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
160
- if (fs.existsSync(cacheDir)) {
161
- fs.removeSync(cacheDir);
162
- console.log(chalk.green(`✨ Whoosh! Cache swept clean at ${cacheDir}`));
163
- } else {
164
- console.log(chalk.yellow(`🤷 Cache directory already vanished (or never existed): ${cacheDir}`));
165
- }
166
- });
22
+ program.hook('preAction', (thisCommand) => {
23
+ const opts = thisCommand.opts();
24
+ setLang(opts.lang);
25
+ });
167
26
 
168
- cacheCmd
169
- .command('info')
170
- .description('Print cache directory information')
171
- .action(async () => {
172
- const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
173
- console.log(chalk.cyan('📂 Cache Directory: ') + cacheDir);
174
-
175
- if (fs.existsSync(cacheDir)) {
176
- const files = await fs.readdir(cacheDir);
177
- let totalSize = 0;
178
-
179
- console.log(chalk.cyan('📦 Cached Files:'));
180
- for (const file of files) {
181
- const filePath = path.join(cacheDir, file);
182
- const stat = await fs.stat(filePath);
183
- totalSize += stat.size;
184
-
185
- let displaySize = '';
186
- if (stat.size > 1024 * 1024) {
187
- displaySize = `${(stat.size / (1024 * 1024)).toFixed(2)} MB`;
188
- } else {
189
- displaySize = `${Math.round(stat.size / 1024)} KB`;
190
- }
191
-
192
- console.log(` - 📄 ${file} (${displaySize})`);
193
- }
194
-
195
- let totalDisplaySize = '';
196
- if (totalSize > 1024 * 1024) {
197
- totalDisplaySize = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
198
- } else {
199
- totalDisplaySize = `${Math.round(totalSize / 1024)} KB`;
200
- }
201
-
202
- console.log(chalk.cyan(`\n📊 Total Cache Size: `) + totalDisplaySize);
203
- } else {
204
- console.log(chalk.yellow('🍃 Cache is currently as empty as space.'));
205
- }
27
+ program
28
+ .command('create [projectName]')
29
+ .description(t('create.createCmdDesc'))
30
+ .option('--company-name <name>', 'Company/Organization name (silent mode)')
31
+ .option('--project-name <name>', 'Project name (silent mode)')
32
+ .option('--download-static-resource <boolean>', t('cli.downloadOpt'))
33
+ .option('-o, --oinone-version <version>', t('cli.versionOpt'))
34
+ .option('-e, --edition <edition>', t('cli.editionOpt'))
35
+ .option('--auth-token <token>', 'Oinone registry auth token (for enterprise edition)')
36
+ .option('--write-project-credential', 'Allow writing credentials to project directory')
37
+ .option('-f, --force', 'Overwrite target directory if it exists')
38
+ .option('-d, --dry-run', 'Skip writing files to disk')
39
+ .action((projectNameArg, options, command) => {
40
+ const mergedOptions = { ...program.opts(), ...options };
41
+ return createAction(projectNameArg, mergedOptions);
206
42
  });
207
43
 
208
- // Create Command (Default Behavior)
209
44
  program
210
- .argument('[project-name]', 'Name of the project to create silently')
211
- .option('--download-static-resource <value>', 'Download static resources (true/false)', 'true')
212
- .option('--oinone-version <value>', 'Oinone version to use (e.g. 7.2.0, 6.4.0)', '7.2.0')
213
- .option('--edition <value>', 'Oinone edition to use (community/enterprise)', 'community')
214
- .action(async (projectNameArg, options) => {
215
- // If command is 'cache', skip create logic
216
- if (projectNameArg === 'cache') {
217
- return;
218
- }
219
-
220
- // Trigger version check without blocking
221
- let checkReq = null;
222
- const versionCheckPromise = new Promise((resolve) => {
223
- checkReq = https.get('https://registry.npmjs.org/-/package/@oinone/cli/dist-tags', { timeout: 3000 }, (res) => {
224
- let data = '';
225
- res.on('data', chunk => data += chunk);
226
- res.on('end', () => {
227
- try {
228
- const parsed = JSON.parse(data);
229
- resolve(parsed.latest);
230
- } catch (e) {
231
- resolve(null);
232
- }
233
- });
234
- });
235
- checkReq.on('timeout', () => {
236
- checkReq.destroy();
237
- resolve(null);
238
- });
239
- checkReq.on('error', () => {
240
- resolve(null);
241
- });
242
- });
243
-
244
- try {
245
- let prefix;
246
- let fullProjectName;
247
- let oinoneVersion;
248
- let edition;
249
- let downloadStaticResources;
250
-
251
- if (projectNameArg) {
252
- // Remove '-frontend' suffix if it exists to form the prefix
253
- prefix = projectNameArg.endsWith('-frontend')
254
- ? projectNameArg.slice(0, -9)
255
- : projectNameArg;
256
- fullProjectName = projectNameArg;
257
- oinoneVersion = options.oinoneVersion;
258
- // Ensure oinoneVersion has a tilde prefix
259
- if (!oinoneVersion.startsWith('~')) {
260
- oinoneVersion = `~${oinoneVersion}`;
261
- }
262
- edition = options.edition;
263
- downloadStaticResources = options.downloadStaticResource !== 'false';
264
- } else {
265
- const answers = await inquirer.prompt([
266
- {
267
- type: 'input',
268
- name: 'companyName',
269
- message: '🏢 What is your awesome company/org name? (e.g. ss):',
270
- default: 'ss',
271
- validate: (input) => {
272
- if (input.trim() === '') return 'Oops! Company name cannot be empty 🙈';
273
- return true;
274
- },
275
- },
276
- {
277
- type: 'input',
278
- name: 'projectName',
279
- message: '🚀 Name your epic project (e.g. oms):',
280
- default: 'oms',
281
- validate: (input) => {
282
- if (input.trim() === '') return 'Hold on! Project name cannot be empty 🛑';
283
- return true;
284
- },
285
- },
286
- {
287
- type: 'list',
288
- name: 'edition',
289
- message: '💎 Choose your Oinone flavor:',
290
- choices: [
291
- { name: '🌱 Community Edition (Default)', value: 'community' },
292
- { name: '👑 Enterprise Edition', value: 'enterprise' }
293
- ],
294
- default: 'community'
295
- },
296
- {
297
- type: 'list',
298
- name: 'oinoneVersion',
299
- message: '📦 Which Oinone version are we rocking today?',
300
- choices: [
301
- { name: '✨ 7.2.0 (Default)', value: '~7.2.0' },
302
- { name: '🕰️ 6.4.0', value: '~6.4.0' }
303
- ],
304
- default: '~7.2.0'
305
- },
306
- {
307
- type: 'confirm',
308
- name: 'downloadStaticResources',
309
- message: '📥 Shall we fetch the latest static resources for you? (Highly recommended! 🌟)',
310
- default: true
311
- }
312
- ]);
313
-
314
- prefix = answers.companyName;
315
- fullProjectName = `${answers.companyName}-${answers.projectName}-frontend`;
316
- oinoneVersion = answers.oinoneVersion;
317
- edition = answers.edition;
318
- downloadStaticResources = answers.downloadStaticResources;
319
- }
320
-
321
- const targetPath = path.resolve(process.cwd(), fullProjectName);
322
-
323
- if (fs.existsSync(targetPath)) {
324
- console.log(chalk.red(`\n🚫 Yikes! The directory ${fullProjectName} already exists. Try a different name or clear the path.\n`));
325
- process.exit(1);
326
- }
327
-
328
- const spinner = ora('✨ Weaving magic to create your project...').start();
329
-
330
- const versionDir = oinoneVersion.replace(/[^0-9.]/g, ''); // Extract '7.2.0' or '6.4.0'
331
- const templatePath = path.resolve(__dirname, `../template-${versionDir}-${edition}`);
332
-
333
- if (!fs.existsSync(templatePath)) {
334
- spinner.fail(chalk.red(`😢 Uh-oh! Template for version ${oinoneVersion} (${edition} edition) went missing in action.`));
335
- process.exit(1);
336
- }
337
-
338
- // Helper function to process files recursively
339
- const processDirectory = async (dirPath) => {
340
- const files = await fs.readdir(dirPath);
341
- for (const file of files) {
342
- const currentPath = path.join(dirPath, file);
343
- const stat = await fs.stat(currentPath);
344
-
345
- // Rename directory if it starts with 'ss-'
346
- let newPath = currentPath;
347
- if (file.startsWith('ss-')) {
348
- const newFile = file.replace(/^ss-/, `${prefix}-`);
349
- newPath = path.join(dirPath, newFile);
350
- await fs.rename(currentPath, newPath);
351
- }
352
-
353
- if (stat.isDirectory()) {
354
- await processDirectory(newPath);
355
- } else {
356
- // Check if it's a text file
357
- const ext = path.extname(newPath);
358
- const isTextFile = !['.png', '.ico', '.jpg', '.jpeg', '.gif'].includes(ext);
359
-
360
- if (isTextFile) {
361
- let content = await fs.readFile(newPath, 'utf8');
362
- let hasChanges = false;
363
-
364
- // Replace 'ss-' with '${prefix}-' but avoid replacing within words
365
- // We use a regex that matches 'ss-' either at the start of a string or preceded by non-word characters
366
- // To prevent changing things like postcss -> postprefix
367
- const regex = /(^|[^a-zA-Z])ss-/g;
368
- if (regex.test(content)) {
369
- content = content.replace(regex, `$1${prefix}-`);
370
- hasChanges = true;
371
- }
372
-
373
- // Replace '@ss/oinone' with `@${prefix}/oinone`
374
- if (content.includes('@ss/')) {
375
- content = content.replace(/@ss\//g, `@${prefix}/`);
376
- hasChanges = true;
377
- }
378
-
379
- if (hasChanges) {
380
- await fs.writeFile(newPath, content, 'utf8');
381
- }
382
- }
383
- }
384
- }
385
- };
386
-
387
- // Copy template files
388
- await fs.copy(templatePath, targetPath, {
389
- filter: (src) => {
390
- // Ignore node_modules just in case
391
- const relativePath = path.relative(templatePath, src);
392
- if (relativePath.split(path.sep).includes('node_modules')) return false;
393
- return true;
394
- }
395
- });
396
-
397
- // Process the copied files (rename and replace content)
398
- await processDirectory(targetPath);
399
-
400
- // Handle package.json
401
- const pkgPath = path.join(targetPath, '_package.json');
402
- const newPkgPath = path.join(targetPath, 'package.json');
403
- if (fs.existsSync(pkgPath)) {
404
- const pkgContent = await fs.readJson(pkgPath);
405
- pkgContent.name = fullProjectName;
406
- await fs.writeJson(newPkgPath, pkgContent, { spaces: 2 });
407
- await fs.remove(pkgPath);
408
- }
409
-
410
- // Handle gitignore
411
- const gitignorePath = path.join(targetPath, 'gitignore');
412
- const newGitignorePath = path.join(targetPath, '.gitignore');
413
- if (fs.existsSync(gitignorePath)) {
414
- await fs.move(gitignorePath, newGitignorePath);
415
- }
416
-
417
- // Handle npmrc
418
- const npmrcPath = path.join(targetPath, 'npmrc');
419
- const newNpmrcPath = path.join(targetPath, '.npmrc');
420
- if (fs.existsSync(npmrcPath)) {
421
- await fs.move(npmrcPath, newNpmrcPath);
422
- }
423
-
424
- if (downloadStaticResources) {
425
- spinner.succeed(chalk.green('🎉 Boom! Project structure is ready!'));
426
- console.log(chalk.cyan('🚚 Hauling in the static resources...'));
427
- try {
428
- const ossDir = path.join(targetPath, 'packages', `${prefix}-boot`, 'public', 'oss');
429
- await fs.ensureDir(ossDir);
430
- await downloadAndExtractZip('https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip', ossDir);
431
- console.log(chalk.green('🎯 Bullseye! Static resources downloaded and ready to roll!'));
432
- } catch (err) {
433
- console.log(chalk.yellow(`⚠️ Project is ready, but the static resources had a hiccup: ${err.message}`));
434
- }
435
- } else {
436
- spinner.succeed(chalk.green('🎉 Boom! Project created successfully!'));
437
- const relativeOssDir = `packages/${prefix}-boot/public/oss`;
438
- console.log(chalk.yellow(`\n⚠️ You chose to skip the static resources download.`));
439
- console.log(chalk.yellow(`Don't forget to grab them manually before you fire up the project:`));
440
- console.log(chalk.cyan(` mkdir -p ${fullProjectName}/${relativeOssDir}`));
441
- console.log(chalk.cyan(` curl -L https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip -o static-resources.zip`));
442
- console.log(chalk.cyan(` unzip static-resources.zip -d ${fullProjectName}/${relativeOssDir}`));
443
- console.log(chalk.cyan(` rm static-resources.zip`));
444
- }
445
-
446
- console.log(`\n🚀 Let's get this party started:\n`);
447
- console.log(chalk.cyan(` cd ${fullProjectName}`));
448
- console.log(chalk.cyan(` pnpm install`));
449
- console.log(chalk.cyan(` pnpm run dev\n`));
450
- console.log(chalk.magenta(`Happy coding! 💻☕\n`));
45
+ .command('doctor')
46
+ .description(t('doctor.doctorCmdDesc'))
47
+ .option('-o, --oinone-version <version>', t('cli.versionOpt'))
48
+ .action((...args) => {
49
+ const cmd = args[args.length - 1];
50
+ const mergedOptions = { ...program.opts(), ...(cmd && typeof cmd.opts === 'function' ? cmd.opts() : {}) };
51
+ return doctorAction(mergedOptions);
52
+ });
451
53
 
452
- try {
453
- const latestVersion = await Promise.race([
454
- versionCheckPromise,
455
- new Promise(resolve => setTimeout(() => {
456
- if (checkReq) checkReq.destroy();
457
- resolve(null);
458
- }, 1000))
459
- ]);
54
+ setupCacheCommand();
460
55
 
461
- if (latestVersion) {
462
- const isNewerVersion = (current, latest) => {
463
- const c = current.replace(/[^0-9.]/g, '').split('.').map(Number);
464
- const l = latest.replace(/[^0-9.]/g, '').split('.').map(Number);
465
- for (let i = 0; i < Math.max(c.length, l.length); i++) {
466
- const numC = c[i] || 0;
467
- const numL = l[i] || 0;
468
- if (numL > numC) return true;
469
- if (numL < numC) return false;
470
- }
471
- return false;
472
- };
473
-
474
- if (isNewerVersion(packageJson.version, latestVersion)) {
475
- console.log(chalk.yellow(`====================================================`));
476
- console.log(chalk.yellow(`📦 Update available! ${chalk.red(packageJson.version)} → ${chalk.green(latestVersion)}`));
477
- console.log(chalk.yellow(`Run ${chalk.cyan('npm install -g @oinone/cli')} to update.`));
478
- console.log(chalk.yellow(`====================================================\n`));
479
- }
480
- }
481
- } catch (e) {
482
- // ignore errors
483
- }
56
+ program.on('command:*', (operands) => {
57
+ const first = Array.isArray(operands) && operands.length > 0 ? operands[0] : '';
58
+ console.log(chalk.red(t('cli.requireCreateSubcommand', { cmd: first })));
59
+ process.exit(1);
60
+ });
484
61
 
485
- } catch (error) {
486
- console.error(chalk.red(`\n💥 Oops! Something broke: ${error.message}\n`));
487
- process.exit(1);
488
- }
489
- });
62
+ if (process.argv.length <= 2) {
63
+ program.outputHelp();
64
+ process.exit(0);
65
+ }
490
66
 
491
67
  program.parse(process.argv);
@@ -0,0 +1,70 @@
1
+ const { program } = require('commander');
2
+ const fs = require('fs-extra');
3
+ const path = require('path');
4
+ const os = require('os');
5
+ const chalk = require('chalk');
6
+ const { t } = require('../i18n');
7
+
8
+ function setupCacheCommand() {
9
+ const cacheCmd = program
10
+ .command('cache')
11
+ .description(t('cache.cacheCmdDesc'))
12
+ .action(() => {
13
+ cacheCmd.help();
14
+ });
15
+
16
+ cacheCmd
17
+ .command('clean')
18
+ .description(t('cache.cacheCleanDesc'))
19
+ .action(() => {
20
+ const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
21
+ if (fs.existsSync(cacheDir)) {
22
+ fs.removeSync(cacheDir);
23
+ console.log(chalk.green(t('cache.cacheCleaned', { dir: cacheDir })));
24
+ } else {
25
+ console.log(chalk.yellow(t('cache.cacheAlreadyEmpty', { dir: cacheDir })));
26
+ }
27
+ });
28
+
29
+ cacheCmd
30
+ .command('info')
31
+ .description(t('cache.cacheInfoDesc'))
32
+ .action(async () => {
33
+ const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
34
+ console.log(chalk.cyan(t('cache.cacheDir')) + cacheDir);
35
+
36
+ if (fs.existsSync(cacheDir)) {
37
+ const files = await fs.readdir(cacheDir);
38
+ let totalSize = 0;
39
+
40
+ console.log(chalk.cyan(t('cache.cachedFiles')));
41
+ for (const file of files) {
42
+ const filePath = path.join(cacheDir, file);
43
+ const stat = await fs.stat(filePath);
44
+ totalSize += stat.size;
45
+
46
+ let displaySize = '';
47
+ if (stat.size > 1024 * 1024) {
48
+ displaySize = `${(stat.size / (1024 * 1024)).toFixed(2)} MB`;
49
+ } else {
50
+ displaySize = `${Math.round(stat.size / 1024)} KB`;
51
+ }
52
+
53
+ console.log(` - 📄 ${file} (${displaySize})`);
54
+ }
55
+
56
+ let totalDisplaySize = '';
57
+ if (totalSize > 1024 * 1024) {
58
+ totalDisplaySize = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
59
+ } else {
60
+ totalDisplaySize = `${Math.round(totalSize / 1024)} KB`;
61
+ }
62
+
63
+ console.log(chalk.cyan(t('cache.totalCacheSize')) + totalDisplaySize);
64
+ } else {
65
+ console.log(chalk.yellow(t('cache.cacheEmpty')));
66
+ }
67
+ });
68
+ }
69
+
70
+ module.exports = setupCacheCommand;