@spcsn/taro-cli 0.1.5 → 1.0.0
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.
- package/README.md +37 -0
- package/define-config.d.ts +1 -0
- package/define-config.js +1 -0
- package/dist/cli.js +140 -110
- package/dist/cli.js.map +1 -1
- package/dist/commands/{customCommand.d.ts → custom-command.d.ts} +1 -1
- package/dist/commands/custom-command.js +23 -0
- package/dist/commands/custom-command.js.map +1 -0
- package/dist/create/creator.js +2 -0
- package/dist/create/creator.js.map +1 -1
- package/dist/create/{fetchTemplate.js → fetch-template.js} +26 -33
- package/dist/create/fetch-template.js.map +1 -0
- package/dist/create/project.d.ts +2 -6
- package/dist/create/project.js +240 -285
- package/dist/create/project.js.map +1 -1
- package/dist/create/template-creator.d.ts +75 -0
- package/dist/create/template-creator.js +275 -0
- package/dist/create/template-creator.js.map +1 -0
- package/dist/doctor/validators.d.ts +7 -6
- package/dist/doctor/validators.js +6 -7
- package/dist/doctor/validators.js.map +1 -1
- package/dist/platform-weapp/apis-list.d.ts +1 -0
- package/dist/platform-weapp/apis-list.js +37 -0
- package/dist/platform-weapp/apis-list.js.map +1 -0
- package/dist/platform-weapp/apis.d.ts +16 -0
- package/dist/platform-weapp/apis.js +34 -0
- package/dist/platform-weapp/apis.js.map +1 -0
- package/dist/platform-weapp/components-react.d.ts +80 -0
- package/dist/platform-weapp/components-react.js +86 -0
- package/dist/platform-weapp/components-react.js.map +1 -0
- package/dist/platform-weapp/components.d.ts +4 -0
- package/dist/platform-weapp/components.js +520 -0
- package/dist/platform-weapp/components.js.map +1 -0
- package/dist/platform-weapp/index.d.ts +11 -0
- package/dist/platform-weapp/index.js +17 -0
- package/dist/platform-weapp/index.js.map +1 -0
- package/dist/platform-weapp/program.d.ts +35 -0
- package/dist/platform-weapp/program.js +64 -0
- package/dist/platform-weapp/program.js.map +1 -0
- package/dist/platform-weapp/runtime-utils.d.ts +27 -0
- package/dist/platform-weapp/runtime-utils.js +48 -0
- package/dist/platform-weapp/runtime-utils.js.map +1 -0
- package/dist/platform-weapp/runtime.d.ts +1 -0
- package/dist/platform-weapp/runtime.js +7 -0
- package/dist/platform-weapp/runtime.js.map +1 -0
- package/dist/platform-weapp/template.d.ts +39 -0
- package/dist/platform-weapp/template.js +119 -0
- package/dist/platform-weapp/template.js.map +1 -0
- package/dist/presets/commands/build.js +25 -45
- package/dist/presets/commands/build.js.map +1 -1
- package/dist/presets/commands/init.js +2 -4
- package/dist/presets/commands/init.js.map +1 -1
- package/dist/presets/constant/hooks.d.ts +0 -2
- package/dist/presets/constant/hooks.js +1 -3
- package/dist/presets/constant/hooks.js.map +1 -1
- package/dist/presets/files/generate-framework-info.js +68 -0
- package/dist/presets/files/generate-framework-info.js.map +1 -0
- package/dist/presets/files/{generateProjectConfig.js → generate-project-config.js} +1 -1
- package/dist/presets/files/generate-project-config.js.map +1 -0
- package/dist/presets/files/{writeFileToDist.js → write-file-to-dist.js} +1 -1
- package/dist/presets/files/write-file-to-dist.js.map +1 -0
- package/dist/presets/hooks/build.js +1 -3
- package/dist/presets/hooks/build.js.map +1 -1
- package/dist/presets/index.js +3 -5
- package/dist/presets/index.js.map +1 -1
- package/dist/util/{appConfig.d.ts → app-config.d.ts} +2 -2
- package/dist/util/{appConfig.js → app-config.js} +4 -3
- package/dist/util/app-config.js.map +1 -0
- package/dist/util/defineConfig.d.ts +5 -5
- package/dist/util/defineConfig.js.map +1 -1
- package/dist/util/index.d.ts +9 -1
- package/dist/util/index.js +54 -23
- package/dist/util/index.js.map +1 -1
- package/package.json +36 -39
- package/postinstall.js +1 -17
- package/src/cli.ts +185 -132
- package/src/commands/custom-command.ts +22 -0
- package/src/create/{fetchTemplate.ts → fetch-template.ts} +30 -35
- package/src/create/project.ts +31 -78
- package/src/create/template-creator.ts +325 -0
- package/src/doctor/validators.js +1 -0
- package/src/doctor/validators.ts +8 -6
- package/src/platform-weapp/apis-list.ts +33 -0
- package/src/platform-weapp/apis.ts +48 -0
- package/src/platform-weapp/components-react.ts +81 -0
- package/src/platform-weapp/components.ts +521 -0
- package/src/platform-weapp/index.ts +25 -0
- package/src/platform-weapp/program.ts +70 -0
- package/src/platform-weapp/runtime-utils.ts +57 -0
- package/src/platform-weapp/runtime.ts +6 -0
- package/src/platform-weapp/template.ts +150 -0
- package/src/presets/commands/build.ts +20 -40
- package/src/presets/commands/init.ts +1 -4
- package/src/presets/constant/hooks.js +12 -0
- package/src/presets/constant/hooks.ts +0 -2
- package/src/presets/files/{generateFrameworkInfo.ts → generate-framework-info.ts} +7 -1
- package/src/presets/hooks/build.ts +1 -3
- package/src/presets/index.ts +3 -5
- package/src/util/app-config.js +1 -0
- package/src/util/{appConfig.ts → app-config.ts} +5 -4
- package/src/util/defineConfig.ts +6 -6
- package/src/util/index.ts +67 -25
- package/templates/default/config/dev.js +1 -1
- package/templates/default/config/index.js +28 -40
- package/templates/default/config/prod.js +1 -1
- package/templates/default/package.json.tmpl +2 -17
- package/templates/default/types/global.d.ts +0 -4
- package/templates/plugin-compile/README.md +3 -1
- package/templates/plugin-compile/package.json.tmpl +1 -2
- package/templates/plugin-compile/src/index.ts +18 -28
- package/LICENSE +0 -174
- package/dist/commands/customCommand.js +0 -23
- package/dist/commands/customCommand.js.map +0 -1
- package/dist/config/packagesManagement.d.ts +0 -19
- package/dist/config/packagesManagement.js +0 -22
- package/dist/config/packagesManagement.js.map +0 -1
- package/dist/create/fetchTemplate.js.map +0 -1
- package/dist/create/page.d.ts +0 -65
- package/dist/create/page.js +0 -266
- package/dist/create/page.js.map +0 -1
- package/dist/create/plugin.d.ts +0 -16
- package/dist/create/plugin.js +0 -77
- package/dist/create/plugin.js.map +0 -1
- package/dist/presets/commands/config.js +0 -121
- package/dist/presets/commands/config.js.map +0 -1
- package/dist/presets/commands/create.js +0 -112
- package/dist/presets/commands/create.js.map +0 -1
- package/dist/presets/commands/doctor.js +0 -15
- package/dist/presets/commands/doctor.js.map +0 -1
- package/dist/presets/commands/global-config.d.ts +0 -3
- package/dist/presets/commands/global-config.js +0 -175
- package/dist/presets/commands/global-config.js.map +0 -1
- package/dist/presets/commands/help.d.ts +0 -3
- package/dist/presets/commands/help.js +0 -16
- package/dist/presets/commands/help.js.map +0 -1
- package/dist/presets/commands/info.d.ts +0 -3
- package/dist/presets/commands/info.js +0 -96
- package/dist/presets/commands/info.js.map +0 -1
- package/dist/presets/commands/inspect.d.ts +0 -3
- package/dist/presets/commands/inspect.js +0 -155
- package/dist/presets/commands/inspect.js.map +0 -1
- package/dist/presets/commands/update.d.ts +0 -3
- package/dist/presets/commands/update.js +0 -187
- package/dist/presets/commands/update.js.map +0 -1
- package/dist/presets/files/generateFrameworkInfo.d.ts +0 -3
- package/dist/presets/files/generateFrameworkInfo.js +0 -30
- package/dist/presets/files/generateFrameworkInfo.js.map +0 -1
- package/dist/presets/files/generateProjectConfig.d.ts +0 -3
- package/dist/presets/files/generateProjectConfig.js.map +0 -1
- package/dist/presets/files/writeFileToDist.d.ts +0 -3
- package/dist/presets/files/writeFileToDist.js.map +0 -1
- package/dist/presets/hooks/create.d.ts +0 -3
- package/dist/presets/hooks/create.js +0 -42
- package/dist/presets/hooks/create.js.map +0 -1
- package/dist/presets/platforms/plugin.d.ts +0 -3
- package/dist/presets/platforms/plugin.js +0 -106
- package/dist/presets/platforms/plugin.js.map +0 -1
- package/dist/presets/platforms/rn.d.ts +0 -3
- package/dist/presets/platforms/rn.js +0 -130
- package/dist/presets/platforms/rn.js.map +0 -1
- package/dist/util/appConfig.js.map +0 -1
- package/dist/util/createPage.d.ts +0 -9
- package/dist/util/createPage.js +0 -114
- package/dist/util/createPage.js.map +0 -1
- package/src/__tests__/__mocks__/presets.ts +0 -15
- package/src/__tests__/build-config.spec.ts +0 -66
- package/src/__tests__/cli.spec.ts +0 -226
- package/src/__tests__/config.spec.ts +0 -224
- package/src/__tests__/doctor-config.spec.ts +0 -918
- package/src/__tests__/doctor-recommand.spec.ts +0 -136
- package/src/__tests__/doctor.spec.ts +0 -94
- package/src/__tests__/dotenv-parse.spec.ts +0 -105
- package/src/__tests__/env/.env +0 -2
- package/src/__tests__/fixtures/default/.env +0 -3
- package/src/__tests__/fixtures/default/.env.development +0 -1
- package/src/__tests__/fixtures/default/.env.local +0 -1
- package/src/__tests__/fixtures/default/.env.pre +0 -3
- package/src/__tests__/fixtures/default/.env.production +0 -1
- package/src/__tests__/fixtures/default/.env.uat +0 -5
- package/src/__tests__/fixtures/default/.env.uat.local +0 -1
- package/src/__tests__/fixtures/default/babel.config.js +0 -10
- package/src/__tests__/fixtures/default/config/dev.js +0 -9
- package/src/__tests__/fixtures/default/config/index.js +0 -84
- package/src/__tests__/fixtures/default/config/prod.js +0 -18
- package/src/__tests__/fixtures/default/package.json +0 -27
- package/src/__tests__/fixtures/default/src/app.config.js +0 -11
- package/src/__tests__/fixtures/default/src/app.js +0 -16
- package/src/__tests__/fixtures/default/src/app.scss +0 -0
- package/src/__tests__/fixtures/default/src/index.html +0 -19
- package/src/__tests__/fixtures/default/src/pages/index/index.config.js +0 -3
- package/src/__tests__/fixtures/default/src/pages/index/index.jsx +0 -22
- package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
- package/src/__tests__/info.spec.ts +0 -72
- package/src/__tests__/inspect.spec.ts +0 -160
- package/src/__tests__/update.spec.ts +0 -310
- package/src/__tests__/utils/index.ts +0 -54
- package/src/commands/customCommand.ts +0 -22
- package/src/config/packagesManagement.ts +0 -20
- package/src/config/rn-stylelint.json +0 -4
- package/src/create/page.ts +0 -325
- package/src/create/plugin.ts +0 -55
- package/src/presets/commands/config.ts +0 -86
- package/src/presets/commands/create.ts +0 -104
- package/src/presets/commands/doctor.ts +0 -21
- package/src/presets/commands/global-config.ts +0 -140
- package/src/presets/commands/help.ts +0 -17
- package/src/presets/commands/info.ts +0 -81
- package/src/presets/commands/inspect.ts +0 -137
- package/src/presets/commands/update.ts +0 -175
- package/src/presets/hooks/create.ts +0 -9
- package/src/presets/platforms/plugin.ts +0 -75
- package/src/presets/platforms/rn.ts +0 -125
- package/src/util/createPage.ts +0 -139
- package/templates/default/babel.config.js +0 -14
- /package/dist/create/{fetchTemplate.d.ts → fetch-template.d.ts} +0 -0
- /package/dist/presets/{commands/config.d.ts → files/generate-framework-info.d.ts} +0 -0
- /package/dist/presets/{commands/create.d.ts → files/generate-project-config.d.ts} +0 -0
- /package/dist/presets/{commands/doctor.d.ts → files/write-file-to-dist.d.ts} +0 -0
- /package/src/presets/files/{generateProjectConfig.ts → generate-project-config.ts} +0 -0
- /package/src/presets/files/{writeFileToDist.ts → write-file-to-dist.ts} +0 -0
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import * as validatePkgName from 'validate-npm-package-name';
|
|
5
|
-
|
|
6
|
-
import { execCommand, getPkgNameByFilterVersion, getRootPath } from '../../util';
|
|
7
|
-
|
|
8
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
9
|
-
|
|
10
|
-
type TPresetOrPluginAction = 'install' | 'uninstall';
|
|
11
|
-
type TPluginType = 'plugin' | 'preset';
|
|
12
|
-
|
|
13
|
-
const PRESET_OR_PLUGIN_COMMAND_CHINESE_MAP_MAP = {
|
|
14
|
-
install: '添加',
|
|
15
|
-
uninstall: '删除',
|
|
16
|
-
};
|
|
17
|
-
const PRESET_OR_PLUGIN_CHINESE_NAME_MAP = {
|
|
18
|
-
plugin: '插件',
|
|
19
|
-
preset: '插件集',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const PLUGIN_TYPE_TO_CONFIG_KEY = {
|
|
23
|
-
plugin: 'plugins',
|
|
24
|
-
preset: 'presets',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default (ctx: IPluginContext) => {
|
|
28
|
-
ctx.registerCommand({
|
|
29
|
-
name: 'global-config',
|
|
30
|
-
synopsisList: [
|
|
31
|
-
'taro global-config add-plugin [pluginName]',
|
|
32
|
-
'taro global-config remove-plugin [pluginName]',
|
|
33
|
-
'taro global-config add-preset [presetName]',
|
|
34
|
-
'taro global-config remove-preset [presetName]',
|
|
35
|
-
'taro global-config reset',
|
|
36
|
-
],
|
|
37
|
-
optionsMap: {
|
|
38
|
-
'-r --registry [url]': '指定 npm registry',
|
|
39
|
-
'-h, --help': 'output usage information',
|
|
40
|
-
},
|
|
41
|
-
fn({ _, options }) {
|
|
42
|
-
const [, action, pluginName] = _;
|
|
43
|
-
const { getUserHomeDir, TARO_GLOBAL_CONFIG_DIR, fs, TARO_GLOBAL_CONFIG_FILE } = ctx.helper;
|
|
44
|
-
const homedir = getUserHomeDir();
|
|
45
|
-
const globalPluginConfigDir = path.join(homedir, TARO_GLOBAL_CONFIG_DIR);
|
|
46
|
-
if (!homedir) return console.log('找不到用户根目录');
|
|
47
|
-
const rootPath = getRootPath();
|
|
48
|
-
const templatePath = path.join(rootPath, 'templates', 'global-config');
|
|
49
|
-
const registry = options.registry || options.r;
|
|
50
|
-
function makeSureConfigExists() {
|
|
51
|
-
if (!fs.existsSync(globalPluginConfigDir)) {
|
|
52
|
-
const spinner = ora(`目录不存在,全局配置初始化`).start();
|
|
53
|
-
try {
|
|
54
|
-
fs.copySync(templatePath, globalPluginConfigDir);
|
|
55
|
-
spinner.succeed(`全局配置初始化成功,${globalPluginConfigDir}`);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
spinner.fail(`全局配置初始化失败,${e}`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function addOrRemovePresetOrPlugin(actionType: TPresetOrPluginAction, pluginType: TPluginType) {
|
|
63
|
-
makeSureConfigExists();
|
|
64
|
-
const presetOrPluginChineseName = PRESET_OR_PLUGIN_CHINESE_NAME_MAP[pluginType];
|
|
65
|
-
const chineseCommand = PRESET_OR_PLUGIN_COMMAND_CHINESE_MAP_MAP[actionType];
|
|
66
|
-
if (!pluginName) {
|
|
67
|
-
console.error(`缺少要${chineseCommand}的${presetOrPluginChineseName}`);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const spinner = ora(`开始${chineseCommand}${presetOrPluginChineseName} ${pluginName}`).start();
|
|
72
|
-
const pluginWithoutVersionName = getPkgNameByFilterVersion(pluginName);
|
|
73
|
-
if (!validatePkgName(pluginWithoutVersionName).validForNewPackages) {
|
|
74
|
-
spinner.fail('安装的插件名不合规!');
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
let command = `cd ${globalPluginConfigDir} && npm ${actionType} ${pluginName}`;
|
|
78
|
-
if (registry) {
|
|
79
|
-
command += ` --registry=${registry}`;
|
|
80
|
-
}
|
|
81
|
-
execCommand({
|
|
82
|
-
command,
|
|
83
|
-
successCallback(data) {
|
|
84
|
-
console.log(data.replace(/\n$/, ''));
|
|
85
|
-
spinner.start(`开始修改${presetOrPluginChineseName}配置`);
|
|
86
|
-
const configFilePath = path.join(globalPluginConfigDir, TARO_GLOBAL_CONFIG_FILE);
|
|
87
|
-
let globalConfig;
|
|
88
|
-
try {
|
|
89
|
-
globalConfig = fs.readJSONSync(configFilePath);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
spinner.fail('获取配置文件失败');
|
|
92
|
-
}
|
|
93
|
-
const configKey = PLUGIN_TYPE_TO_CONFIG_KEY[pluginType];
|
|
94
|
-
const configItem = globalConfig[configKey] || [];
|
|
95
|
-
const pluginIndex = configItem.findIndex((item) => {
|
|
96
|
-
if (typeof item === 'string') return item === pluginWithoutVersionName;
|
|
97
|
-
if (item instanceof Array) return item?.[0] === pluginWithoutVersionName;
|
|
98
|
-
});
|
|
99
|
-
const shouldChangeFile = !(Number(pluginIndex !== -1) ^ Number(actionType === 'uninstall'));
|
|
100
|
-
if (shouldChangeFile) {
|
|
101
|
-
actionType === 'install' ? configItem.push(pluginWithoutVersionName) : configItem.splice(pluginIndex, 1);
|
|
102
|
-
try {
|
|
103
|
-
fs.writeJSONSync(configFilePath, {
|
|
104
|
-
[configKey]: configItem,
|
|
105
|
-
});
|
|
106
|
-
} catch (e) {
|
|
107
|
-
spinner.fail(`修改配置文件失败:${e}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
spinner.succeed('修改配置文件成功');
|
|
111
|
-
},
|
|
112
|
-
failCallback(data) {
|
|
113
|
-
spinner.stop();
|
|
114
|
-
spinner.warn(data.replace(/\n$/, ''));
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
switch (action) {
|
|
119
|
-
case 'add-plugin':
|
|
120
|
-
addOrRemovePresetOrPlugin('install', 'plugin');
|
|
121
|
-
break;
|
|
122
|
-
case 'remove-plugin':
|
|
123
|
-
addOrRemovePresetOrPlugin('uninstall', 'plugin');
|
|
124
|
-
break;
|
|
125
|
-
case 'add-preset':
|
|
126
|
-
addOrRemovePresetOrPlugin('install', 'preset');
|
|
127
|
-
break;
|
|
128
|
-
case 'remove-preset':
|
|
129
|
-
addOrRemovePresetOrPlugin('uninstall', 'preset');
|
|
130
|
-
break;
|
|
131
|
-
case 'reset':
|
|
132
|
-
if (fs.existsSync(globalPluginConfigDir)) fs.removeSync(globalPluginConfigDir);
|
|
133
|
-
fs.copySync(templatePath, globalPluginConfigDir);
|
|
134
|
-
break;
|
|
135
|
-
default:
|
|
136
|
-
console.error('请输出正确的参数');
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { chalk } from '@spcsn/taro-helper';
|
|
2
|
-
|
|
3
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
4
|
-
|
|
5
|
-
export default (ctx: IPluginContext) => {
|
|
6
|
-
ctx.registerCommand({
|
|
7
|
-
name: 'help',
|
|
8
|
-
synopsisList: ['taro help [cmd]'],
|
|
9
|
-
async fn({ _ }) {
|
|
10
|
-
const cmd = _[1];
|
|
11
|
-
|
|
12
|
-
if (!cmd) return console.log(chalk.yellow('用法:taro help [cmd],cmd 不存在!请输入需要查看帮助的命令名称。'));
|
|
13
|
-
|
|
14
|
-
ctx.ctx.runHelp(cmd);
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import * as envinfo from 'envinfo';
|
|
4
|
-
|
|
5
|
-
import { getPkgVersion } from '../../util';
|
|
6
|
-
|
|
7
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
8
|
-
|
|
9
|
-
export default (ctx: IPluginContext) => {
|
|
10
|
-
ctx.registerCommand({
|
|
11
|
-
name: 'info',
|
|
12
|
-
synopsisList: ['taro info', 'taro info rn'],
|
|
13
|
-
async fn({ _ }) {
|
|
14
|
-
const rn = _[1] === 'rn';
|
|
15
|
-
const { fs, chalk, PROJECT_CONFIG } = ctx.helper;
|
|
16
|
-
const { appPath, configPath } = ctx.paths;
|
|
17
|
-
|
|
18
|
-
if (!configPath || !fs.existsSync(configPath)) {
|
|
19
|
-
console.log(chalk.red(`找不到项目配置文件${PROJECT_CONFIG},请确定当前目录是 Taro 项目根目录!`));
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (rn) {
|
|
24
|
-
const tempPath = path.join(appPath, '.rn_temp');
|
|
25
|
-
if (fs.lstatSync(tempPath).isDirectory()) {
|
|
26
|
-
process.chdir('.rn_temp');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
await info({}, ctx);
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// 单独function获取@jdtaro相关的包
|
|
36
|
-
function getJdtaroPackages(ctx) {
|
|
37
|
-
try {
|
|
38
|
-
const { appPath } = ctx.paths;
|
|
39
|
-
const fs = ctx.helper.fs;
|
|
40
|
-
const packageJsonPath = path.join(appPath, 'package.json');
|
|
41
|
-
|
|
42
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
43
|
-
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
|
|
44
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
45
|
-
const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {});
|
|
46
|
-
|
|
47
|
-
// 筛选出@jdtaro相关的包
|
|
48
|
-
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@jdtaro/'));
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
// 记录错误但不中断程序执行(添加trycatch)
|
|
52
|
-
console.error('读取或解析package.json时发生错误:', error instanceof Error ? error.message : String(error));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function info(options, ctx) {
|
|
59
|
-
let npmPackages = ctx.helper.UPDATE_PACKAGE_LIST.concat(['react', 'react-native', 'expo', 'taro-ui']);
|
|
60
|
-
|
|
61
|
-
// 调用新函数获取@jdtaro相关包
|
|
62
|
-
const jdtaroPackages = getJdtaroPackages(ctx);
|
|
63
|
-
npmPackages = npmPackages.concat(jdtaroPackages);
|
|
64
|
-
|
|
65
|
-
const info = await envinfo.run(
|
|
66
|
-
Object.assign(
|
|
67
|
-
{},
|
|
68
|
-
{
|
|
69
|
-
System: ['OS', 'Shell'],
|
|
70
|
-
Binaries: ['Node', 'Yarn', 'npm'],
|
|
71
|
-
npmPackages,
|
|
72
|
-
npmGlobalPackages: ['typescript'],
|
|
73
|
-
},
|
|
74
|
-
options,
|
|
75
|
-
),
|
|
76
|
-
{
|
|
77
|
-
title: `Taro CLI ${getPkgVersion()} environment info`,
|
|
78
|
-
},
|
|
79
|
-
);
|
|
80
|
-
console.log(info);
|
|
81
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { ENTRY, OUTPUT_DIR, resolveScriptPath, SOURCE_DIR } from '@spcsn/taro-helper';
|
|
4
|
-
import { getPlatformType } from '@spcsn/taro-shared';
|
|
5
|
-
|
|
6
|
-
import * as hooks from '../constant';
|
|
7
|
-
|
|
8
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
9
|
-
|
|
10
|
-
export default (ctx: IPluginContext) => {
|
|
11
|
-
ctx.registerCommand({
|
|
12
|
-
name: 'inspect',
|
|
13
|
-
optionsMap: {
|
|
14
|
-
'-t, --type [typeName]': 'Build type, weapp',
|
|
15
|
-
'-o, --output [outputPath]': 'output config to outputPath',
|
|
16
|
-
},
|
|
17
|
-
synopsisList: [
|
|
18
|
-
'taro inspect --type weapp',
|
|
19
|
-
'taro inspect --type weapp --output inspect.config.js',
|
|
20
|
-
'taro inspect --type weapp plugins',
|
|
21
|
-
'taro inspect --type weapp module.rules.0',
|
|
22
|
-
],
|
|
23
|
-
async fn({ _, options }) {
|
|
24
|
-
const { fs, chalk } = ctx.helper;
|
|
25
|
-
const platform = options.type || options.t;
|
|
26
|
-
|
|
27
|
-
verifyIsTaroProject(ctx);
|
|
28
|
-
verifyPlatform(platform, chalk);
|
|
29
|
-
|
|
30
|
-
const configName = ctx.platforms.get(platform)?.useConfigName || '';
|
|
31
|
-
process.env.TARO_ENV = platform;
|
|
32
|
-
process.env.TARO_PLATFORM = getPlatformType(platform, configName);
|
|
33
|
-
|
|
34
|
-
let config = getConfig(ctx, platform);
|
|
35
|
-
config = {
|
|
36
|
-
...config,
|
|
37
|
-
...config[configName],
|
|
38
|
-
};
|
|
39
|
-
delete config.mini;
|
|
40
|
-
delete config.h5;
|
|
41
|
-
|
|
42
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
43
|
-
const outputPath = options.output || options.o;
|
|
44
|
-
const mode = outputPath ? 'output' : 'console';
|
|
45
|
-
const extractPath = _[1];
|
|
46
|
-
|
|
47
|
-
await ctx.applyPlugins({
|
|
48
|
-
name: platform,
|
|
49
|
-
opts: {
|
|
50
|
-
config: {
|
|
51
|
-
...config,
|
|
52
|
-
isWatch: !isProduction,
|
|
53
|
-
mode: isProduction ? 'production' : 'development',
|
|
54
|
-
async modifyWebpackChain(chain, webpack, data) {
|
|
55
|
-
await ctx.applyPlugins({
|
|
56
|
-
name: hooks.MODIFY_WEBPACK_CHAIN,
|
|
57
|
-
initialVal: chain,
|
|
58
|
-
opts: {
|
|
59
|
-
chain,
|
|
60
|
-
webpack,
|
|
61
|
-
data,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
onWebpackChainReady(chain) {
|
|
66
|
-
const webpackConfig = chain.toConfig();
|
|
67
|
-
const { toString } = chain.constructor;
|
|
68
|
-
const config = extractConfig(webpackConfig, extractPath);
|
|
69
|
-
const res = toString(config);
|
|
70
|
-
|
|
71
|
-
if (mode === 'console') {
|
|
72
|
-
const highlight = require('cli-highlight').default;
|
|
73
|
-
console.info(highlight(res, { language: 'js' }));
|
|
74
|
-
} else if (mode === 'output' && outputPath) {
|
|
75
|
-
fs.writeFileSync(outputPath, res);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
process.exit(0);
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/** 是否 Taro 项目根路径 */
|
|
88
|
-
function verifyIsTaroProject(ctx: IPluginContext) {
|
|
89
|
-
const { fs, chalk, PROJECT_CONFIG } = ctx.helper;
|
|
90
|
-
const { configPath } = ctx.paths;
|
|
91
|
-
|
|
92
|
-
if (!configPath || !fs.existsSync(configPath)) {
|
|
93
|
-
console.log(chalk.red(`找不到项目配置文件${PROJECT_CONFIG},请确定当前目录是 Taro 项目根目录!`));
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** 检查平台类型 */
|
|
99
|
-
function verifyPlatform(platform, chalk) {
|
|
100
|
-
if (typeof platform !== 'string') {
|
|
101
|
-
console.log(chalk.red('请传入正确的编译类型!'));
|
|
102
|
-
process.exit(0);
|
|
103
|
-
}
|
|
104
|
-
if (platform !== 'weapp') {
|
|
105
|
-
console.log(chalk.red('当前 Fork 仅支持 weapp 平台检查。'));
|
|
106
|
-
process.exit(0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** 整理 config */
|
|
111
|
-
function getConfig(ctx: IPluginContext, platform: string) {
|
|
112
|
-
const { initialConfig } = ctx;
|
|
113
|
-
const sourceDirName = initialConfig.sourceRoot || SOURCE_DIR;
|
|
114
|
-
const outputDirName = initialConfig.outputRoot || OUTPUT_DIR;
|
|
115
|
-
const sourceDir = path.join(ctx.appPath, sourceDirName);
|
|
116
|
-
const entryFilePath = resolveScriptPath(path.join(sourceDir, ENTRY));
|
|
117
|
-
|
|
118
|
-
const entry = {
|
|
119
|
-
[ENTRY]: [entryFilePath],
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
...initialConfig,
|
|
124
|
-
entry,
|
|
125
|
-
sourceRoot: sourceDirName,
|
|
126
|
-
outputRoot: outputDirName,
|
|
127
|
-
platform,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** 按路径取出 webpackConfig 内的对应值 */
|
|
132
|
-
function extractConfig(webpackConfig, extractPath: string | undefined) {
|
|
133
|
-
if (!extractPath) return webpackConfig;
|
|
134
|
-
|
|
135
|
-
const list = extractPath.split('.');
|
|
136
|
-
return list.reduce((config, current) => config[current], webpackConfig);
|
|
137
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import * as inquirer from 'inquirer';
|
|
4
|
-
import getLatestVersion from 'latest-version';
|
|
5
|
-
import ora from 'ora';
|
|
6
|
-
import * as semver from 'semver';
|
|
7
|
-
|
|
8
|
-
import packagesManagement from '../../config/packagesManagement';
|
|
9
|
-
import { execCommand, getPkgItemByKey } from '../../util';
|
|
10
|
-
|
|
11
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
12
|
-
|
|
13
|
-
export default (ctx: IPluginContext) => {
|
|
14
|
-
ctx.registerCommand({
|
|
15
|
-
name: 'update',
|
|
16
|
-
synopsisList: ['taro update self [version]', 'taro update project [version]'],
|
|
17
|
-
optionsMap: {
|
|
18
|
-
'--npm [npm]': '包管理工具',
|
|
19
|
-
'-h, --help': 'output usage information',
|
|
20
|
-
},
|
|
21
|
-
async fn({ _, options }) {
|
|
22
|
-
const { npm } = options;
|
|
23
|
-
const [, updateType, version] = _ as [string, ('self' | 'project')?, string?];
|
|
24
|
-
const { appPath, configPath } = ctx.paths;
|
|
25
|
-
const { chalk, fs, PROJECT_CONFIG, UPDATE_PACKAGE_LIST } = ctx.helper;
|
|
26
|
-
|
|
27
|
-
const pkgPath = path.join(appPath, 'package.json');
|
|
28
|
-
const pkgName = getPkgItemByKey('name');
|
|
29
|
-
const conf = {
|
|
30
|
-
npm: null,
|
|
31
|
-
};
|
|
32
|
-
const prompts: Record<string, unknown>[] = [];
|
|
33
|
-
|
|
34
|
-
async function getTargetVersion() {
|
|
35
|
-
let targetTaroVersion;
|
|
36
|
-
|
|
37
|
-
if (version) {
|
|
38
|
-
targetTaroVersion = semver.clean(version);
|
|
39
|
-
} else {
|
|
40
|
-
try {
|
|
41
|
-
targetTaroVersion = await getLatestVersion(pkgName, {
|
|
42
|
-
version: 'latest',
|
|
43
|
-
});
|
|
44
|
-
} catch (e) {
|
|
45
|
-
targetTaroVersion = await getLatestVersion(pkgName);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!semver.valid(targetTaroVersion)) {
|
|
49
|
-
console.log(chalk.red('命令错误:无效的 version ~'));
|
|
50
|
-
throw Error('无效的 version!');
|
|
51
|
-
}
|
|
52
|
-
return targetTaroVersion;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function execUpdate(command: string, version: string, isSelf = false) {
|
|
56
|
-
const updateTarget = isSelf ? ' CLI ' : ' Taro 项目依赖';
|
|
57
|
-
const spinString = `正在更新${updateTarget}到 v${version} ...`;
|
|
58
|
-
const spinner = ora(spinString).start();
|
|
59
|
-
execCommand({
|
|
60
|
-
command,
|
|
61
|
-
successCallback(data) {
|
|
62
|
-
spinner.stop();
|
|
63
|
-
console.log(data.replace(/\n$/, ''));
|
|
64
|
-
},
|
|
65
|
-
failCallback(data) {
|
|
66
|
-
spinner.stop();
|
|
67
|
-
spinner.warn(data.replace(/\n$/, ''));
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** 更新全局的 Taro CLI */
|
|
73
|
-
async function updateSelf() {
|
|
74
|
-
const spinner = ora('正在获取最新版本信息...').start();
|
|
75
|
-
const targetTaroVersion = await getTargetVersion();
|
|
76
|
-
spinner.stop();
|
|
77
|
-
console.log(chalk.green(`Taro 最新版本:${targetTaroVersion}\n`));
|
|
78
|
-
|
|
79
|
-
askNpm(conf, prompts);
|
|
80
|
-
const answers = npm ? { npm } : await inquirer.prompt(prompts);
|
|
81
|
-
|
|
82
|
-
const command = `${packagesManagement[answers.npm].globalCommand}@${targetTaroVersion}`;
|
|
83
|
-
execUpdate(command, targetTaroVersion, true);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** 更新当前项目中的 Taro 相关依赖 */
|
|
87
|
-
async function updateProject() {
|
|
88
|
-
if (!configPath || !fs.existsSync(configPath)) {
|
|
89
|
-
console.log(chalk.red(`找不到项目配置文件 ${PROJECT_CONFIG},请确定当前目录是 Taro 项目根目录!`));
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
const packageMap = require(pkgPath);
|
|
93
|
-
|
|
94
|
-
const spinner = ora('正在获取最新版本信息...').start();
|
|
95
|
-
|
|
96
|
-
const version = await getTargetVersion();
|
|
97
|
-
|
|
98
|
-
spinner.stop();
|
|
99
|
-
|
|
100
|
-
const oldVersion = packageMap.dependencies['@spcsn/taro'];
|
|
101
|
-
// 更新 @spcsn/* 底座版本
|
|
102
|
-
Object.keys(packageMap.dependencies || {}).forEach((key) => {
|
|
103
|
-
if (UPDATE_PACKAGE_LIST.indexOf(key) !== -1) {
|
|
104
|
-
packageMap.dependencies[key] = version;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
Object.keys(packageMap.devDependencies || {}).forEach((key) => {
|
|
108
|
-
if (UPDATE_PACKAGE_LIST.indexOf(key) !== -1) {
|
|
109
|
-
packageMap.devDependencies[key] = version;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// 写入package.json
|
|
114
|
-
try {
|
|
115
|
-
await fs.writeJson(pkgPath, packageMap, { spaces: '\t' });
|
|
116
|
-
console.log(
|
|
117
|
-
chalk.green(`项目当前 Taro 版本:${oldVersion},Taro 最新版本:${version},更新项目 package.json 成功!`),
|
|
118
|
-
);
|
|
119
|
-
console.log();
|
|
120
|
-
} catch (err) {
|
|
121
|
-
console.error(err);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
askNpm(conf, prompts);
|
|
125
|
-
const answers = npm ? { npm } : await inquirer.prompt(prompts);
|
|
126
|
-
|
|
127
|
-
const command = packagesManagement[answers.npm].command;
|
|
128
|
-
|
|
129
|
-
execUpdate(command, version);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function askNpm(conf, prompts) {
|
|
133
|
-
const packages = [
|
|
134
|
-
{
|
|
135
|
-
name: 'yarn',
|
|
136
|
-
value: 'yarn',
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: 'pnpm',
|
|
140
|
-
value: 'pnpm',
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
name: 'npm',
|
|
144
|
-
value: 'npm',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: 'cnpm',
|
|
148
|
-
value: 'cnpm',
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
if ((typeof conf.npm as string | undefined) !== 'string') {
|
|
153
|
-
prompts.push({
|
|
154
|
-
type: 'list',
|
|
155
|
-
name: 'npm',
|
|
156
|
-
message: '请选择包管理工具',
|
|
157
|
-
choices: packages,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (updateType === 'self') return updateSelf();
|
|
163
|
-
|
|
164
|
-
if (updateType === 'project') return updateProject();
|
|
165
|
-
|
|
166
|
-
console.log(chalk.red('命令错误:'));
|
|
167
|
-
console.log(
|
|
168
|
-
`${chalk.green('taro update self [version]')} 更新 Taro 开发工具 taro-cli 到指定版本或 Taro3 的最新版本`,
|
|
169
|
-
);
|
|
170
|
-
console.log(
|
|
171
|
-
`${chalk.green('taro update project [version]')} 更新项目所有 Taro 相关依赖到指定版本或 Taro3 的最新版本`,
|
|
172
|
-
);
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { fs } from '@spcsn/taro-helper';
|
|
4
|
-
import { getPlatformType } from '@spcsn/taro-shared';
|
|
5
|
-
|
|
6
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
7
|
-
|
|
8
|
-
const configName = 'mini';
|
|
9
|
-
export default (ctx: IPluginContext) => {
|
|
10
|
-
ctx.registerPlatform({
|
|
11
|
-
name: 'plugin',
|
|
12
|
-
useConfigName: configName,
|
|
13
|
-
async fn({ config }) {
|
|
14
|
-
const { options, _ } = ctx.runOpts;
|
|
15
|
-
const { chalk, PLATFORMS } = ctx.helper;
|
|
16
|
-
const { WEAPP } = PLATFORMS;
|
|
17
|
-
const typeMap = {
|
|
18
|
-
[WEAPP]: '微信',
|
|
19
|
-
};
|
|
20
|
-
const { plugin, isWatch } = options;
|
|
21
|
-
if (plugin !== WEAPP) {
|
|
22
|
-
console.log(chalk.red('当前 Fork 仅支持微信小程序插件编译!'));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
console.log(chalk.green(`开始编译${typeMap[plugin]}小程序插件`));
|
|
26
|
-
async function buildPlugin(platform) {
|
|
27
|
-
process.env.TARO_ENV = platform;
|
|
28
|
-
process.env.TARO_PLATFORM = getPlatformType(platform, configName);
|
|
29
|
-
await ctx.applyPlugins({
|
|
30
|
-
name: 'build',
|
|
31
|
-
opts: {
|
|
32
|
-
config: {
|
|
33
|
-
...config,
|
|
34
|
-
isBuildPlugin: true,
|
|
35
|
-
isWatch,
|
|
36
|
-
outputRoot: `${config.outputRoot}/plugin`,
|
|
37
|
-
platform,
|
|
38
|
-
},
|
|
39
|
-
options: Object.assign({}, options, {
|
|
40
|
-
platform,
|
|
41
|
-
}),
|
|
42
|
-
_,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
await ctx.applyPlugins({
|
|
46
|
-
name: 'build',
|
|
47
|
-
opts: {
|
|
48
|
-
config: {
|
|
49
|
-
...config,
|
|
50
|
-
isBuildPlugin: false,
|
|
51
|
-
isWatch,
|
|
52
|
-
outputRoot: `${config.outputRoot}/miniprogram`,
|
|
53
|
-
platform,
|
|
54
|
-
output: { ...(config.output || {}), clean: false },
|
|
55
|
-
},
|
|
56
|
-
options: Object.assign({}, options, {
|
|
57
|
-
platform,
|
|
58
|
-
}),
|
|
59
|
-
_,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
await buildPlugin(plugin);
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const docSrcPath = path.join(process.cwd(), 'src/plugin/doc');
|
|
68
|
-
const docDestPath = path.join(process.cwd(), 'miniprogram/doc');
|
|
69
|
-
fs.copy(docSrcPath, docDestPath);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
console.error('[@spcsn/taro-cli] build plugin doc failed: ', err);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
};
|