Skip to content

Commit

Permalink
feat(@muniz/muniz-plugin-create): 开发创建模版插件
Browse files Browse the repository at this point in the history
affects: @muniz/cli, @muniz/muniz-plugin-create

创建pc模版、创建chrome扩展模版、创建脚手架插件模版
  • Loading branch information
1160007652 committed Dec 14, 2020
1 parent 5112ea4 commit 3f76ffe
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 144 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"scripts": {
"dev": "nodemon --exec ./scripts/dev.sh",
"build": "./scripts/build.sh",
"clear": "./scripts/clear.sh",
"commit": "git-cz"
},
"config": {
Expand Down
5 changes: 5 additions & 0 deletions packages/@muniz/cli/dist/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 设定的最小兼容版本号
Expand Down
11 changes: 3 additions & 8 deletions packages/@muniz/cli/dist/configs/system.json
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": []
}
5 changes: 5 additions & 0 deletions packages/@muniz/cli/src/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import {
import i18n from '../lib/i18n';
i18n.initI18n();

/**
* const USER_HOME = process.env.HOME || process.env.USERPROFILE;
* 用户目录
**/

/**
*
* @param {String} wanted 设定的最小兼容版本号
Expand Down
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 packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js
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 packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js
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 packages/@muniz/muniz-plugin-create/src/command/Extension/index.js
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;
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 packages/@muniz/muniz-plugin-create/src/command/H5/index.js
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;
34 changes: 6 additions & 28 deletions packages/@muniz/muniz-plugin-create/src/command/Pc/index.js
Original file line number Diff line number Diff line change
@@ -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 });
Expand All @@ -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;
62 changes: 31 additions & 31 deletions packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js
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;
Loading

0 comments on commit 3f76ffe

Please sign in to comment.