@spcsn/taro-cli 0.1.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/LICENSE +174 -0
- package/README.md +0 -0
- package/bin/taro +7 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +266 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/customCommand.d.ts +5 -0
- package/dist/commands/customCommand.js +23 -0
- package/dist/commands/customCommand.js.map +1 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +10 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/packagesManagement.d.ts +19 -0
- package/dist/config/packagesManagement.js +22 -0
- package/dist/config/packagesManagement.js.map +1 -0
- package/dist/create/constants.d.ts +1 -0
- package/dist/create/constants.js +5 -0
- package/dist/create/constants.js.map +1 -0
- package/dist/create/creator.d.ts +9 -0
- package/dist/create/creator.js +64 -0
- package/dist/create/creator.js.map +1 -0
- package/dist/create/fetchTemplate.d.ts +8 -0
- package/dist/create/fetchTemplate.js +169 -0
- package/dist/create/fetchTemplate.js.map +1 -0
- package/dist/create/page.d.ts +65 -0
- package/dist/create/page.js +266 -0
- package/dist/create/page.js.map +1 -0
- package/dist/create/plugin.d.ts +16 -0
- package/dist/create/plugin.js +77 -0
- package/dist/create/plugin.js.map +1 -0
- package/dist/create/project.d.ts +70 -0
- package/dist/create/project.js +481 -0
- package/dist/create/project.js.map +1 -0
- package/dist/doctor/index.d.ts +4 -0
- package/dist/doctor/index.js +23 -0
- package/dist/doctor/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/presets/commands/build.d.ts +3 -0
- package/dist/presets/commands/build.js +236 -0
- package/dist/presets/commands/build.js.map +1 -0
- package/dist/presets/commands/config.d.ts +3 -0
- package/dist/presets/commands/config.js +121 -0
- package/dist/presets/commands/config.js.map +1 -0
- package/dist/presets/commands/create.d.ts +3 -0
- package/dist/presets/commands/create.js +112 -0
- package/dist/presets/commands/create.js.map +1 -0
- package/dist/presets/commands/global-config.d.ts +3 -0
- package/dist/presets/commands/global-config.js +175 -0
- package/dist/presets/commands/global-config.js.map +1 -0
- package/dist/presets/commands/help.d.ts +3 -0
- package/dist/presets/commands/help.js +16 -0
- package/dist/presets/commands/help.js.map +1 -0
- package/dist/presets/commands/info.d.ts +3 -0
- package/dist/presets/commands/info.js +96 -0
- package/dist/presets/commands/info.js.map +1 -0
- package/dist/presets/commands/init.d.ts +3 -0
- package/dist/presets/commands/init.js +46 -0
- package/dist/presets/commands/init.js.map +1 -0
- package/dist/presets/commands/inspect.d.ts +3 -0
- package/dist/presets/commands/inspect.js +155 -0
- package/dist/presets/commands/inspect.js.map +1 -0
- package/dist/presets/commands/update.d.ts +3 -0
- package/dist/presets/commands/update.js +187 -0
- package/dist/presets/commands/update.js.map +1 -0
- package/dist/presets/constant/hooks.d.ts +13 -0
- package/dist/presets/constant/hooks.js +17 -0
- package/dist/presets/constant/hooks.js.map +1 -0
- package/dist/presets/constant/index.d.ts +1 -0
- package/dist/presets/constant/index.js +18 -0
- package/dist/presets/constant/index.js.map +1 -0
- package/dist/presets/files/generateFrameworkInfo.d.ts +3 -0
- package/dist/presets/files/generateFrameworkInfo.js +30 -0
- package/dist/presets/files/generateFrameworkInfo.js.map +1 -0
- package/dist/presets/files/generateProjectConfig.d.ts +3 -0
- package/dist/presets/files/generateProjectConfig.js +72 -0
- package/dist/presets/files/generateProjectConfig.js.map +1 -0
- package/dist/presets/files/writeFileToDist.d.ts +3 -0
- package/dist/presets/files/writeFileToDist.js +50 -0
- package/dist/presets/files/writeFileToDist.js.map +1 -0
- package/dist/presets/hooks/build.d.ts +3 -0
- package/dist/presets/hooks/build.js +55 -0
- package/dist/presets/hooks/build.js.map +1 -0
- package/dist/presets/hooks/create.d.ts +3 -0
- package/dist/presets/hooks/create.js +42 -0
- package/dist/presets/hooks/create.js.map +1 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/index.js +50 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/platforms/plugin.d.ts +3 -0
- package/dist/presets/platforms/plugin.js +106 -0
- package/dist/presets/platforms/plugin.js.map +1 -0
- package/dist/presets/platforms/rn.d.ts +3 -0
- package/dist/presets/platforms/rn.js +130 -0
- package/dist/presets/platforms/rn.js.map +1 -0
- package/dist/util/appConfig.d.ts +11 -0
- package/dist/util/appConfig.js +27 -0
- package/dist/util/appConfig.js.map +1 -0
- package/dist/util/createPage.d.ts +9 -0
- package/dist/util/createPage.js +114 -0
- package/dist/util/createPage.js.map +1 -0
- package/dist/util/defineConfig.d.ts +17 -0
- package/dist/util/defineConfig.js +11 -0
- package/dist/util/defineConfig.js.map +1 -0
- package/dist/util/index.d.ts +23 -0
- package/dist/util/index.js +149 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/types.d.ts +58 -0
- package/dist/util/types.js +3 -0
- package/dist/util/types.js.map +1 -0
- package/global.d.ts +4 -0
- package/index.js +3 -0
- package/package.json +74 -0
- package/postinstall.js +17 -0
- package/src/__tests__/__mocks__/presets.ts +15 -0
- package/src/__tests__/build-config.spec.ts +66 -0
- package/src/__tests__/cli.spec.ts +226 -0
- package/src/__tests__/config.spec.ts +224 -0
- package/src/__tests__/doctor-config.spec.ts +943 -0
- package/src/__tests__/doctor-recommand.spec.ts +136 -0
- package/src/__tests__/doctor.spec.ts +94 -0
- package/src/__tests__/dotenv-parse.spec.ts +105 -0
- package/src/__tests__/env/.env +2 -0
- package/src/__tests__/fixtures/default/.env +3 -0
- package/src/__tests__/fixtures/default/.env.development +1 -0
- package/src/__tests__/fixtures/default/.env.local +1 -0
- package/src/__tests__/fixtures/default/.env.pre +3 -0
- package/src/__tests__/fixtures/default/.env.production +1 -0
- package/src/__tests__/fixtures/default/.env.uat +5 -0
- package/src/__tests__/fixtures/default/.env.uat.local +1 -0
- package/src/__tests__/fixtures/default/babel.config.js +10 -0
- package/src/__tests__/fixtures/default/config/dev.js +9 -0
- package/src/__tests__/fixtures/default/config/index.js +84 -0
- package/src/__tests__/fixtures/default/config/prod.js +18 -0
- package/src/__tests__/fixtures/default/package.json +27 -0
- package/src/__tests__/fixtures/default/src/app.config.js +11 -0
- package/src/__tests__/fixtures/default/src/app.js +16 -0
- package/src/__tests__/fixtures/default/src/app.scss +0 -0
- package/src/__tests__/fixtures/default/src/index.html +19 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.config.js +3 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.jsx +22 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
- package/src/__tests__/info.spec.ts +72 -0
- package/src/__tests__/inspect.spec.ts +160 -0
- package/src/__tests__/update.spec.ts +310 -0
- package/src/__tests__/utils/index.ts +54 -0
- package/src/cli.ts +240 -0
- package/src/commands/customCommand.ts +22 -0
- package/src/config/index.ts +7 -0
- package/src/config/manifest.default.json +33 -0
- package/src/config/packagesManagement.ts +20 -0
- package/src/config/rn-stylelint.json +4 -0
- package/src/config/tsconfig.json +22 -0
- package/src/create/constants.ts +1 -0
- package/src/create/creator.ts +37 -0
- package/src/create/fetchTemplate.ts +161 -0
- package/src/create/page.ts +325 -0
- package/src/create/plugin.ts +55 -0
- package/src/create/project.ts +539 -0
- package/src/doctor/index.ts +21 -0
- package/src/index.ts +24 -0
- package/src/presets/commands/build.ts +215 -0
- package/src/presets/commands/config.ts +86 -0
- package/src/presets/commands/create.ts +104 -0
- package/src/presets/commands/global-config.ts +140 -0
- package/src/presets/commands/help.ts +17 -0
- package/src/presets/commands/info.ts +81 -0
- package/src/presets/commands/init.ts +63 -0
- package/src/presets/commands/inspect.ts +137 -0
- package/src/presets/commands/update.ts +175 -0
- package/src/presets/constant/hooks.ts +14 -0
- package/src/presets/constant/index.ts +1 -0
- package/src/presets/files/generateFrameworkInfo.ts +30 -0
- package/src/presets/files/generateProjectConfig.ts +41 -0
- package/src/presets/files/writeFileToDist.ts +17 -0
- package/src/presets/hooks/build.ts +22 -0
- package/src/presets/hooks/create.ts +9 -0
- package/src/presets/index.ts +15 -0
- package/src/presets/platforms/plugin.ts +75 -0
- package/src/presets/platforms/rn.ts +125 -0
- package/src/util/appConfig.ts +32 -0
- package/src/util/createPage.ts +139 -0
- package/src/util/defineConfig.ts +28 -0
- package/src/util/index.ts +126 -0
- package/src/util/types.ts +81 -0
- package/templates/default/_editorconfig +12 -0
- package/templates/default/_env.development +2 -0
- package/templates/default/_env.production +1 -0
- package/templates/default/_env.test +1 -0
- package/templates/default/_gitignore +8 -0
- package/templates/default/babel.config.js +14 -0
- package/templates/default/config/dev.js +5 -0
- package/templates/default/config/index.js +61 -0
- package/templates/default/config/prod.js +5 -0
- package/templates/default/package.json.tmpl +52 -0
- package/templates/default/project.config.json +15 -0
- package/templates/default/src/app.config.js +11 -0
- package/templates/default/src/app.css +0 -0
- package/templates/default/src/app.js +15 -0
- package/templates/default/src/pages/index/index.config.js +3 -0
- package/templates/default/src/pages/index/index.css +0 -0
- package/templates/default/src/pages/index/index.jsx +15 -0
- package/templates/default/template_creator.js +61 -0
- package/templates/default/tsconfig.json +30 -0
- package/templates/default/types/global.d.ts +27 -0
- package/templates/global-config/index.json +4 -0
- package/templates/global-config/package.json +5 -0
- package/templates/plugin-compile/README.md +32 -0
- package/templates/plugin-compile/index.js +3 -0
- package/templates/plugin-compile/package.json.tmpl +43 -0
- package/templates/plugin-compile/src/index.ts +153 -0
- package/templates/plugin-compile/tsconfig.json +28 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ projectName }}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "{{ description }}",
|
|
6
|
+
"templateInfo": {
|
|
7
|
+
"name": "{{ template }}",
|
|
8
|
+
"typescript": {{ typescript }},
|
|
9
|
+
"css": "{{ css }}",
|
|
10
|
+
"framework": "{{ framework }}"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"new": "taro new",
|
|
14
|
+
"build:weapp": "taro build --type weapp",
|
|
15
|
+
"dev:weapp": "npm run build:weapp -- --watch"
|
|
16
|
+
},
|
|
17
|
+
{{#if buildEs5 }}
|
|
18
|
+
"browserslist": {
|
|
19
|
+
"development": [
|
|
20
|
+
"defaults and fully supports es6-module",
|
|
21
|
+
"maintained node versions"
|
|
22
|
+
],
|
|
23
|
+
"production": [
|
|
24
|
+
"last 3 versions",
|
|
25
|
+
"Android >= 4.1",
|
|
26
|
+
"ios >= 8"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{{else}}
|
|
30
|
+
"browserslist": [
|
|
31
|
+
"defaults and fully supports es6-module",
|
|
32
|
+
"maintained node versions"
|
|
33
|
+
],
|
|
34
|
+
{{/if}}
|
|
35
|
+
"author": "",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@spcsn/taro-components": "{{ version }}",
|
|
38
|
+
"@spcsn/taro": "{{ version }}",
|
|
39
|
+
"react-dom": "^19.2.0",
|
|
40
|
+
"react": "^19.2.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@spcsn/taro-cli": "{{ version }}",
|
|
44
|
+
"@types/react": "^19.2.14",
|
|
45
|
+
"@types/react-dom": "^19.2.3",{{#if (eq css "Sass") }}
|
|
46
|
+
"sass": "^1.75.0",{{/if}}{{#if (eq css "Less") }}
|
|
47
|
+
"less": "^4.2.0",{{/if}}{{#if (eq css "Stylus") }}
|
|
48
|
+
"stylus": "^0.63.0",{{/if}}{{#if typescript }}
|
|
49
|
+
"typescript": "^5.9.3",{{/if}}
|
|
50
|
+
"@types/minimatch": "^5"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"miniprogramRoot": "./dist",
|
|
3
|
+
"projectname": "{{ projectName }}",
|
|
4
|
+
"description": "{{ description }}",
|
|
5
|
+
"appid": "touristappid",
|
|
6
|
+
"setting": {
|
|
7
|
+
"urlCheck": true,
|
|
8
|
+
"es6": false,
|
|
9
|
+
"enhance": false,
|
|
10
|
+
"compileHotReLoad": false,
|
|
11
|
+
"postcss": false,
|
|
12
|
+
"minified": false
|
|
13
|
+
},
|
|
14
|
+
"compileType": "miniprogram"
|
|
15
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{#if typescript }}import { PropsWithChildren } from 'react'{{/if}}
|
|
2
|
+
import { useLaunch } from '@spcsn/taro'
|
|
3
|
+
|
|
4
|
+
import './app.{{ cssExt }}'
|
|
5
|
+
|
|
6
|
+
function App({ children }{{#if typescript }}: PropsWithChildren<any>{{/if}}) {
|
|
7
|
+
useLaunch(() => {
|
|
8
|
+
console.log('App launched.')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// children 是将要会渲染的页面
|
|
12
|
+
return children
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default App
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { View, Text } from '@spcsn/taro-components'
|
|
2
|
+
import { useLoad } from '@spcsn/taro'
|
|
3
|
+
import './index.{{ cssExt }}'
|
|
4
|
+
|
|
5
|
+
export default function {{ to_pascal_case pageName }} () {
|
|
6
|
+
useLoad(() => {
|
|
7
|
+
console.log('Page loaded.')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<View className='{{ pageName }}'>
|
|
12
|
+
<Text>Hello world!</Text>
|
|
13
|
+
</View>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
function createWhenTs (err, params) {
|
|
4
|
+
return !!params.typescript
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function normalizePath (path) {
|
|
8
|
+
return path.replace(/\\/g, '/').replace(/\/{2,}/g, '/')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const SOURCE_ENTRY = '/src'
|
|
12
|
+
const PAGES_ENTRY = '/src/pages'
|
|
13
|
+
|
|
14
|
+
const handler = {
|
|
15
|
+
'/tsconfig.json': createWhenTs,
|
|
16
|
+
'/types/global.d.ts': createWhenTs,
|
|
17
|
+
'/src/pages/index/index.jsx' (err, { pageDir = '', pageName = '', subPkg = '' }) {
|
|
18
|
+
return {
|
|
19
|
+
setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.jsx')),
|
|
20
|
+
setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.jsx'))
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
'/src/pages/index/index.css' (err, { pageDir = '', pageName = '', subPkg = '' }) {
|
|
24
|
+
return {
|
|
25
|
+
setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.css')),
|
|
26
|
+
setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.css'))
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
'/src/pages/index/index.config.js' (err, { pageDir = '', pageName = '', subPkg = '' }) {
|
|
30
|
+
return {
|
|
31
|
+
setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.config.js')),
|
|
32
|
+
setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.config.js'))
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
'/_editorconfig' () {
|
|
36
|
+
return { setPageName: `/.editorconfig` }
|
|
37
|
+
},
|
|
38
|
+
'/_env.development' () {
|
|
39
|
+
return { setPageName: `/.env.development` }
|
|
40
|
+
},
|
|
41
|
+
'/_env.production' () {
|
|
42
|
+
return { setPageName: `/.env.production` }
|
|
43
|
+
},
|
|
44
|
+
'/_env.test' () {
|
|
45
|
+
return { setPageName: `/.env.test` }
|
|
46
|
+
},
|
|
47
|
+
'/_gitignore' () {
|
|
48
|
+
return { setPageName: `/.gitignore` }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const basePageFiles = [
|
|
53
|
+
'/src/pages/index/index.jsx',
|
|
54
|
+
'/src/pages/index/index.css',
|
|
55
|
+
'/src/pages/index/index.config.js'
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
handler,
|
|
60
|
+
basePageFiles
|
|
61
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"removeComments": false,
|
|
6
|
+
"preserveConstEnums": true,
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"noImplicitAny": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"outDir": "lib",
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"rootDir": ".",
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
"allowJs": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"typeRoots": [
|
|
21
|
+
"node_modules/@types"
|
|
22
|
+
],
|
|
23
|
+
"paths": {
|
|
24
|
+
// TS5090 leading './'
|
|
25
|
+
"@/*": ["./src/*"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"include": ["./src", "./types", "./config"],
|
|
29
|
+
"compileOnSave": false
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="@spcsn/taro" />
|
|
2
|
+
|
|
3
|
+
declare module '*.png';
|
|
4
|
+
declare module '*.gif';
|
|
5
|
+
declare module '*.jpg';
|
|
6
|
+
declare module '*.jpeg';
|
|
7
|
+
declare module '*.svg';
|
|
8
|
+
declare module '*.css';
|
|
9
|
+
declare module '*.less';
|
|
10
|
+
declare module '*.scss';
|
|
11
|
+
declare module '*.sass';
|
|
12
|
+
declare module '*.styl';
|
|
13
|
+
|
|
14
|
+
declare namespace NodeJS {
|
|
15
|
+
interface ProcessEnv {
|
|
16
|
+
/** NODE 内置环境变量, 会影响到最终构建生成产物 */
|
|
17
|
+
NODE_ENV: 'development' | 'production',
|
|
18
|
+
/** 当前构建的平台(当前 fork 仅支持 weapp) */
|
|
19
|
+
TARO_ENV: 'weapp'
|
|
20
|
+
/**
|
|
21
|
+
* 当前构建的小程序 appid
|
|
22
|
+
* @description 若不同环境有不同的小程序,可通过在 env 文件中配置环境变量`TARO_APP_ID`来方便快速切换 appid, 而不必手动去修改 dist/project.config.json 文件
|
|
23
|
+
* @see https://taro-docs.jd.com/docs/next/env-mode-config#特殊环境变量-taro_app_id
|
|
24
|
+
*/
|
|
25
|
+
TARO_APP_ID: string
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# {{ projectName }}
|
|
2
|
+
|
|
3
|
+
> {{ description }}
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
### 安装
|
|
8
|
+
```
|
|
9
|
+
npm i {{ projectName }} -D
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 使用插件
|
|
13
|
+
`/config/index.js`
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
{{#if (eq pluginType "plugin-template") }}
|
|
17
|
+
/**插件参数为 IPluginOpts {
|
|
18
|
+
* installPath: string 安装的路径
|
|
19
|
+
* css?: 'none' | 'sass' | 'stylus' | 'less'
|
|
20
|
+
* typescript?: boolean
|
|
21
|
+
* compiler?: 'webpack5' | 'vite'
|
|
22
|
+
* }
|
|
23
|
+
* 这些参数后续会被模版文件解析所用
|
|
24
|
+
* 如果不传,会从 package.json 的 templateInfo
|
|
25
|
+
*/
|
|
26
|
+
{{/if}}
|
|
27
|
+
const config = {
|
|
28
|
+
plugins: [
|
|
29
|
+
["{{ projectName }}"{{#if (eq pluginType "plugin-template") }}, { installPath:'/xxx/xx/x' }{{/if}}]
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ projectName }}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "{{ description }}",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Taro",
|
|
7
|
+
"Plugin"
|
|
8
|
+
],
|
|
9
|
+
"author": "",
|
|
10
|
+
"homepage": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"typings": "types/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"index.js",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": ""
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"dev": "tsc -w"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": ""
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@spcsn/taro-service": "^{{ version }}"{{#if (eq pluginType "plugin-build") }},
|
|
32
|
+
"webpack-chain": "^6.5.1"{{/if}}{{#if (eq pluginType "plugin-template") }},
|
|
33
|
+
"download": "^8.0.0",
|
|
34
|
+
"fs-extra": "^11.2.0",
|
|
35
|
+
"unzip": "^0.1.11"{{/if}}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.19.19"
|
|
39
|
+
}{{#if (eq pluginType "plugin-template") }},
|
|
40
|
+
"resolutions": {
|
|
41
|
+
"graceful-fs": "^4.2.11"
|
|
42
|
+
}{{/if}}
|
|
43
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { IPluginContext } from '@spcsn/taro-service'
|
|
2
|
+
{{#if (eq pluginType "plugin-build") }}
|
|
3
|
+
import webpackChain from 'webpack-chain'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 编译过程扩展
|
|
7
|
+
*/
|
|
8
|
+
export default (ctx: IPluginContext, pluginOpts) => {
|
|
9
|
+
ctx.onBuildStart(() => {
|
|
10
|
+
console.log('插件入参:', pluginOpts)
|
|
11
|
+
console.log('编译开始')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
ctx.modifyWebpackChain(({ chain }: { chain: webpackChain }) => {
|
|
15
|
+
console.log('这里可以修改webpack配置')
|
|
16
|
+
// 示例:利用webpackChain向html中插入脚本
|
|
17
|
+
if (process.env.TARO_ENV !== 'h5') return
|
|
18
|
+
chain
|
|
19
|
+
.plugin('htmlWebpackPlugin')
|
|
20
|
+
.tap(([pluginConfig]) => {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
...pluginConfig,
|
|
24
|
+
script: pluginConfig.script + 'console.log("向html中插入代码");'
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
ctx.onBuildComplete(() => {
|
|
31
|
+
console.log('Taro 构建完成!')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
ctx.modifyBuildAssets(({ assets }) => {
|
|
35
|
+
console.log('修改编译后的结果')
|
|
36
|
+
// 示例:修改html产物内容
|
|
37
|
+
const indexHtml = assets['index.html']
|
|
38
|
+
if (indexHtml && indexHtml._value) {
|
|
39
|
+
indexHtml._value = indexHtml._value.replace(/<title>(.*?)<\/title>/,'<title>被插件修改过的标题</title>')
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
ctx.onBuildFinish(() => {
|
|
44
|
+
console.log('Webpack 编译结束!')
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
{{/if}}
|
|
48
|
+
{{#if (eq pluginType "plugin-command") }}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 命令行扩展
|
|
52
|
+
*/
|
|
53
|
+
export default (ctx: IPluginContext, pluginOpts) => {
|
|
54
|
+
ctx.registerCommand({
|
|
55
|
+
// 命令名
|
|
56
|
+
name: 'say',
|
|
57
|
+
// 参数说明,执行 taro say --help 时输出的 options 信息
|
|
58
|
+
optionsMap: {
|
|
59
|
+
'--msg': '输出的信息',
|
|
60
|
+
},
|
|
61
|
+
// 执行 taro say --help 时输出的使用例子的信息
|
|
62
|
+
synopsisList: ['taro say --msg Hello!'],
|
|
63
|
+
// 命令钩子
|
|
64
|
+
async fn() {
|
|
65
|
+
console.log('插件入参:', pluginOpts)
|
|
66
|
+
const { msg } = ctx.runOpts.options
|
|
67
|
+
console.log('Taro say:', msg)
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
{{/if}}
|
|
72
|
+
{{#if (eq pluginType "plugin-template") }}
|
|
73
|
+
import * as fs from 'fs-extra'
|
|
74
|
+
const path = require('path')
|
|
75
|
+
const download = require('download')
|
|
76
|
+
const unzip = require("unzip")
|
|
77
|
+
/**
|
|
78
|
+
* 创建 page 自定义模版
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
interface ITemplateInfo {
|
|
82
|
+
css: 'none' | 'sass' | 'stylus' | 'less'
|
|
83
|
+
typescript?: boolean
|
|
84
|
+
compiler?: 'webpack5' | 'vite'
|
|
85
|
+
template?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type TCustomTemplateInfo = Omit<ITemplateInfo & {
|
|
89
|
+
isCustomTemplate?: boolean
|
|
90
|
+
customTemplatePath?: string
|
|
91
|
+
}, 'template'>
|
|
92
|
+
|
|
93
|
+
type TSetCustomTemplateConfig = (customTemplateConfig: TCustomTemplateInfo) => void
|
|
94
|
+
|
|
95
|
+
interface IPluginOpts extends ITemplateInfo {
|
|
96
|
+
installPath: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default (ctx: IPluginContext, pluginOpts:IPluginOpts) => {
|
|
100
|
+
ctx.modifyCreateTemplate(async (setCustomTemplateConfig: TSetCustomTemplateConfig)=> {
|
|
101
|
+
const { installPath, css, typescript, compiler } = pluginOpts
|
|
102
|
+
const templateName = 'mobx'
|
|
103
|
+
const templatePath = path.join(installPath, templateName)
|
|
104
|
+
const customTemplateConfig = {
|
|
105
|
+
//自定义模版路径
|
|
106
|
+
customTemplatePath: templatePath,
|
|
107
|
+
css,
|
|
108
|
+
typescript,
|
|
109
|
+
compiler
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 下载模版到电脑本地,可以自行进行判断,看是否需要重新下载
|
|
114
|
+
* 从哪里下载,如何下载,taro 官方不做限定
|
|
115
|
+
* 模版格式和社区模版一样
|
|
116
|
+
* 只要保证下载后的文件目录为 `${templatePath}` 即可,taro 会在该目录下获取模版
|
|
117
|
+
* 如果下载模版失败,请不要调用 setCustomTemplateConfig,taro 会根据默认流程进行兜底创建
|
|
118
|
+
*/
|
|
119
|
+
if (!fs.existsSync(templatePath)) {
|
|
120
|
+
//如果文件不存在,就下载文件到指定路径
|
|
121
|
+
await downloadTemplate(customTemplateConfig)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(templatePath)) {
|
|
125
|
+
//如果文件下载成功,调用 setCustomTemplateConfig
|
|
126
|
+
setCustomTemplateConfig(customTemplateConfig)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const downloadTemplate = async (customTemplateConfig) => {
|
|
133
|
+
return new Promise<void>(async (resolve, reject)=>{
|
|
134
|
+
const url = 'https://storage.360buyimg.com/olympic-models-test/mobx.zip'
|
|
135
|
+
const { name, templatePath } = customTemplateConfig
|
|
136
|
+
const zipName = `${name}.zip`
|
|
137
|
+
const zipPath = path.join(templatePath, zipName)
|
|
138
|
+
fs.writeFileSync(zipPath, await download(url))
|
|
139
|
+
const extract = unzip.Extract({ path: templatePath })
|
|
140
|
+
fs.createReadStream(zipPath).pipe(extract)
|
|
141
|
+
extract.on('close', function () {
|
|
142
|
+
console.log("解压完成!!")
|
|
143
|
+
//删除
|
|
144
|
+
fs.unlinkSync(zipPath)
|
|
145
|
+
resolve()
|
|
146
|
+
})
|
|
147
|
+
extract.on('error', function (err) {
|
|
148
|
+
console.log(err)
|
|
149
|
+
reject()
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
{{/if}}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"removeComments": false,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"strictNullChecks": true,
|
|
13
|
+
"target": "ES2017",
|
|
14
|
+
"module": "commonjs",
|
|
15
|
+
"preserveConstEnums": true,
|
|
16
|
+
"outDir": "./dist",
|
|
17
|
+
"traceResolution": false,
|
|
18
|
+
"sourceMap": true,
|
|
19
|
+
"rootDir": "./src",
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationDir": "types"
|
|
22
|
+
},
|
|
23
|
+
"include": ["./src"],
|
|
24
|
+
"exclude": [
|
|
25
|
+
"node_modules",
|
|
26
|
+
"dist"
|
|
27
|
+
]
|
|
28
|
+
}
|