@ohos-ports/tarojs-cli 0.0.0-stage → 4.3.0-beta.1

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 (223) hide show
  1. package/LICENSE +174 -0
  2. package/README.md +0 -3
  3. package/bin/taro +7 -0
  4. package/dist/cli.d.ts +6 -0
  5. package/dist/cli.js +252 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/customCommand.d.ts +5 -0
  8. package/dist/commands/customCommand.js +23 -0
  9. package/dist/commands/customCommand.js.map +1 -0
  10. package/dist/config/index.d.ts +8 -0
  11. package/dist/config/index.js +10 -0
  12. package/dist/config/index.js.map +1 -0
  13. package/dist/config/packagesManagement.d.ts +19 -0
  14. package/dist/config/packagesManagement.js +22 -0
  15. package/dist/config/packagesManagement.js.map +1 -0
  16. package/dist/create/constants.d.ts +1 -0
  17. package/dist/create/constants.js +5 -0
  18. package/dist/create/constants.js.map +1 -0
  19. package/dist/create/creator.d.ts +9 -0
  20. package/dist/create/creator.js +31 -0
  21. package/dist/create/creator.js.map +1 -0
  22. package/dist/create/fetchTemplate.d.ts +8 -0
  23. package/dist/create/fetchTemplate.js +137 -0
  24. package/dist/create/fetchTemplate.js.map +1 -0
  25. package/dist/create/page.d.ts +65 -0
  26. package/dist/create/page.js +252 -0
  27. package/dist/create/page.js.map +1 -0
  28. package/dist/create/plugin.d.ts +16 -0
  29. package/dist/create/plugin.js +48 -0
  30. package/dist/create/plugin.js.map +1 -0
  31. package/dist/create/project.d.ts +80 -0
  32. package/dist/create/project.js +519 -0
  33. package/dist/create/project.js.map +1 -0
  34. package/dist/doctor/index.d.ts +4 -0
  35. package/dist/doctor/index.js +32 -0
  36. package/dist/doctor/index.js.map +1 -0
  37. package/dist/index.d.ts +16 -0
  38. package/dist/index.js +21 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/presets/commands/build.d.ts +3 -0
  41. package/dist/presets/commands/build.js +239 -0
  42. package/dist/presets/commands/build.js.map +1 -0
  43. package/dist/presets/commands/config.d.ts +3 -0
  44. package/dist/presets/commands/config.js +88 -0
  45. package/dist/presets/commands/config.js.map +1 -0
  46. package/dist/presets/commands/create.d.ts +3 -0
  47. package/dist/presets/commands/create.js +91 -0
  48. package/dist/presets/commands/create.js.map +1 -0
  49. package/dist/presets/commands/global-config.d.ts +3 -0
  50. package/dist/presets/commands/global-config.js +139 -0
  51. package/dist/presets/commands/global-config.js.map +1 -0
  52. package/dist/presets/commands/help.d.ts +3 -0
  53. package/dist/presets/commands/help.js +29 -0
  54. package/dist/presets/commands/help.js.map +1 -0
  55. package/dist/presets/commands/info.d.ts +3 -0
  56. package/dist/presets/commands/info.js +79 -0
  57. package/dist/presets/commands/info.js.map +1 -0
  58. package/dist/presets/commands/init.d.ts +3 -0
  59. package/dist/presets/commands/init.js +59 -0
  60. package/dist/presets/commands/init.js.map +1 -0
  61. package/dist/presets/commands/inspect.d.ts +3 -0
  62. package/dist/presets/commands/inspect.js +118 -0
  63. package/dist/presets/commands/inspect.js.map +1 -0
  64. package/dist/presets/commands/update.d.ts +3 -0
  65. package/dist/presets/commands/update.js +171 -0
  66. package/dist/presets/commands/update.js.map +1 -0
  67. package/dist/presets/constant/hooks.d.ts +13 -0
  68. package/dist/presets/constant/hooks.js +17 -0
  69. package/dist/presets/constant/hooks.js.map +1 -0
  70. package/dist/presets/constant/index.d.ts +1 -0
  71. package/dist/presets/constant/index.js +18 -0
  72. package/dist/presets/constant/index.js.map +1 -0
  73. package/dist/presets/files/generateFrameworkInfo.d.ts +3 -0
  74. package/dist/presets/files/generateFrameworkInfo.js +30 -0
  75. package/dist/presets/files/generateFrameworkInfo.js.map +1 -0
  76. package/dist/presets/files/generateProjectConfig.d.ts +3 -0
  77. package/dist/presets/files/generateProjectConfig.js +40 -0
  78. package/dist/presets/files/generateProjectConfig.js.map +1 -0
  79. package/dist/presets/files/writeFileToDist.d.ts +3 -0
  80. package/dist/presets/files/writeFileToDist.js +17 -0
  81. package/dist/presets/files/writeFileToDist.js.map +1 -0
  82. package/dist/presets/hooks/build.d.ts +3 -0
  83. package/dist/presets/hooks/build.js +22 -0
  84. package/dist/presets/hooks/build.js.map +1 -0
  85. package/dist/presets/hooks/create.d.ts +3 -0
  86. package/dist/presets/hooks/create.js +11 -0
  87. package/dist/presets/hooks/create.js.map +1 -0
  88. package/dist/presets/index.d.ts +4 -0
  89. package/dist/presets/index.js +17 -0
  90. package/dist/presets/index.js.map +1 -0
  91. package/dist/presets/platforms/plugin.d.ts +3 -0
  92. package/dist/presets/platforms/plugin.js +76 -0
  93. package/dist/presets/platforms/plugin.js.map +1 -0
  94. package/dist/presets/platforms/rn.d.ts +3 -0
  95. package/dist/presets/platforms/rn.js +101 -0
  96. package/dist/presets/platforms/rn.js.map +1 -0
  97. package/dist/util/appConfig.d.ts +11 -0
  98. package/dist/util/appConfig.js +25 -0
  99. package/dist/util/appConfig.js.map +1 -0
  100. package/dist/util/createPage.d.ts +9 -0
  101. package/dist/util/createPage.js +117 -0
  102. package/dist/util/createPage.js.map +1 -0
  103. package/dist/util/defineConfig.d.ts +17 -0
  104. package/dist/util/defineConfig.js +12 -0
  105. package/dist/util/defineConfig.js.map +1 -0
  106. package/dist/util/index.d.ts +23 -0
  107. package/dist/util/index.js +125 -0
  108. package/dist/util/index.js.map +1 -0
  109. package/dist/util/types.d.ts +58 -0
  110. package/dist/util/types.js +3 -0
  111. package/dist/util/types.js.map +1 -0
  112. package/global.d.ts +4 -0
  113. package/index.js +3 -0
  114. package/package.json +76 -4
  115. package/postinstall.js +14 -0
  116. package/src/__tests__/__mocks__/presets.ts +15 -0
  117. package/src/__tests__/build-config.spec.ts +99 -0
  118. package/src/__tests__/cli.spec.ts +233 -0
  119. package/src/__tests__/config.spec.ts +232 -0
  120. package/src/__tests__/doctor-config.spec.ts +805 -0
  121. package/src/__tests__/doctor-eslint.spec.ts +31 -0
  122. package/src/__tests__/doctor-recommand.spec.ts +158 -0
  123. package/src/__tests__/doctor.spec.ts +77 -0
  124. package/src/__tests__/dotenv-parse.spec.ts +105 -0
  125. package/src/__tests__/env/.env +2 -0
  126. package/src/__tests__/fixtures/default/.env +3 -0
  127. package/src/__tests__/fixtures/default/.env.development +1 -0
  128. package/src/__tests__/fixtures/default/.env.local +1 -0
  129. package/src/__tests__/fixtures/default/.env.pre +3 -0
  130. package/src/__tests__/fixtures/default/.env.production +1 -0
  131. package/src/__tests__/fixtures/default/.env.uat +5 -0
  132. package/src/__tests__/fixtures/default/.env.uat.local +1 -0
  133. package/src/__tests__/fixtures/default/babel.config.js +10 -0
  134. package/src/__tests__/fixtures/default/config/dev.js +9 -0
  135. package/src/__tests__/fixtures/default/config/index.js +84 -0
  136. package/src/__tests__/fixtures/default/config/prod.js +18 -0
  137. package/src/__tests__/fixtures/default/package.json +38 -0
  138. package/src/__tests__/fixtures/default/src/app.config.js +11 -0
  139. package/src/__tests__/fixtures/default/src/app.js +16 -0
  140. package/src/__tests__/fixtures/default/src/app.scss +0 -0
  141. package/src/__tests__/fixtures/default/src/index.html +19 -0
  142. package/src/__tests__/fixtures/default/src/pages/index/index.config.js +3 -0
  143. package/src/__tests__/fixtures/default/src/pages/index/index.jsx +22 -0
  144. package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
  145. package/src/__tests__/info.spec.ts +74 -0
  146. package/src/__tests__/inspect.spec.ts +163 -0
  147. package/src/__tests__/project.spec.ts +304 -0
  148. package/src/__tests__/update.spec.ts +324 -0
  149. package/src/__tests__/utils/index.ts +54 -0
  150. package/src/cli.ts +250 -0
  151. package/src/commands/customCommand.ts +26 -0
  152. package/src/config/index.ts +7 -0
  153. package/src/config/manifest.default.json +35 -0
  154. package/src/config/packagesManagement.ts +20 -0
  155. package/src/config/rn-stylelint.json +5 -0
  156. package/src/config/tsconfig.json +24 -0
  157. package/src/create/constants.ts +1 -0
  158. package/src/create/creator.ts +37 -0
  159. package/src/create/fetchTemplate.ts +152 -0
  160. package/src/create/page.ts +299 -0
  161. package/src/create/plugin.ts +55 -0
  162. package/src/create/project.ts +591 -0
  163. package/src/doctor/index.ts +27 -0
  164. package/src/index.ts +24 -0
  165. package/src/presets/commands/build.ts +227 -0
  166. package/src/presets/commands/config.ts +86 -0
  167. package/src/presets/commands/create.ts +105 -0
  168. package/src/presets/commands/global-config.ts +140 -0
  169. package/src/presets/commands/help.ts +19 -0
  170. package/src/presets/commands/info.ts +77 -0
  171. package/src/presets/commands/init.ts +66 -0
  172. package/src/presets/commands/inspect.ts +138 -0
  173. package/src/presets/commands/update.ts +179 -0
  174. package/src/presets/constant/hooks.ts +14 -0
  175. package/src/presets/constant/index.ts +1 -0
  176. package/src/presets/files/generateFrameworkInfo.ts +30 -0
  177. package/src/presets/files/generateProjectConfig.ts +41 -0
  178. package/src/presets/files/writeFileToDist.ts +17 -0
  179. package/src/presets/hooks/build.ts +22 -0
  180. package/src/presets/hooks/create.ts +11 -0
  181. package/src/presets/index.ts +15 -0
  182. package/src/presets/platforms/plugin.ts +81 -0
  183. package/src/presets/platforms/rn.ts +113 -0
  184. package/src/util/appConfig.ts +29 -0
  185. package/src/util/createPage.ts +132 -0
  186. package/src/util/defineConfig.ts +22 -0
  187. package/src/util/index.ts +127 -0
  188. package/src/util/types.ts +81 -0
  189. package/templates/default/.husky/commit-msg +4 -0
  190. package/templates/default/_editorconfig +12 -0
  191. package/templates/default/_env.development +2 -0
  192. package/templates/default/_env.production +1 -0
  193. package/templates/default/_env.test +1 -0
  194. package/templates/default/_eslintrc +11 -0
  195. package/templates/default/_gitignore +8 -0
  196. package/templates/default/babel.config.js +14 -0
  197. package/templates/default/commitlint.config.mjs +1 -0
  198. package/templates/default/config/dev.js +10 -0
  199. package/templates/default/config/index.js +106 -0
  200. package/templates/default/config/prod.js +46 -0
  201. package/templates/default/package.json.tmpl +158 -0
  202. package/templates/default/project.config.json +15 -0
  203. package/templates/default/src/app.config.js +11 -0
  204. package/templates/default/src/app.css +0 -0
  205. package/templates/default/src/app.js +44 -0
  206. package/templates/default/src/index.html +17 -0
  207. package/templates/default/src/pages/index/index.config.js +3 -0
  208. package/templates/default/src/pages/index/index.css +0 -0
  209. package/templates/default/src/pages/index/index.jsx +15 -0
  210. package/templates/default/src/pages/index/index.vue +23 -0
  211. package/templates/default/stylelint.config.mjs +4 -0
  212. package/templates/default/template_creator.js +77 -0
  213. package/templates/default/tsconfig.json +32 -0
  214. package/templates/default/types/global.d.ts +35 -0
  215. package/templates/default/types/solid.d.ts +12 -0
  216. package/templates/default/types/vue.d.ts +10 -0
  217. package/templates/global-config/index.json +4 -0
  218. package/templates/global-config/package.json +5 -0
  219. package/templates/plugin-compile/README.md +32 -0
  220. package/templates/plugin-compile/index.js +3 -0
  221. package/templates/plugin-compile/package.json.tmpl +43 -0
  222. package/templates/plugin-compile/src/index.ts +153 -0
  223. package/templates/plugin-compile/tsconfig.json +29 -0
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isNil = exports.getPkgNameByFilterVersion = exports.execCommand = exports.clearConsole = exports.printDevelopmentTip = exports.readDirWithFileTypes = exports.getTemplateSourceType = exports.getAllFilesInFolder = exports.printPkgVersion = exports.getPkgItemByKey = exports.getPkgVersion = exports.getRootPath = void 0;
13
+ const path = require("node:path");
14
+ const helper_1 = require("@tarojs/helper");
15
+ const child_process_1 = require("child_process");
16
+ function getRootPath() {
17
+ return path.resolve(__dirname, '../../');
18
+ }
19
+ exports.getRootPath = getRootPath;
20
+ function getPkgVersion() {
21
+ return require(path.join(getRootPath(), 'package.json')).version;
22
+ }
23
+ exports.getPkgVersion = getPkgVersion;
24
+ function getPkgItemByKey(key) {
25
+ const packageMap = require(path.join(getRootPath(), 'package.json'));
26
+ if (Object.keys(packageMap).indexOf(key) === -1) {
27
+ return {};
28
+ }
29
+ else {
30
+ return packageMap[key];
31
+ }
32
+ }
33
+ exports.getPkgItemByKey = getPkgItemByKey;
34
+ function printPkgVersion() {
35
+ const taroVersion = getPkgVersion();
36
+ console.log(`👽 Taro v${taroVersion}`);
37
+ console.log();
38
+ }
39
+ exports.printPkgVersion = printPkgVersion;
40
+ const getAllFilesInFolder = (folder_1, ...args_1) => __awaiter(void 0, [folder_1, ...args_1], void 0, function* (folder, filter = []) {
41
+ let files = [];
42
+ const list = readDirWithFileTypes(folder);
43
+ yield Promise.all(list.map((item) => __awaiter(void 0, void 0, void 0, function* () {
44
+ const itemPath = path.join(folder, item.name);
45
+ if (item.isDirectory) {
46
+ const _files = yield (0, exports.getAllFilesInFolder)(itemPath, filter);
47
+ files = [...files, ..._files];
48
+ }
49
+ else if (item.isFile) {
50
+ if (!filter.find(rule => rule === item.name))
51
+ files.push(itemPath);
52
+ }
53
+ })));
54
+ return files;
55
+ });
56
+ exports.getAllFilesInFolder = getAllFilesInFolder;
57
+ function getTemplateSourceType(url) {
58
+ if (/^github:/.test(url) || /^gitlab:/.test(url) || /^direct:/.test(url)) {
59
+ return 'git';
60
+ }
61
+ else {
62
+ return 'url';
63
+ }
64
+ }
65
+ exports.getTemplateSourceType = getTemplateSourceType;
66
+ function readDirWithFileTypes(folder) {
67
+ const list = helper_1.fs.readdirSync(folder);
68
+ const res = list.map(name => {
69
+ const stat = helper_1.fs.statSync(path.join(folder, name));
70
+ return {
71
+ name,
72
+ isDirectory: stat.isDirectory(),
73
+ isFile: stat.isFile()
74
+ };
75
+ });
76
+ return res;
77
+ }
78
+ exports.readDirWithFileTypes = readDirWithFileTypes;
79
+ function printDevelopmentTip(platform) {
80
+ if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
81
+ let exampleCommand;
82
+ if (helper_1.isWindows) {
83
+ exampleCommand = `$ set NODE_ENV=production && taro build --type ${platform} --watch`;
84
+ }
85
+ else {
86
+ exampleCommand = `$ NODE_ENV=production taro build --type ${platform} --watch`;
87
+ }
88
+ console.log(helper_1.chalk.yellowBright(`Tips: 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
89
+ Example:
90
+ ${exampleCommand}
91
+ `));
92
+ }
93
+ }
94
+ exports.printDevelopmentTip = printDevelopmentTip;
95
+ function clearConsole() {
96
+ const readline = require('readline');
97
+ if (process.stdout.isTTY) {
98
+ const blank = '\n'.repeat(process.stdout.rows);
99
+ console.log(blank);
100
+ readline.cursorTo(process.stdout, 0, 0);
101
+ readline.clearScreenDown(process.stdout);
102
+ }
103
+ }
104
+ exports.clearConsole = clearConsole;
105
+ function execCommand(params) {
106
+ const { command, successCallback, failCallback } = params;
107
+ const child = (0, child_process_1.exec)(command);
108
+ child.stdout.on('data', function (data) {
109
+ successCallback === null || successCallback === void 0 ? void 0 : successCallback(data);
110
+ });
111
+ child.stderr.on('data', function (data) {
112
+ failCallback === null || failCallback === void 0 ? void 0 : failCallback(data);
113
+ });
114
+ }
115
+ exports.execCommand = execCommand;
116
+ function getPkgNameByFilterVersion(pkgString) {
117
+ const versionFlagIndex = pkgString.lastIndexOf('@');
118
+ return versionFlagIndex === 0 ? pkgString : pkgString.slice(0, versionFlagIndex);
119
+ }
120
+ exports.getPkgNameByFilterVersion = getPkgNameByFilterVersion;
121
+ function isNil(value) {
122
+ return value === null || value === undefined;
123
+ }
124
+ exports.isNil = isNil;
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAAiC;AAEjC,2CAAqD;AACrD,iDAAoC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AE,UAAU,IAAI;QACrC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,IAAI,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC;AAbD,kCAaC;AAED,SAAgB,yBAAyB,CAAE,SAAiB;IAC1D,MAAM,gBAAgB,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,OAAO,gBAAgB,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAClF,CAAC;AAHD,8DAGC;AAED,SAAgB,KAAK,CAAE,KAAU;IAC/B,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAA;AAC9C,CAAC;AAFD,sBAEC"}
@@ -0,0 +1,58 @@
1
+ export interface IInstallOptions {
2
+ dev: boolean;
3
+ peerDependencies?: boolean;
4
+ }
5
+ export interface INpmConfig {
6
+ dir: string;
7
+ name: string;
8
+ }
9
+ export interface IResolvedCache {
10
+ [key: string]: {
11
+ main: string;
12
+ files: string[];
13
+ };
14
+ }
15
+ export interface IPrettierConfig {
16
+ printWidth?: number;
17
+ tabWidth?: number;
18
+ useTabs?: boolean;
19
+ semi?: boolean;
20
+ singleQuote?: boolean;
21
+ jsxSingleQuote?: boolean;
22
+ trailingComma?: 'none' | 'es5' | 'all';
23
+ bracketSpacing?: boolean;
24
+ jsxBracketSameLine?: boolean;
25
+ arrowParens?: 'avoid' | 'always';
26
+ rangeStart?: number;
27
+ rangeEnd?: number;
28
+ parser?: 'babel' | 'babylon' | 'flow' | 'typescript' | 'css' | 'scss' | 'less' | 'json' | 'json5' | 'json-stringify' | 'graphql' | 'markdown' | 'mdx' | 'html' | 'vue' | 'angular' | 'yaml';
29
+ filepath?: string;
30
+ requirePragma?: boolean;
31
+ insertPragma?: boolean;
32
+ proseWrap?: 'always' | 'never' | 'preserve';
33
+ htmlWhitespaceSensitivity?: 'css' | 'strict' | 'ignore';
34
+ endOfLine?: 'auto' | 'lf' | 'crlf' | 'cr';
35
+ }
36
+ export interface IBuildOptions {
37
+ type?: string;
38
+ watch?: boolean;
39
+ platform?: string;
40
+ port?: number;
41
+ release?: boolean;
42
+ envHasBeenSet?: boolean;
43
+ page?: string;
44
+ component?: string;
45
+ uiIndex?: string;
46
+ }
47
+ export interface IMiniAppBuildConfig {
48
+ adapter: string;
49
+ watch?: boolean;
50
+ envHasBeenSet?: boolean;
51
+ port?: number;
52
+ release?: boolean;
53
+ page?: string;
54
+ component?: string;
55
+ }
56
+ export interface IOption {
57
+ [key: string]: any;
58
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/util/types.ts"],"names":[],"mappings":""}
package/global.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module '*.json' {
2
+ const value: any
3
+ export default value
4
+ }
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = require('./dist/index.js').default
2
+
3
+ module.exports.default = module.exports
package/package.json CHANGED
@@ -1,6 +1,78 @@
1
1
  {
2
2
  "name": "@ohos-ports/tarojs-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.3.0-beta.1",
4
+ "description": "cli tool for taro",
5
+ "author": "O2Team",
6
+ "license": "MIT",
7
+ "main": "index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "dist",
13
+ "templates",
14
+ "postinstall.js",
15
+ "index.js",
16
+ "global.d.ts"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/ohos-ports/ohos-ports.git",
21
+ "directory": "ports/tarojs-cli/4.3.0"
22
+ },
23
+ "bin": {
24
+ "taro": "bin/taro"
25
+ },
26
+ "keywords": [
27
+ "taro",
28
+ "weapp"
29
+ ],
30
+ "engines": {
31
+ "node": ">= 18"
32
+ },
33
+ "dependencies": {
34
+ "@tarojs/plugin-doctor": "npm:@ohos-ports/tarojs-plugin-doctor@0.0.13-beta.1",
35
+ "adm-zip": "^0.5.12",
36
+ "axios": "^1.6.8",
37
+ "cli-highlight": "^2.1.11",
38
+ "download-git-repo": "^3.0.2",
39
+ "envinfo": "^7.12.0",
40
+ "inquirer": "^8.2.6",
41
+ "latest-version": "^5.1.0",
42
+ "minimist": "^1.2.8",
43
+ "ora": "^5.4.1",
44
+ "semver": "^7.6.0",
45
+ "validate-npm-package-name": "^5.0.0",
46
+ "@tarojs/binding": "npm:@ohos-ports/tarojs-binding@4.3.0-beta.1",
47
+ "@tarojs/helper": "npm:@ohos-ports/tarojs-helper@4.3.0-beta.1",
48
+ "@tarojs/service": "npm:@ohos-ports/tarojs-service@4.3.0-beta.1",
49
+ "@tarojs/shared": "4.3.0"
50
+ },
51
+ "devDependencies": {
52
+ "@babel/types": "^7.24.0",
53
+ "@types/babel__traverse": "^7.20.6",
54
+ "@ohos-ports/eslint-plugin-react": "^7.37.5-beta.1",
55
+ "@ohos-ports/eslint-plugin-react-hooks": "^4.6.2-beta.1",
56
+ "@tarojs/plugin-platform-h5": "4.3.0",
57
+ "@tarojs/plugin-platform-weapp": "4.3.0",
58
+ "@tarojs/taro": "4.3.0",
59
+ "@tarojs/webpack5-runner": "4.3.0",
60
+ "babel-preset-taro": "4.3.0"
61
+ },
62
+ "scripts": {
63
+ "prod": "pnpm run build",
64
+ "postinstall": "node postinstall.js",
65
+ "test": "cross-env NODE_ENV=test jest",
66
+ "test:ci": "cross-env NODE_ENV=test jest --ci -i --coverage --silent",
67
+ "test:dev": "cross-env NODE_ENV=test jest --watch",
68
+ "test:coverage": "cross-env NODE_ENV=test jest --coverage",
69
+ "updateSnapshot": "cross-env NODE_ENV=test jest --updateSnapshot",
70
+ "prebuild": "pnpm run clean",
71
+ "build": "tsc",
72
+ "dev": "tsc -w",
73
+ "clean": "rimraf dist"
74
+ },
75
+ "bugs": {
76
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
77
+ }
78
+ }
package/postinstall.js ADDED
@@ -0,0 +1,14 @@
1
+ const { exec } = require('child_process')
2
+ const axios = require('axios')
3
+
4
+ axios.get('https://taro.jd.com/', { timeout: 5000 })
5
+ .then(() => {
6
+ exec('./bin/taro global-config add-plugin @jdtaro/plugin-build-report-performance@latest --registry http://registry.m.jd.com', (error, _stdout, _stderr) => {
7
+ if (error) {
8
+ console.error(`install performance plugin error: ${error}`)
9
+ }
10
+ })
11
+ console.log('cli postinstall success')
12
+ })
13
+ .catch(() => {
14
+ })
@@ -0,0 +1,15 @@
1
+ import * as path from 'node:path'
2
+
3
+ export default () => {
4
+ return {
5
+ plugins: [
6
+ // hooks
7
+ path.resolve(__dirname, '../../presets', 'hooks', 'build.ts'),
8
+
9
+ // 兼容其他平台小程序插件
10
+ path.resolve(__dirname, '../../presets', 'files', 'writeFileToDist.ts'),
11
+ path.resolve(__dirname, '../../presets', 'files', 'generateProjectConfig.ts'),
12
+ path.resolve(__dirname, '../../presets', 'files', 'generateFrameworkInfo.ts')
13
+ ]
14
+ }
15
+ }
@@ -0,0 +1,99 @@
1
+ import * as path from 'node:path'
2
+
3
+ import { emptyDirectory } from '@tarojs/helper'
4
+
5
+ import { run } from './utils'
6
+
7
+ const runBuild = run('build', [
8
+ 'commands/build',
9
+ require.resolve('@tarojs/plugin-platform-weapp'),
10
+ require.resolve('@tarojs/plugin-platform-h5')
11
+ ])
12
+
13
+ jest.mock('@tarojs/helper', () => {
14
+ const helper = jest.requireActual('@tarojs/helper')
15
+ const fs = helper.fs
16
+ return {
17
+ __esModule: true,
18
+ ...helper,
19
+ emptyDirectory: jest.fn(),
20
+ fs: {
21
+ ...fs
22
+ },
23
+ }
24
+ })
25
+
26
+ const APP_PATH = path.join(__dirname, 'fixtures/default')
27
+ const OUTPUT_PATH = path.join(__dirname, 'fixtures/default/dist')
28
+
29
+ describe('构建配置测试', () => {
30
+ const emptyDirectoryMocked = emptyDirectory as jest.Mock<any>
31
+
32
+ beforeEach(() => {
33
+ emptyDirectoryMocked.mockReset()
34
+ process.argv = []
35
+ })
36
+
37
+ afterEach(() => {
38
+ process.argv = []
39
+ emptyDirectoryMocked.mockReset()
40
+ })
41
+
42
+ describe('小程序', () => {
43
+ it(`项目 output.clean = clean: { keep: ['project.config.json'] } ==> 清空dist文件夹但保留指定文件`, async () => {
44
+ const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>
45
+ const logSpy = jest.spyOn(console, 'log')
46
+ const errorSpy = jest.spyOn(console, 'error')
47
+ logSpy.mockImplementation(() => {})
48
+ errorSpy.mockImplementation(() => {})
49
+ exitSpy.mockImplementation(() => {
50
+ throw new Error()
51
+ })
52
+
53
+ try {
54
+ await runBuild(APP_PATH, {
55
+ options: {
56
+ type: 'weapp',
57
+ platform: 'weapp'
58
+ }
59
+ })
60
+ } catch (error) {
61
+ // no handler
62
+ }
63
+ expect(emptyDirectoryMocked).toBeCalledWith(OUTPUT_PATH, { excludes: ['project.config.json'] })
64
+
65
+ exitSpy.mockRestore()
66
+ logSpy.mockRestore()
67
+ errorSpy.mockRestore()
68
+ })
69
+ })
70
+
71
+ describe('h5', () => {
72
+ it('output.clean = false ==> 保留dist文件夹', async () => {
73
+ const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>
74
+ const logSpy = jest.spyOn(console, 'log')
75
+ const errorSpy = jest.spyOn(console, 'error')
76
+ logSpy.mockImplementation(() => {})
77
+ errorSpy.mockImplementation(() => {})
78
+ exitSpy.mockImplementation(() => {
79
+ throw new Error()
80
+ })
81
+
82
+ try {
83
+ await runBuild(APP_PATH, {
84
+ options: {
85
+ type: 'h5',
86
+ platform: 'h5'
87
+ }
88
+ })
89
+ } catch (error) {
90
+ // no handler
91
+ }
92
+ expect(emptyDirectoryMocked).toBeCalledTimes(0)
93
+
94
+ exitSpy.mockRestore()
95
+ logSpy.mockRestore()
96
+ errorSpy.mockRestore()
97
+ })
98
+ })
99
+ })
@@ -0,0 +1,233 @@
1
+ import { Kernel } from '@tarojs/service'
2
+
3
+ import CLI from '../cli'
4
+ import { getPkgVersion } from '../util'
5
+
6
+ jest.mock('@tarojs/service')
7
+ const MockedKernel = (Kernel as unknown) as (jest.Mock<Kernel>)
8
+ const APP_PATH = '/a/b/c'
9
+
10
+ function setProcessArgv (cmd: string) {
11
+ // @ts-ignore
12
+ process.argv = [null, ...cmd.split(' ')]
13
+ }
14
+
15
+ describe('inspect', () => {
16
+ let cli: CLI
17
+
18
+ beforeAll(() => {
19
+ cli = new CLI(APP_PATH)
20
+ })
21
+
22
+ beforeEach(() => {
23
+ MockedKernel.mockClear()
24
+ process.argv = []
25
+ delete process.env.NODE_ENV
26
+ delete process.env.TARO_ENV
27
+ })
28
+
29
+ afterEach(() => {
30
+ MockedKernel.mockClear()
31
+ process.argv = []
32
+ delete process.env.NODE_ENV
33
+ delete process.env.TARO_ENV
34
+ })
35
+
36
+ describe('build', () => {
37
+ const baseOpts = {
38
+ _: [
39
+ 'build'
40
+ ],
41
+ options: {
42
+ args: expect.any(Object),
43
+ platform: undefined,
44
+ publicPath: undefined,
45
+ isWatch: false,
46
+ withoutBuild: false,
47
+ env: undefined,
48
+ blended: false,
49
+ assetsDest: undefined,
50
+ bundleOutput: undefined,
51
+ plugin: undefined,
52
+ isBuildNativeComp: false,
53
+ newBlended: false,
54
+ noInjectGlobalStyle: false,
55
+ noCheck: false,
56
+ sourceMapUrl: undefined,
57
+ sourcemapOutput: undefined,
58
+ sourcemapSourcesRoot: undefined,
59
+ },
60
+ isHelp: false
61
+ }
62
+
63
+ it('should make configs', async () => {
64
+ const platform = 'weapp'
65
+ setProcessArgv('taro build --type weapp --watch --port 8080')
66
+ await cli.run()
67
+ const ins = MockedKernel.mock.instances[0]
68
+
69
+ const opts = Object.assign({}, baseOpts)
70
+ opts.options = Object.assign({}, baseOpts.options, {
71
+ platform,
72
+ isWatch: true,
73
+ port: 8080,
74
+ deviceType: undefined,
75
+ resetCache: false,
76
+ qr: false
77
+ })
78
+
79
+ expect(ins.run).toHaveBeenCalledWith({
80
+ name: 'build',
81
+ opts
82
+ })
83
+ })
84
+
85
+ it('should not set node env again', async () => {
86
+ process.env.NODE_ENV = 'development'
87
+ setProcessArgv('taro build --type weapp')
88
+ await cli.run()
89
+ expect(process.env.NODE_ENV).toEqual('development')
90
+ })
91
+
92
+ it.skip('should make plugin config', async () => {
93
+ setProcessArgv('taro build --plugin')
94
+ await cli.run()
95
+ const ins = MockedKernel.mock.instances[0]
96
+ expect(ins.run).toHaveBeenCalledWith({
97
+ name: 'build',
98
+ opts: Object.assign({}, baseOpts, {
99
+ platform: 'plugin',
100
+ plugin: 'weapp'
101
+ })
102
+ })
103
+ expect(process.env.NODE_ENV).toEqual('production')
104
+ expect(process.env.TARO_ENV).toEqual('plugin')
105
+ })
106
+ })
107
+
108
+ describe('init', () => {
109
+ it('should make configs', async () => {
110
+ const projectName = 'temp'
111
+ const templateSource = 'https://url'
112
+ const template = 'mobx'
113
+ const css = 'sass'
114
+ setProcessArgv('taro init temp --typescript --template-source=https://url --clone --template mobx --css sass')
115
+ await cli.run()
116
+ const ins = MockedKernel.mock.instances[0]
117
+ expect(ins.run).toHaveBeenCalledWith({
118
+ name: 'init',
119
+ opts: {
120
+ _: [
121
+ 'init',
122
+ 'temp'
123
+ ],
124
+ options: {
125
+ appPath: APP_PATH,
126
+ projectName,
127
+ typescript: true,
128
+ templateSource,
129
+ description: undefined,
130
+ clone: true,
131
+ template,
132
+ css
133
+ },
134
+ isHelp: false
135
+ }
136
+ })
137
+ })
138
+
139
+ it('should set project name', async () => {
140
+ const projectName = 'demo'
141
+ setProcessArgv('taro init --name demo')
142
+ await cli.run()
143
+ const ins = MockedKernel.mock.instances[0]
144
+ expect(ins.run).toHaveBeenCalledWith({
145
+ name: 'init',
146
+ opts: {
147
+ _: [
148
+ 'init'
149
+ ],
150
+ options: {
151
+ appPath: APP_PATH,
152
+ projectName,
153
+ typescript: undefined,
154
+ templateSource: undefined,
155
+ description: undefined,
156
+ clone: false,
157
+ template: undefined,
158
+ css: undefined
159
+ },
160
+ isHelp: false
161
+ }
162
+ })
163
+ })
164
+ })
165
+
166
+ describe('convert', () => {
167
+ it('should make configs', async () => {
168
+ setProcessArgv('taro convert')
169
+ await cli.run()
170
+ const ins = MockedKernel.mock.instances[0]
171
+ expect(ins.run).toHaveBeenCalledWith({
172
+ name: 'convert',
173
+ opts: {
174
+ _: ['convert'],
175
+ options: {
176
+ build: true,
177
+ check: true,
178
+ 'inject-global-style': true,
179
+ },
180
+ isHelp: false
181
+ }
182
+ })
183
+ })
184
+ })
185
+
186
+ describe('customCommand', () => {
187
+ it('should make configs', async () => {
188
+ const cmd = 'inspect'
189
+ const _ = [cmd, 'entry']
190
+ const type = 'weapp'
191
+ setProcessArgv('taro inspect entry --type weapp -h --version')
192
+ await cli.run()
193
+ const ins = MockedKernel.mock.instances[0]
194
+ expect(ins.run).toHaveBeenCalledWith({
195
+ name: cmd,
196
+ opts: {
197
+ _,
198
+ options: {
199
+ build: true,
200
+ check: true,
201
+ 'inject-global-style': true,
202
+ type
203
+ },
204
+ isHelp: true
205
+ }
206
+ })
207
+ })
208
+ })
209
+
210
+ describe('others', () => {
211
+ it('should log helps', async () => {
212
+ const spy = jest.spyOn(console, 'log')
213
+ spy.mockImplementation(() => {})
214
+
215
+ setProcessArgv('taro -h')
216
+ await cli.run()
217
+ expect(spy).toBeCalledTimes(16)
218
+
219
+ spy.mockRestore()
220
+ })
221
+
222
+ it('should log version', async () => {
223
+ const spy = jest.spyOn(console, 'log')
224
+ spy.mockImplementation(() => {})
225
+
226
+ setProcessArgv('taro -v')
227
+ await cli.run()
228
+ expect(spy).toBeCalledWith(getPkgVersion())
229
+
230
+ spy.mockRestore()
231
+ })
232
+ })
233
+ })