From 3f76ffe37ae0a77128b568d71ac64859e5013d96 Mon Sep 17 00:00:00 2001 From: muniz <1160007652@qq.com> Date: Mon, 14 Dec 2020 15:51:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(@muniz/muniz-plugin-create):=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E5=88=9B=E5=BB=BA=E6=A8=A1=E7=89=88=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit affects: @muniz/cli, @muniz/muniz-plugin-create 创建pc模版、创建chrome扩展模版、创建脚手架插件模版 --- package.json | 1 + packages/@muniz/cli/dist/bin/cli.js | 5 ++ packages/@muniz/cli/dist/configs/system.json | 11 +--- packages/@muniz/cli/src/bin/cli.js | 5 ++ .../dist/configs/commandHelp.json | 2 +- .../dist/configs/locales/en-US.js | 15 ++++- .../dist/configs/locales/zh-CN.js | 15 ++++- .../src/command/Extension/index.js | 63 ++++++++++--------- .../src/command/Extension/prompts.js | 5 +- .../src/command/H5/index.js | 30 +-------- .../src/command/Pc/index.js | 34 ++-------- .../src/command/Plugin/index.js | 62 +++++++++--------- .../src/configs/gitRepo.js | 7 +-- .../src/configs/locales/en-US.js | 8 +++ .../src/configs/locales/zh-CN.js | 8 +++ .../src/lib/pkgManger/index.js | 25 +++++++- .../src/lib/project/index.js | 19 +++++- .../src/lib/prompts/index.js | 8 +++ scripts/build.sh | 2 +- scripts/clear.sh | 7 +++ 20 files changed, 188 insertions(+), 144 deletions(-) create mode 100755 scripts/clear.sh diff --git a/package.json b/package.json index 61e8cf6..56905c6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "dev": "nodemon --exec ./scripts/dev.sh", "build": "./scripts/build.sh", + "clear": "./scripts/clear.sh", "commit": "git-cz" }, "config": { diff --git a/packages/@muniz/cli/dist/bin/cli.js b/packages/@muniz/cli/dist/bin/cli.js index 8edcb75..a8465a1 100755 --- a/packages/@muniz/cli/dist/bin/cli.js +++ b/packages/@muniz/cli/dist/bin/cli.js @@ -16,6 +16,11 @@ var pkgInfo = require('../../package.json'); var requiredVersion = pkgInfo.engines.node; _i18n["default"].initI18n(); +/** + * const USER_HOME = process.env.HOME || process.env.USERPROFILE; + * 用户目录 + **/ + /** * * @param {String} wanted 设定的最小兼容版本号 diff --git a/packages/@muniz/cli/dist/configs/system.json b/packages/@muniz/cli/dist/configs/system.json index 21a4758..415b8e5 100644 --- a/packages/@muniz/cli/dist/configs/system.json +++ b/packages/@muniz/cli/dist/configs/system.json @@ -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" - } - ] -} \ No newline at end of file + "plugins": [] +} diff --git a/packages/@muniz/cli/src/bin/cli.js b/packages/@muniz/cli/src/bin/cli.js index 4264d19..e349d38 100644 --- a/packages/@muniz/cli/src/bin/cli.js +++ b/packages/@muniz/cli/src/bin/cli.js @@ -20,6 +20,11 @@ import { import i18n from '../lib/i18n'; i18n.initI18n(); +/** + * const USER_HOME = process.env.HOME || process.env.USERPROFILE; + * 用户目录 + **/ + /** * * @param {String} wanted 设定的最小兼容版本号 diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json b/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json index 68add79..46c54f7 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json +++ b/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json @@ -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"}]} diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js b/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js index 0dcf7b7..e85536e 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js +++ b/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js @@ -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; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js b/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js index 2b89863..84df395 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js +++ b/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js @@ -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; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js index ea2177f..9b0d28c 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js @@ -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; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js b/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js index 5848951..b8c86fc 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js @@ -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; }; diff --git a/packages/@muniz/muniz-plugin-create/src/command/H5/index.js b/packages/@muniz/muniz-plugin-create/src/command/H5/index.js index c4cbfe6..9bf3dce 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/H5/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/H5/index.js @@ -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; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js index b53f786..0aacb97 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js @@ -1,35 +1,25 @@ -import PropTypes from 'prop-types'; const path = require('path'); const ora = require('ora'); import prompts from './prompts'; -import syncRemoteProject from '../../lib/project'; +import project from '../../lib/project'; import pkgManger from '../../lib/pkgManger'; import i18n from '../../configs/i18n'; /** * @muniz * @type function - * @description 创建PC端开发模版 + * @description command_pc_desc * */ async function Pc(props) { - let anwser = await prompts(); + let anwser = await prompts(props); anwser = { ...anwser, branch: anwser.isTypeScript ? 'typescript' : 'main', destDir: path.resolve(process.cwd(), anwser.projectName || '.'), }; - // anwser = { - // projectName: 'test', - // projectDesc: 'miaoshu', - // isTypeScript: true, - // isGit: true, - // branch: 'typescript', - // destDir: '/Users/mac/NodeProjects/testProject/test', - // }; - // 同步代码 - await syncRemoteProject({ type: 'pc', projectPath: '/', anwser }); + await project.syncRemoteProject({ type: 'pc', anwser }); // 替换信息 await pkgManger.replacePkgInfo({ anwser }); @@ -45,20 +35,8 @@ async function Pc(props) { throw err; } - // 打印结果 + // 初始化Git + await project.initGit(anwser); } -Pc.propTypes = { - /** - * @muniz - * @description 生成项目的名称 - * @alias n - */ - isGit: PropTypes.bool, -}; - -Pc.defaultProps = { - isGit: false, -}; - export default Pc; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js index 47d86fc..63ad760 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js @@ -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; diff --git a/packages/@muniz/muniz-plugin-create/src/configs/gitRepo.js b/packages/@muniz/muniz-plugin-create/src/configs/gitRepo.js index ce89f47..20224b5 100644 --- a/packages/@muniz/muniz-plugin-create/src/configs/gitRepo.js +++ b/packages/@muniz/muniz-plugin-create/src/configs/gitRepo.js @@ -8,11 +8,10 @@ export default { typescript: '', }, extension: { - main: '', - typescript: '', + main: '1160007652/chrome-extensions-tpl#main', + typescript: '1160007652/chrome-extensions-tpl#typescript', }, plugin: { - main: '', - typescript: '', + main: '1160007652/muniz-plugin-tpl#main', }, }; diff --git a/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js b/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js index 6be1cce..761882b 100644 --- a/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js +++ b/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js @@ -5,6 +5,7 @@ const enUS = { 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', @@ -15,6 +16,13 @@ const enUS = { project_install_npm: 'Start Installation Dependencies', project_install_npm_success: 'Install Success', project_install_npm_fail: 'Install Fail', + + git_commit_content: 'Initialize project engineering', + + command_pc_desc: 'Create a PC development template', + command_plugin_desc: 'Create a Scaffolding-Plugin development template', + command_extension_desc: 'Create a Chrome-Extension development template', + command_h5_desc: 'Create a H5 development template', }; export default enUS; diff --git a/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js b/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js index 42f01f1..5827be0 100644 --- a/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js +++ b/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js @@ -5,6 +5,7 @@ const zhCN = { extensionShortName: '请输入Chrome扩展-短名称', isGit: '是否启动Git?', isTypeScript: '是否启用TypeScript?', + extensionAuthor: '请输入Chrome扩展-作者', create_project_have_existed: '警告: 该项目已存在,请重新更换一个项目名称', @@ -15,6 +16,13 @@ const zhCN = { project_install_npm: '安装依赖', project_install_npm_success: '安装成功', project_install_npm_fail: '安装失败', + + git_commit_content: '初始化项目工程', + + command_pc_desc: '创建PC开发模版', + command_plugin_desc: '创建脚手架插件开发模版', + command_extension_desc: '创建Chrome扩展开发模版', + command_h5_desc: '创建H5开发模版', }; export default zhCN; diff --git a/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js b/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js index d5307b6..041e8a3 100644 --- a/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js +++ b/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js @@ -9,6 +9,10 @@ const path = require('path'); const fse = require('fs-extra'); const shellExec = require('shell-exec'); +/** + * 替换Package.json 中的信息 + * @param {obj} anwser, prompts 结果集 + */ async function replacePkgInfo({ anwser }) { const pkgInfo = require(path.join(anwser.destDir, './package.json')); pkgInfo.name = anwser.projectName; @@ -16,11 +20,30 @@ async function replacePkgInfo({ anwser }) { fse.outputFileSync(path.join(anwser.destDir, './package.json'), JSON.stringify(pkgInfo, null, 2)); } +/** + * 替换Chrome扩展 manifest.json 中的信息 + * @param {obj} anwser, prompts 结果集 + */ +async function replaceManifestInfo({ anwser }) { + const manifest = require(path.join(anwser.destDir, './build/manifest/manifest.base.json')); + manifest.author = anwser.extensionAuthor; + manifest.description = anwser.projectDesc; + manifest.name = anwser.projectName; + manifest.short_name = anwser.extensionShortName; + fse.outputFileSync( + path.join(anwser.destDir, './build/manifest/manifest.base.json'), + JSON.stringify(manifest, null, 2), + ); +} + /** * 安装 项目依赖 + * @param {string} command 命令 + * @param {obj} args 参数 + * */ async function runCommand(command, args) { return await shellExec(command, args); } -export default { replacePkgInfo, runCommand }; +export default { replacePkgInfo, replaceManifestInfo, runCommand }; diff --git a/packages/@muniz/muniz-plugin-create/src/lib/project/index.js b/packages/@muniz/muniz-plugin-create/src/lib/project/index.js index 11d4787..f592f8b 100644 --- a/packages/@muniz/muniz-plugin-create/src/lib/project/index.js +++ b/packages/@muniz/muniz-plugin-create/src/lib/project/index.js @@ -6,6 +6,7 @@ const GitDownLoad = require('download-git-repo'); const ora = require('ora'); +import pkgManger from '../pkgManger'; import i18n from '../../configs/i18n'; import gitRepo from '../../configs/gitRepo'; @@ -42,4 +43,20 @@ function downTplLoad(gitRepoUrl, destDir) { }); } -export default syncRemoteProject; +/** + * 初始化Git + * @param {obj} anwser + */ +async function initGit(anwser) { + if (anwser.isGit) { + try { + await pkgManger.runCommand('git init -b main', { cwd: anwser.destDir }); + await pkgManger.runCommand('git add .', { cwd: anwser.destDir }); + await pkgManger.runCommand(`git commit -m "${i18n.getLocale('git_commit_content')}"`, { cwd: anwser.destDir }); + } catch (err) { + throw err; + } + } +} + +export default { syncRemoteProject, initGit }; diff --git a/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js index a426299..fa2b80d 100644 --- a/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js +++ b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js @@ -55,3 +55,11 @@ export const extensionShortName = { name: 'extensionShortName', default: '', }; + +// 4、chrome 扩展短名称 +export const extensionAuthor = { + type: 'input', + message: i18n.getLocale('extensionAuthor'), + name: 'extensionAuthor', + default: '', +}; diff --git a/scripts/build.sh b/scripts/build.sh index 5cd16fc..27c7852 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,4 +1,4 @@ -# 开发启动脚本 +# 生产环境脚本 # 首次启动时删除之前构建出的“dist”文件夹 rm -rf ./packages/@muniz/*/dist diff --git a/scripts/clear.sh b/scripts/clear.sh new file mode 100755 index 0000000..937e8e8 --- /dev/null +++ b/scripts/clear.sh @@ -0,0 +1,7 @@ +# 清楚副本垃圾数据脚本 + +# 删除 “dist” 文件夹 +rm -rf ./packages/@muniz/*/dist + +# 提示打包成功 +echo 'Muniz 脚手架 垃圾数据清楚完毕'