Skip to content

Commit

Permalink
Feat/init command add source root (#15991)
Browse files Browse the repository at this point in the history
* feat: 增加sourceRoot参数

* feat: create page 增加 template source

* feat: 增加create page clone 参数

* chore: 移除冗余的 yarn.lock

* chore(release): publish 3.6.32-alpha.1 --tag=alpha

* feat: 增加templates mkdirp逻辑

* chore(release): publish 3.6.32-alpha.2 --tag=alpha

---------

Co-authored-by: weiyanhai <weiyanhai@jd.com>
  • Loading branch information
koppthe and weiyanhai authored Jul 4, 2024
1 parent bab6f51 commit 473d5ef
Show file tree
Hide file tree
Showing 75 changed files with 86 additions and 75 deletions.
2 changes: 1 addition & 1 deletion crates/native_binding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/binding",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Node binding for taro",
"main": "binding.js",
"typings": "binding.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-arm64",
"description": "Native binding for taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-x64",
"description": "Native binding for taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-linux-x64-gnu",
"description": "Native binding for taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/binding-linux-x64-musl",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-win32-x64-msvc",
"description": "Native binding for taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "开放式跨端跨框架开发解决方案",
"homepage": "https://github.com/NervJS/taro#readme",
"author": "O2Team",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-jsx-to-rn-stylesheet",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Transform stylesheet selector to style in JSX Elements.",
"license": "MIT",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-taroapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-taroapi",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro babel preset",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/create-app",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "create taro app with one command",
"author": "VincentW <Vincent.Mr.W@gmail.com>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/create-app#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/css-to-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "taro-css-to-react-native",
"description": "Convert CSS text to a React Native stylesheet object",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"main": "dist/index.js",
"license": "MIT",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-taro",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro specific linting rules for ESLint",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-html-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-html-transform",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "transform html tag name selector",
"main": "index.js",
"author": "drchan",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-plugin-constparse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-plugin-constparse",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "parse constants defined in config",
"main": "index.js",
"author": "Simba",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-pxtransform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-pxtransform",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
"main": "index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-unit-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-taro-unit-transform",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "小程序单位转换",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/shared",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro utils internal use.",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/shared#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-config-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-config-taro-rn",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Shareable stylelint config for React Native CSS modules",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stylelint-taro-rn",
"description": "A collection of React Native specific rules for stylelint",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"main": "dist/index.js",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-alipay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-platform-alipay",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "支付宝小程序平台插件",
"author": "Chen-jj",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-alipay#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/api",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro common API",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/api#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli-convertor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/cli-convertor",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "cli tool for taro-convert",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/cli",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "cli tool for taro",
"main": "index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/taro-cli/src/create/fetchTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function fetchTemplate (templateSource: string, templateRootPath:
return new Promise<void>(async (resolve) => {
// 下载文件的缓存目录
if (fs.existsSync(tempPath)) await fs.remove(tempPath)
await fs.mkdirp(templateRootPath)
await fs.mkdir(tempPath)

const spinner = ora(`正在从 ${templateSource} 拉取远程模板...`).start()
Expand Down
11 changes: 8 additions & 3 deletions packages/taro-cli/src/create/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface IPageConf {
projectName: string
npm: NpmType
template: string
clone?: boolean
templateSource?: string
description?: string
pageName: string
date?: string
Expand All @@ -31,6 +33,8 @@ interface ITemplateInfo {
typescript?: boolean
compiler?: CompilerType
template?: string
templateSource?: string
clone?: boolean
}

type TCustomTemplateInfo = Omit<ITemplateInfo & {
Expand Down Expand Up @@ -123,13 +127,14 @@ export default class Page extends Creator {
const config = await fs.readJSON(taroConfig)
templateSource = config && config.templateSource ? config.templateSource : DEFAULT_TEMPLATE_SRC
} else {
templateSource = this.conf.templateSource || DEFAULT_TEMPLATE_SRC

await fs.createFile(taroConfig)
await fs.writeJSON(taroConfig, { templateSource: DEFAULT_TEMPLATE_SRC })
templateSource = DEFAULT_TEMPLATE_SRC
await fs.writeJSON(taroConfig, { templateSource })
}

// 从模板源下载模板
await fetchTemplate(templateSource, this.templatePath(''))
await fetchTemplate(templateSource, this.templatePath(''), this.conf.clone)
}

async create () {
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-cli/src/presets/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default (ctx: IPluginContext) => {
const type = options.type || createTemplateTypeEnum.PAGE
const name = _[1] || options.name
const description = options.description || ''
const templateSource = options.templateSource
const clone = options.clone
const { chalk } = ctx.helper
const { appPath } = ctx.paths

Expand All @@ -50,9 +52,11 @@ export default (ctx: IPluginContext) => {

const Page = require('../../create/page').default
const page = new Page({
clone,
pageName: name,
projectDir: appPath,
description,
templateSource,
async modifyCustomTemplateConfig (cb: TSetCustomTemplateConfig) {
await ctx.applyPlugins({ name: hooks.MODIFY_CREATE_TEMPLATE, opts: cb })
}
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-cli/src/presets/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export default (ctx: IPluginContext) => {
// init project
const { appPath } = ctx.paths
const { options } = opts
const { projectName, templateSource, clone, template, description, typescript, css, npm, framework, compiler } = options
const { projectName, templateSource, clone, template, description, typescript, css, npm, framework, compiler, sourceRoot } = options
const Project = require('../../create/project').default
const project = new Project({
sourceRoot,
projectName,
projectDir: appPath,
npm,
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-advanced/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-advanced",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-react",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro 组件库 React 版本库",
"private": true,
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-vue2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-vue2",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro 组件库 Vue2 版本库",
"private": true,
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-vue3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-vue3",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro 组件库 Vue3 版本库",
"private": true,
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-react",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "",
"main:h5": "src/index.js",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-rn",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "多端解决方案基础组件(RN)",
"main": "./dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro 组件库",
"browser": "dist/index.js",
"main:h5": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-extend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/extend",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro extend functionality",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-extend#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-h5/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro-h5",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro h5 framework",
"browser": "dist/index.js",
"main:h5": "dist/index.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/helper",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro Helper",
"main": "index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-jd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-platform-jd",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "京东小程序平台插件",
"author": "Chen-jj",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-jd#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro-loader",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Taro runner use webpack loader",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-loader#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-mini-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/mini-runner",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Mini app runner for taro",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-platform-h5/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-platform-h5",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Web 端平台插件",
"author": "ZakaryCode",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-platform-harmony-hybrid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-platform-harmony-hybrid",
"version": "3.6.32",
"version": "3.6.32-alpha.2",
"description": "Harmony 端平台插件",
"author": "ZakaryCode",
"license": "MIT",
Expand Down
Loading

0 comments on commit 473d5ef

Please sign in to comment.