-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@muniz/muniz-plugin-create): 开发创建模版插件
affects: @muniz/cli, @muniz/muniz-plugin-create 创建pc模版、创建chrome扩展模版、创建脚手架插件模版
- Loading branch information
1 parent
5112ea4
commit 3f76ffe
Showing
20 changed files
with
188 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
{ | ||
"MUNIZ_CLI_DEBUG": true, | ||
"MUNIZ_CLI_DEBUG": false, | ||
"MUNIZ_PLUGIN_DEV": false, | ||
"languageLocale": "zhCN", | ||
"plugins": [ | ||
{ | ||
"shortName": "create", | ||
"pkgName": "@muniz/muniz-plugin-create" | ||
} | ||
] | ||
} | ||
"plugins": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"enUS":[{"key":"h5","commandType":"function","description":"创建H5开发模版","options":[{"key":"flags","type":"string","description":"创建H5开发模版","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"创建PC端开发模版","options":[{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"创建脚手架插件模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"},{"key":"extension","commandType":"function","description":"创建Chrome插件扩展","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Extension","path":"Extension/index.js"}],"zhCN":[{"key":"h5","commandType":"function","description":"创建H5开发模版","options":[{"key":"flags","type":"string","description":"创建H5开发模版","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"创建PC端开发模版","options":[{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"创建脚手架插件模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"},{"key":"extension","commandType":"function","description":"创建Chrome插件扩展","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Extension","path":"Extension/index.js"}]} | ||
{"enUS":[{"key":"extension","commandType":"function","description":"Create a Chrome-Extension development template","options":[],"isIndex":false,"name":"Extension","path":"Extension/index.js"},{"key":"h5","commandType":"function","description":"Create a H5 development template","options":[],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"Create a PC development template","options":[],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"Create a Scaffolding-Plugin development template","options":[],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"}],"zhCN":[{"key":"extension","commandType":"function","description":"创建Chrome扩展开发模版","options":[],"isIndex":false,"name":"Extension","path":"Extension/index.js"},{"key":"h5","commandType":"function","description":"创建H5开发模版","options":[],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"创建PC开发模版","options":[],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"创建脚手架插件开发模版","options":[],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"}]} |
15 changes: 12 additions & 3 deletions
15
packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
"use strict"; | ||
|
||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var enUS = { | ||
|
||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
|
||
var _enUS; | ||
|
||
var enUS = (_enUS = { | ||
command_pc_desc: 'Create APP development template', | ||
projectName: 'Please enter the project name', | ||
projectDesc: 'Please enter a project description', | ||
extensionShortName: 'Please enter Chrome extension-short name', | ||
isGit: 'Whether to start Git?', | ||
isTypeScript: 'Whether to enable TypeScript?', | ||
extensionAuthor: 'Please enter Chrome extension-author', | ||
create_project_have_existed: 'Warning: The project already exists, please change the project name', | ||
template_project_down: 'Start downloading', | ||
template_project_down_success: 'Download Success', | ||
template_project_down_fail: 'Start Fail', | ||
project_install_npm: 'Start Installation Dependencies', | ||
project_install_npm_success: 'Install Success', | ||
project_install_npm_fail: 'Install Fail' | ||
}; | ||
project_install_npm_fail: 'Install Fail', | ||
git_commit_content: 'Initialize project engineering' | ||
}, (0, _defineProperty2["default"])(_enUS, "command_pc_desc", 'Create a PC development template'), (0, _defineProperty2["default"])(_enUS, "command_plugin_desc", 'Create a Scaffolding-Plugin development template'), (0, _defineProperty2["default"])(_enUS, "command_extension_desc", 'Create a Chrome-Extension development template'), (0, _defineProperty2["default"])(_enUS, "command_h5_desc", 'Create a H5 development template'), _enUS); | ||
var _default = enUS; | ||
exports["default"] = _default; |
15 changes: 12 additions & 3 deletions
15
packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
"use strict"; | ||
|
||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var zhCN = { | ||
|
||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
|
||
var _zhCN; | ||
|
||
var zhCN = (_zhCN = { | ||
command_pc_desc: '创建PC开发模版', | ||
projectName: '请输入项目名称', | ||
projectDesc: '请输入项目描述', | ||
extensionShortName: '请输入Chrome扩展-短名称', | ||
isGit: '是否启动Git?', | ||
isTypeScript: '是否启用TypeScript?', | ||
extensionAuthor: '请输入Chrome扩展-作者', | ||
create_project_have_existed: '警告: 该项目已存在,请重新更换一个项目名称', | ||
template_project_down: '开始下载', | ||
template_project_down_success: '下载成功', | ||
template_project_down_fail: '开始失败', | ||
project_install_npm: '安装依赖', | ||
project_install_npm_success: '安装成功', | ||
project_install_npm_fail: '安装失败' | ||
}; | ||
project_install_npm_fail: '安装失败', | ||
git_commit_content: '初始化项目工程' | ||
}, (0, _defineProperty2["default"])(_zhCN, "command_pc_desc", '创建PC开发模版'), (0, _defineProperty2["default"])(_zhCN, "command_plugin_desc", '创建脚手架插件开发模版'), (0, _defineProperty2["default"])(_zhCN, "command_extension_desc", '创建Chrome扩展开发模版'), (0, _defineProperty2["default"])(_zhCN, "command_h5_desc", '创建H5开发模版'), _zhCN); | ||
var _default = zhCN; | ||
exports["default"] = _default; |
63 changes: 32 additions & 31 deletions
63
packages/@muniz/muniz-plugin-create/src/command/Extension/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const path = require('path'); | ||
const ora = require('ora'); | ||
import prompts from './prompts'; | ||
import project from '../../lib/project'; | ||
import pkgManger from '../../lib/pkgManger'; | ||
import i18n from '../../configs/i18n'; | ||
|
||
/** | ||
* @muniz | ||
* @type function | ||
* @description 创建Chrome插件扩展 | ||
* @description command_extension_desc | ||
* */ | ||
async function Extension(props) { | ||
const anwser = await prompts(); | ||
console.log(anwser); | ||
console.log('创建 Chrome extensions 扩展插件 React 开发模版 , 暂未接入脚手架'); | ||
} | ||
let anwser = await prompts(props); | ||
anwser = { | ||
...anwser, | ||
branch: anwser.isTypeScript ? 'typescript' : 'main', | ||
destDir: path.resolve(process.cwd(), anwser.projectName || '.'), | ||
}; | ||
|
||
// 同步代码 | ||
await project.syncRemoteProject({ type: 'extension', anwser }); | ||
|
||
Extension.propTypes = { | ||
/** | ||
* @muniz | ||
* @description falgs哈哈 | ||
*/ | ||
flags: PropTypes.string, | ||
/** | ||
* @muniz | ||
* @description Number类型转换 | ||
*/ | ||
count: PropTypes.number, | ||
/** | ||
* @muniz | ||
* @description 生成项目的名称 | ||
* @alias n | ||
*/ | ||
isGit: PropTypes.bool, | ||
}; | ||
// 替换信息 | ||
await pkgManger.replacePkgInfo({ anwser }); | ||
await pkgManger.replaceManifestInfo({ anwser }); | ||
|
||
Extension.defaultProps = { | ||
flags: 'wowowoowqqqqqqq', | ||
isGit: false, | ||
count: 1, | ||
}; | ||
// 安装依赖 | ||
const spinner = ora(i18n.getLocale('project_install_npm')); | ||
spinner.start(); | ||
try { | ||
await pkgManger.runCommand('npm install', { cwd: anwser.destDir }); | ||
spinner.succeed(i18n.getLocale('project_install_npm_success')); | ||
} catch (err) { | ||
spinner.fail(i18n.getLocale('project_install_npm_fail')); | ||
throw err; | ||
} | ||
|
||
// 初始化Git | ||
await project.initGit(anwser); | ||
} | ||
|
||
export default Extension; |
5 changes: 2 additions & 3 deletions
5
packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { prokectName, projectDesc, isGit, extensionShortName } from '../../lib/prompts'; | ||
import i18n from '../../configs/i18n'; | ||
import { prokectName, projectDesc, isGit, extensionShortName, extensionAuthor } from '../../lib/prompts'; | ||
|
||
const inquirer = require('inquirer'); | ||
|
||
export default async () => { | ||
const answers = await inquirer.prompt([prokectName, extensionShortName, projectDesc, isGit]); | ||
const answers = await inquirer.prompt([prokectName, extensionShortName, projectDesc, extensionAuthor, isGit]); | ||
return answers; | ||
}; |
30 changes: 1 addition & 29 deletions
30
packages/@muniz/muniz-plugin-create/src/command/H5/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,10 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* @muniz | ||
* @type function | ||
* @description 创建H5开发模版 | ||
* @description command_h5_desc | ||
* */ | ||
function H5(props) { | ||
console.log('创建 H5 React 开发模版 , 暂未接入脚手架'); | ||
} | ||
|
||
H5.propTypes = { | ||
/** | ||
* @muniz | ||
* @description 创建H5开发模版 | ||
*/ | ||
flags: PropTypes.string, | ||
/** | ||
* @muniz | ||
* @description Number类型转换 | ||
*/ | ||
count: PropTypes.number, | ||
/** | ||
* @muniz | ||
* @description 生成项目的名称 | ||
* @alias n | ||
*/ | ||
isGit: PropTypes.bool, | ||
}; | ||
|
||
H5.defaultProps = { | ||
flags: 'wowowoowqqqqqqq', | ||
isGit: false, | ||
count: 1, | ||
}; | ||
|
||
export default H5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 31 additions & 31 deletions
62
packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const path = require('path'); | ||
const ora = require('ora'); | ||
import prompts from './prompts'; | ||
import project from '../../lib/project'; | ||
import pkgManger from '../../lib/pkgManger'; | ||
import i18n from '../../configs/i18n'; | ||
|
||
/** | ||
* @muniz | ||
* @type function | ||
* @description 创建脚手架插件模版 | ||
* @description command_plugin_desc | ||
* */ | ||
async function Plugin(props) { | ||
const anwser = await prompts(); | ||
console.log(anwser); | ||
console.log('创建 脚手架 Muniz plugin 开发模版'); | ||
} | ||
let anwser = await prompts(props); | ||
anwser = { | ||
...anwser, | ||
branch: 'main', // anwser.isTypeScript ? 'typescript' : | ||
destDir: path.resolve(process.cwd(), `muniz-plugin-${anwser.projectName}` || '.'), | ||
}; | ||
|
||
// 同步代码 | ||
await project.syncRemoteProject({ type: 'plugin', anwser }); | ||
|
||
Plugin.propTypes = { | ||
/** | ||
* @muniz | ||
* @description falgs哈哈 | ||
*/ | ||
flags: PropTypes.string, | ||
/** | ||
* @muniz | ||
* @description Number类型转换 | ||
*/ | ||
count: PropTypes.number, | ||
/** | ||
* @muniz | ||
* @description 生成项目的名称 | ||
* @alias n | ||
*/ | ||
isGit: PropTypes.bool, | ||
}; | ||
// 替换信息 | ||
await pkgManger.replacePkgInfo({ anwser }); | ||
|
||
Plugin.defaultProps = { | ||
flags: 'wowowoowqqqqqqq', | ||
isGit: false, | ||
count: 1, | ||
}; | ||
// 安装依赖 | ||
const spinner = ora(i18n.getLocale('project_install_npm')); | ||
spinner.start(); | ||
try { | ||
await pkgManger.runCommand('npm install', { cwd: anwser.destDir }); | ||
spinner.succeed(i18n.getLocale('project_install_npm_success')); | ||
} catch (err) { | ||
spinner.fail(i18n.getLocale('project_install_npm_fail')); | ||
throw err; | ||
} | ||
|
||
// 初始化Git | ||
await project.initGit(anwser); | ||
} | ||
|
||
export default Plugin; |
Oops, something went wrong.