Skip to content

Commit

Permalink
Merge branch 'next' into feat/h5_api_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiDingxian authored Apr 12, 2022
2 parents c9c896d + 09d5e61 commit 53de070
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 226 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
"**/__snapshots__": true
},
"jest.autoEnable": false,
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceBeforeFunctionParenthesis": true
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@types/autoprefixer": "9.7.0",
"@types/babel-types": "^7.0.7",
"@types/babel__traverse": "^7.0.7",
"@types/convert-source-map": "^1.5.2",
"@types/debug": "4.1.5",
"@types/detect-port": "1.3.0",
"@types/fs-extra": "^8.0.1",
Expand Down
53 changes: 33 additions & 20 deletions packages/taro-cli/src/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ describe('inspect', () => {
})

describe('init', () => {
const baseOpts = {
appPath: APP_PATH,
projectName: undefined,
typescript: undefined,
templateSource: undefined,
clone: false,
template: undefined,
css: undefined,
isHelp: false
}

it('should make configs', () => {
const projectName = 'temp'
const templateSource = 'https://url'
Expand All @@ -113,14 +102,23 @@ describe('inspect', () => {
const ins = MockedKernel.mock.instances[0]
expect(ins.run).toHaveBeenCalledWith({
name: 'init',
opts: Object.assign({}, baseOpts, {
projectName,
typescript: true,
templateSource,
clone: true,
template,
css
})
opts: {
_: [
'init',
'temp'
],
options: {
appPath: APP_PATH,
projectName,
typescript: true,
templateSource,
description: undefined,
clone: true,
template,
css
},
isHelp: false
}
})
})

Expand All @@ -131,7 +129,22 @@ describe('inspect', () => {
const ins = MockedKernel.mock.instances[0]
expect(ins.run).toHaveBeenCalledWith({
name: 'init',
opts: Object.assign({}, baseOpts, { projectName })
opts: {
_: [
'init'
],
options: {
appPath: APP_PATH,
projectName,
typescript: undefined,
templateSource: undefined,
description: undefined,
clone: false,
template: undefined,
css: undefined
},
isHelp: false
}
})
})
})
Expand Down
88 changes: 74 additions & 14 deletions packages/taro-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as fs from 'fs-extra'
import * as path from 'path'

import * as minimist from 'minimist'
import { Kernel } from '@tarojs/service'

import init from './commands/init'
import customCommand from './commands/customCommand'
import { getPkgVersion } from './util'

Expand Down Expand Up @@ -36,23 +34,85 @@ export default class CLI {
const _ = args._
const command = _[0]
if (command) {
const appPath = this.appPath
const presetsPath = path.resolve(__dirname, 'presets')
const commandsPath = path.resolve(presetsPath, 'commands')
const platformsPath = path.resolve(presetsPath, 'platforms')
const filesPath = path.resolve(presetsPath, 'files')
const commandPlugins = fs.readdirSync(commandsPath)
const targetPlugin = `${command}.js`

// 设置环境变量
process.env.NODE_ENV ||= args.env || (args.watch ? 'development' : 'production')

const kernel = new Kernel({
appPath: this.appPath,
presets: [
path.resolve(__dirname, '.', 'presets', 'index.js')
]
appPath,
presets: [],
plugins: []
})
kernel.optsPlugins ||= []

// 针对不同的内置命令注册对应的命令插件
if (commandPlugins.includes(targetPlugin)) {
kernel.optsPlugins.push(path.resolve(commandsPath, targetPlugin))
}

switch (command) {
case 'build': {
let plugin
let platform = args.type
const { publicPath, bundleOutput, sourcemapOutput, sourceMapUrl, sourcemapSourcesRoot, assetsDest } = args

// 针对不同的内置平台注册对应的端平台插件
switch (platform) {
case 'weapp':
case 'alipay':
case 'swan':
case 'tt':
case 'qq':
case 'jd':
kernel.optsPlugins = [
...kernel.optsPlugins,
`@tarojs/plugin-platform-${platform}`,
path.resolve(filesPath, 'writeFileToDist.js'),
path.resolve(filesPath, 'generateProjectConfig.js'),
path.resolve(filesPath, 'generateFrameworkInfo.js')
]
break
default: {
// h5, rn
const platformPlugins = fs.readdirSync(platformsPath)
const targetPlugin = `${platform}.js`
if (platformPlugins.includes(targetPlugin)) {
kernel.optsPlugins.push(path.resolve(platformsPath, targetPlugin))
}
break
}
}

// 根据 framework 启用插件
const framework = kernel.config?.initialConfig.framework
switch (framework) {
case 'vue':
kernel.optsPlugins.push('@tarojs/plugin-framework-vue2')
break
case 'vue3':
kernel.optsPlugins.push('@tarojs/plugin-framework-vue3')
break
default:
kernel.optsPlugins.push('@tarojs/plugin-framework-react')
break
}

// 编译小程序插件
if (typeof args.plugin === 'string') {
plugin = args.plugin
platform = 'plugin'
kernel.optsPlugins.push(path.resolve(platformsPath, 'plugin.js'))
}
customCommand('build', kernel, {
_: args._,

customCommand(command, kernel, {
_,
platform,
plugin,
isWatch: Boolean(args.watch),
Expand All @@ -73,17 +133,17 @@ export default class CLI {
break
}
case 'init': {
const projectName = _[1] || args.name
init(kernel, {
appPath: this.appPath,
projectName,
customCommand(command, kernel, {
_,
appPath,
projectName: _[1] || args.name,
description: args.description,
typescript: args.typescript,
templateSource: args['template-source'],
clone: !!args.clone,
template: args.template,
css: args.css,
isHelp: args.h
h: args.h
})
break
}
Expand Down
1 change: 0 additions & 1 deletion packages/taro-cli/src/commands/customCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function customCommand (
})

// 设置环境变量
process.env.NODE_ENV = process.env.NODE_ENV || options.env || (options.isWatch ? 'development' : 'production')
if (options.platform) {
process.env.TARO_ENV = options.platform
}
Expand Down
38 changes: 0 additions & 38 deletions packages/taro-cli/src/commands/init.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/taro-cli/src/presets/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export default (ctx: IPluginContext) => {
'--css [css]': 'CSS预处理器(sass/less/stylus/none)',
'-h, --help': 'output usage information'
},
async fn () {
async fn (opts) {
// init project
const { appPath } = ctx.paths
const { projectName, templateSource, clone, template, description, typescript, css } = ctx.runOpts
const { options } = opts
const { projectName, templateSource, clone, template, description, typescript, css } = options
const Project = require('../../create/project').default
const project = new Project({
projectName,
Expand Down
40 changes: 0 additions & 40 deletions packages/taro-cli/src/presets/index.ts

This file was deleted.

55 changes: 49 additions & 6 deletions packages/taro-components/h5/vue3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,55 @@ import Image from './components/image'
import Icon from './components/icon'
import ScrollView from './components/scroll-view'

export {
Text,
Image,
Icon,
ScrollView
}

export const View = createComponent('taro-view')
export const RichText = createComponent('taro-rich-text')
export const Button = createComponent('taro-button')
export const CheckboxGroup = createComponent('taro-checkbox-group')
export const Editor = createComponent('taro-editor')
export const Form = createComponent('taro-form')
export const Label = createComponent('taro-label')
export const PickerView = createComponent('taro-picker-view')
export const PickerViewColumn = createComponent('taro-picker-view-column')
export const CoverImage = createComponent('taro-cover-image')
export const CoverView = createComponent('taro-cover-view')
export const MovableArea = createComponent('taro-movable-area')
export const MovableView = createComponent('taro-movable-view')
export const Swiper = createComponent('taro-swiper')
export const FunctionalPageNavigator = createComponent('taro-functional-page-navigator')
export const Navigator = createComponent('taro-navigator')
export const Audio = createComponent('taro-audio')
export const Camera = createComponent('taro-camera')
export const LivePlayer = createComponent('taro-live-player')
export const Map = createComponent('taro-map')
export const Ad = createComponent('taro-ad')
export const OfficialAccount = createComponent('taro-official-account')
export const OpenData = createComponent('taro-open-data')
export const WebView = createComponent('taro-web-view')
export const NavigationBar = createComponent('taro-navigation-bar')
export const Block = createComponent('taro-block')
export const Canvas = createComponent('taro-canvas')
export const CustomWrapper = createComponent('taro-custom-wrapper')
export const Checkbox = createComponent('taro-checkbox', ['weui-cells_checkbox'])
export const Progress = createComponent('taro-progress', ['weui-progress'])
export const RadioGroup = createComponent('taro-radio-group', ['weui-cells_radiogroup'])
export const Radio = createComponent('taro-radio', ['weui-cells_checkbox'])
export const SwiperItem = createComponent('taro-swiper-item', ['swiper-slide'])
export const Video = createComponent('taro-video', ['taro-video-container'])
export const Slot = createComponent('taro-slot')

export const Input = createFormsComponent('taro-input', 'input')
export const Textarea = createFormsComponent('taro-textarea', 'input')
export const Picker = createFormsComponent('taro-picker', 'change')
export const Switch = createFormsComponent('taro-switch', 'change', 'checked')
export const Slider = createFormsComponent('taro-slider', 'change', 'value', ['weui-slider-box'])

export function initVue3Components (app) {
app.config.isCustomElement = tag => /^taro-/.test(tag) || tag === 'root' || tag === 'block'

Expand All @@ -18,12 +67,6 @@ export function initVue3Components (app) {
}
})

const Input = createFormsComponent('taro-input', 'input')
const Textarea = createFormsComponent('taro-textarea', 'input')
const Picker = createFormsComponent('taro-picker', 'change')
const Switch = createFormsComponent('taro-switch', 'change', 'checked')
const Slider = createFormsComponent('taro-slider', 'change', 'value', ['weui-slider-box'])

app.component('taro-input', Input)
app.component('taro-textarea', Textarea)
app.component('taro-picker', Picker)
Expand Down
Loading

0 comments on commit 53de070

Please sign in to comment.