@spcsn/taro-cli 0.1.6 → 1.0.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.
- package/LICENSE +1 -153
- package/README.md +10 -7
- 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 +24 -27
- 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/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/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,125 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as os from 'node:os';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { chalk } from '@spcsn/taro-helper';
|
|
6
|
-
import * as child_process from 'child_process';
|
|
7
|
-
|
|
8
|
-
import { printDevelopmentTip } from '../../util';
|
|
9
|
-
|
|
10
|
-
import type { IPluginContext } from '@spcsn/taro-service';
|
|
11
|
-
|
|
12
|
-
function checkReactNativeDependencies(packageInfo): boolean {
|
|
13
|
-
const packageNames = ['react', 'react-native', '@spcsn/taro-rn', '@spcsn/taro-rn-runner'];
|
|
14
|
-
const { dependencies, devDependencies } = packageInfo;
|
|
15
|
-
for (let i = 0; i < packageNames.length; i++) {
|
|
16
|
-
if (!dependencies[packageNames[i]] && !devDependencies[packageNames[i]]) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function makeSureReactNativeInstalled(workspaceRoot: string): Promise<void> {
|
|
24
|
-
return new Promise<void>((resolve, reject) => {
|
|
25
|
-
const packageInfo = JSON.parse(
|
|
26
|
-
fs.readFileSync(path.join(workspaceRoot, 'package.json'), {
|
|
27
|
-
encoding: 'utf8',
|
|
28
|
-
}),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
if (checkReactNativeDependencies(packageInfo)) {
|
|
32
|
-
resolve();
|
|
33
|
-
} else {
|
|
34
|
-
// 便于开发时切换版本
|
|
35
|
-
const devTag = process.env.DEVTAG || '';
|
|
36
|
-
console.log('Installing React-Native related packages:');
|
|
37
|
-
let packages = `react@^18.2.0 react-dom@^18.2.0 react-native@^0.73.1 @react-native/metro-config@^0.73.2 expo@~50.0.2 @spcsn/taro-rn${devTag} @spcsn/taro-components-rn${devTag} @spcsn/taro-rn-runner${devTag} @spcsn/taro-rn-supporter${devTag} @spcsn/taro-runtime-rn${devTag}`;
|
|
38
|
-
console.log(packages);
|
|
39
|
-
// windows下不加引号的话,package.json中添加的依赖不会自动带上^
|
|
40
|
-
packages = packages
|
|
41
|
-
.split(' ')
|
|
42
|
-
.map((str) => `"${str}"`)
|
|
43
|
-
.join(' ');
|
|
44
|
-
let installCmd = `npm install ${packages} --save`;
|
|
45
|
-
if (fs.existsSync(path.join(workspaceRoot, 'yarn.lock'))) {
|
|
46
|
-
installCmd = `yarn add ${packages} --force`;
|
|
47
|
-
}
|
|
48
|
-
if (fs.existsSync(path.join(workspaceRoot, 'pnpm-lock.yaml'))) {
|
|
49
|
-
installCmd = `pnpm add ${packages}`;
|
|
50
|
-
}
|
|
51
|
-
child_process.exec(installCmd, (error) => {
|
|
52
|
-
if (error) {
|
|
53
|
-
reject(error);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
console.log(chalk.green(`React-Native related packages have been installed successfully.${os.EOL}${os.EOL}`));
|
|
57
|
-
console.log(
|
|
58
|
-
`${chalk.yellow('ATTEHNTION')}: Package.json has been modified automatically, please submit it by yourself.${os.EOL}${os.EOL}`,
|
|
59
|
-
);
|
|
60
|
-
resolve();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default (ctx: IPluginContext) => {
|
|
67
|
-
ctx.registerPlatform({
|
|
68
|
-
name: 'rn',
|
|
69
|
-
useConfigName: 'rn',
|
|
70
|
-
async fn({ config }) {
|
|
71
|
-
const { appPath, nodeModulesPath } = ctx.paths;
|
|
72
|
-
const { npm } = ctx.helper;
|
|
73
|
-
const {
|
|
74
|
-
deviceType = 'android',
|
|
75
|
-
port,
|
|
76
|
-
resetCache,
|
|
77
|
-
publicPath,
|
|
78
|
-
bundleOutput,
|
|
79
|
-
sourcemapOutput,
|
|
80
|
-
sourceMapUrl,
|
|
81
|
-
sourcemapSourcesRoot,
|
|
82
|
-
assetsDest,
|
|
83
|
-
qr,
|
|
84
|
-
} = ctx.runOpts.options;
|
|
85
|
-
|
|
86
|
-
printDevelopmentTip('rn');
|
|
87
|
-
|
|
88
|
-
// 准备 rnRunner 参数
|
|
89
|
-
const rnRunnerOpts = {
|
|
90
|
-
...config,
|
|
91
|
-
nodeModulesPath,
|
|
92
|
-
deviceType,
|
|
93
|
-
port,
|
|
94
|
-
qr,
|
|
95
|
-
resetCache,
|
|
96
|
-
publicPath,
|
|
97
|
-
bundleOutput,
|
|
98
|
-
sourcemapOutput,
|
|
99
|
-
sourceMapUrl,
|
|
100
|
-
sourcemapSourcesRoot,
|
|
101
|
-
assetsDest,
|
|
102
|
-
buildAdapter: config.platform,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (!rnRunnerOpts.entry) {
|
|
106
|
-
rnRunnerOpts.entry = 'app';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
makeSureReactNativeInstalled(appPath).then(
|
|
110
|
-
async () => {
|
|
111
|
-
// build with metro
|
|
112
|
-
const rnRunner = await npm.getNpmPkg('@spcsn/taro-rn-runner', appPath);
|
|
113
|
-
await rnRunner(appPath, rnRunnerOpts);
|
|
114
|
-
},
|
|
115
|
-
(error) => {
|
|
116
|
-
console.log(chalk.red('Error when detecting React-Native packages:'));
|
|
117
|
-
console.log(error);
|
|
118
|
-
console.log(
|
|
119
|
-
`${chalk.greenBright('TIP')}: 1) Try to remove React-Native dependencies in package.json and shoot again; 2) Install the packages above manually.`,
|
|
120
|
-
);
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
};
|
package/src/util/createPage.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { babelKit } from '@spcsn/taro-helper';
|
|
2
|
-
|
|
3
|
-
import { ConfigModificationState, ModifyCallback } from '../create/page';
|
|
4
|
-
|
|
5
|
-
import type { ArrayExpression, ExportDefaultDeclaration, ObjectExpression, ObjectProperty } from '@babel/types';
|
|
6
|
-
import type { NodePath } from 'babel__traverse';
|
|
7
|
-
|
|
8
|
-
const t = babelKit.types;
|
|
9
|
-
|
|
10
|
-
const generateNewSubPackageItem = (subPackage: string) => {
|
|
11
|
-
const pageObject = t.objectProperty(t.identifier('pages'), t.arrayExpression([]));
|
|
12
|
-
const subPkgRootObject = t.objectProperty(t.identifier('root'), t.stringLiteral(subPackage));
|
|
13
|
-
const subPkgItemObject = t.objectExpression([subPkgRootObject, pageObject]);
|
|
14
|
-
return subPkgItemObject;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const isValidSubPkgObject = (subPkgObject: ObjectExpression) => {
|
|
18
|
-
const properties = subPkgObject?.properties || {};
|
|
19
|
-
const rootProperty = properties.find(
|
|
20
|
-
(property) => (property as ObjectProperty).key && ((property as ObjectProperty).key as any)?.name === 'root',
|
|
21
|
-
) as ObjectProperty;
|
|
22
|
-
const pagesProperty = properties.find(
|
|
23
|
-
(property) => (property as ObjectProperty).key && ((property as ObjectProperty).key as any)?.name === 'pages',
|
|
24
|
-
) as ObjectProperty;
|
|
25
|
-
const rootPropertyValueType = rootProperty?.value?.type;
|
|
26
|
-
const pagesPropertyValueType = pagesProperty?.value?.type;
|
|
27
|
-
return rootPropertyValueType === 'StringLiteral' && pagesPropertyValueType === 'ArrayExpression';
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const addNewSubPackage = (node: ObjectExpression, page: string, subPackage: string): ConfigModificationState => {
|
|
31
|
-
let subPackages = node?.properties.find((node) => (node as any).key.name === 'subPackages') as ObjectProperty;
|
|
32
|
-
if (!subPackages) {
|
|
33
|
-
// config 文件不存在 subPackages 字段的情况,给该字段赋予默认值
|
|
34
|
-
const subPkgObject = t.objectProperty(t.identifier('subPackages'), t.arrayExpression([]));
|
|
35
|
-
subPackages = subPkgObject;
|
|
36
|
-
node?.properties.push(subPkgObject);
|
|
37
|
-
}
|
|
38
|
-
const value = subPackages?.value;
|
|
39
|
-
|
|
40
|
-
// 文件格式不对的情况
|
|
41
|
-
if (!value || value?.type !== 'ArrayExpression') return ConfigModificationState.Fail;
|
|
42
|
-
let targetSubPkgObject: ObjectExpression = value.elements.find((node) =>
|
|
43
|
-
(node as any)?.properties?.find((property) => (property as any)?.value?.value === subPackage),
|
|
44
|
-
) as ObjectExpression;
|
|
45
|
-
|
|
46
|
-
if (!targetSubPkgObject) {
|
|
47
|
-
// 不存在 当前分包配置对象的情况
|
|
48
|
-
const subPkgItemObject = generateNewSubPackageItem(subPackage);
|
|
49
|
-
targetSubPkgObject = subPkgItemObject;
|
|
50
|
-
value.elements.push(subPkgItemObject);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (targetSubPkgObject.type !== 'ObjectExpression' || !isValidSubPkgObject(targetSubPkgObject))
|
|
54
|
-
return ConfigModificationState.Fail;
|
|
55
|
-
const pagesProperty: ObjectProperty = targetSubPkgObject.properties.find(
|
|
56
|
-
(property) => (property as ObjectProperty).key && ((property as ObjectProperty).key as any)?.name === 'pages',
|
|
57
|
-
) as ObjectProperty;
|
|
58
|
-
const currentPages = (pagesProperty.value as ArrayExpression).elements;
|
|
59
|
-
const isPageExists = Boolean(currentPages.find((node) => (node as any).value === page));
|
|
60
|
-
|
|
61
|
-
if (isPageExists) return ConfigModificationState.NeedLess;
|
|
62
|
-
|
|
63
|
-
currentPages.push(t.stringLiteral(page));
|
|
64
|
-
return ConfigModificationState.Success;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const addNewPage = (node: ObjectExpression, page: string): ConfigModificationState => {
|
|
68
|
-
const pages = node?.properties.find((node) => (node as any).key.name === 'pages') as ObjectProperty;
|
|
69
|
-
if (!pages) return ConfigModificationState.Fail;
|
|
70
|
-
|
|
71
|
-
const value = pages?.value;
|
|
72
|
-
// 仅处理 pages 为数组字面量的情形
|
|
73
|
-
if (!value || value?.type !== 'ArrayExpression') return ConfigModificationState.Fail;
|
|
74
|
-
|
|
75
|
-
const isPageExists = Boolean(value.elements.find((node) => (node as any).value === page));
|
|
76
|
-
if (isPageExists) return ConfigModificationState.NeedLess;
|
|
77
|
-
|
|
78
|
-
const newArrayElement = t.stringLiteral(page);
|
|
79
|
-
value.elements.push(newArrayElement);
|
|
80
|
-
|
|
81
|
-
return ConfigModificationState.Success;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const modifyPages = (path: NodePath<ExportDefaultDeclaration>, newPageConfig, callback: ModifyCallback) => {
|
|
85
|
-
let state = ConfigModificationState.Fail;
|
|
86
|
-
const node = path.node.declaration as any;
|
|
87
|
-
// Case 1. `export default defineAppConfig({})` 这种情况
|
|
88
|
-
if (node.type === 'CallExpression' && node.callee.name === 'defineAppConfig') {
|
|
89
|
-
const configNode = node.arguments[0];
|
|
90
|
-
state = addNewPage(configNode, newPageConfig.page);
|
|
91
|
-
}
|
|
92
|
-
// Case 2. `export default {}` 这种情况
|
|
93
|
-
if (node.type === 'ObjectExpression') {
|
|
94
|
-
state = addNewPage(node, newPageConfig.page);
|
|
95
|
-
}
|
|
96
|
-
callback(state);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const modifySubPackages = (path: NodePath<ExportDefaultDeclaration>, newPageConfig, callback: ModifyCallback) => {
|
|
100
|
-
let state = ConfigModificationState.Fail;
|
|
101
|
-
const node = path.node.declaration as any;
|
|
102
|
-
// `export default defineAppConfig({})` 这种情况
|
|
103
|
-
if (node.type === 'CallExpression' && node.callee.name === 'defineAppConfig') {
|
|
104
|
-
const configNode = node.arguments[0];
|
|
105
|
-
state = addNewSubPackage(configNode, newPageConfig.page, newPageConfig.pkg);
|
|
106
|
-
}
|
|
107
|
-
// `export default {}` 这种情况
|
|
108
|
-
if (node.type === 'ObjectExpression') {
|
|
109
|
-
state = addNewSubPackage(node, newPageConfig.page, newPageConfig.pkg);
|
|
110
|
-
}
|
|
111
|
-
callback(state);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const generateNewPageConfig = (fullPagePath: string, subPkgRootPath = '') => {
|
|
115
|
-
const newPageConfig = {
|
|
116
|
-
pkg: '',
|
|
117
|
-
page: '',
|
|
118
|
-
};
|
|
119
|
-
if (subPkgRootPath) {
|
|
120
|
-
const processedSubPkg = `${subPkgRootPath}/`;
|
|
121
|
-
newPageConfig.pkg = processedSubPkg;
|
|
122
|
-
newPageConfig.page = fullPagePath.split(processedSubPkg)[1];
|
|
123
|
-
} else {
|
|
124
|
-
newPageConfig.page = fullPagePath;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return newPageConfig;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const modifyPagesOrSubPackages = (params: {
|
|
131
|
-
path: NodePath<ExportDefaultDeclaration>;
|
|
132
|
-
fullPagePath: string;
|
|
133
|
-
subPkgRootPath?: string;
|
|
134
|
-
callback: ModifyCallback;
|
|
135
|
-
}) => {
|
|
136
|
-
const { fullPagePath, subPkgRootPath, callback, path } = params;
|
|
137
|
-
const newPageConfig = generateNewPageConfig(fullPagePath, subPkgRootPath);
|
|
138
|
-
subPkgRootPath ? modifySubPackages(path, newPageConfig, callback) : modifyPages(path, newPageConfig, callback);
|
|
139
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// babel-preset-taro 更多选项和默认值:
|
|
2
|
-
// https://docs.taro.zone/docs/next/babel-config
|
|
3
|
-
module.exports = {
|
|
4
|
-
presets: [
|
|
5
|
-
['taro', {
|
|
6
|
-
framework: '{{ to_lower_case framework }}',
|
|
7
|
-
ts: {{ typescript }},
|
|
8
|
-
compiler: '{{ to_lower_case compiler }}',
|
|
9
|
-
{{#if buildEs5 }}
|
|
10
|
-
useBuiltIns: process.env.TARO_ENV === 'h5' ? 'usage' : false
|
|
11
|
-
{{/if}}
|
|
12
|
-
}]
|
|
13
|
-
]
|
|
14
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|