代码拉取完成,页面将自动刷新
const Handlebars = require('handlebars');
module.exports = function (plop) {
plop.setHelper('titleCaseWithoutSpace', function (text) {
// Remove spaces in case text is hyphenated
const template = Handlebars.compile('{{titleCase text}}');
const titleCased = template({ text });
return titleCased.split(/\s/).join('');
});
plop.setGenerator('app', {
description: 'Adds a new app to Rxdrag',
prompts: [
{
type: 'input',
name: 'name',
message: 'app package name',
default: 'app-name',
validate: name => {
if (/\s/g.test(name)) {
throw new Error("Name can't have spaces");
}
return true;
},
transformer: name => name.toLowerCase()
},
{
type: 'input',
name: 'description',
message: 'app description',
default: 'Rxdrag Application'
},
{
type: 'input',
name: 'maintainer',
message: 'maintainer name',
default: 'Water.li'
}
],
actions: [
{
type: 'addMany',
destination: 'apps/{{name}}',
base: 'tools/generators/app',
templateFiles: 'tools/generators/app'
},
{
type: 'modify',
path: 'apps/core/package.json',
pattern: /"dependencies":\s*{/,
template: '"dependencies": {\n "@rxdrag/{{name}}": "workspace:*",'
},
{
type: 'modify',
path: 'apps/core/src/App.js',
pattern:
/const CoreApp = React.lazy\(\(\) => import\('\.\/routes'\)\);/,
template: `const CoreApp = React.lazy(() => import('./routes'));
const {{titleCaseWithoutSpace name}}App = React.lazy(() => import('@rxdrag/{{name}}'));`
},
{
type: 'modify',
path: 'apps/core/src/App.js',
pattern: /\{\/\* Applications \*\/\}/,
template: `{/* Applications */}
<Route path="/{{name}}">
<DefaultFallback>
<{{titleCaseWithoutSpace name}}App />
</DefaultFallback>
</Route>
`
},
{
type: 'modify',
path: 'packages/shared/src/constants/apps.js',
pattern: /\/\/ add default apps/,
template: `,{ href: '/{{name}}', icon: HelpIcon, description: '{{description}}', color: '#ffffff', contactEmail: 'hi@agarun.com' }
// add default apps`
},
function runPnpmInstall() {
const { spawn } = require('child_process');
const pnpmInstall = spawn('pnpm', ['install']);
pnpmInstall.stdout.pipe(process.stdout);
pnpmInstall.stderr.pipe(process.stderr);
}
]
});
plop.setGenerator('library', {
description: 'Adds a new library to Rxdrag',
prompts: [
{
type: 'input',
name: 'name',
message: 'library package name',
default: 'library-name',
validate: name => {
if (/\s/g.test(name)) {
throw new Error("Name can't have spaces");
}
return true;
},
transformer: name => name.toLowerCase()
},
{
type: 'input',
name: 'description',
message: 'library description',
default: 'Rxdrag Package'
},
{
type: 'input',
name: 'maintainer',
message: 'maintainer name',
default: 'Water.Li'
}
],
actions: [
{
type: 'addMany',
destination: 'packages/{{name}}',
base: 'tools/generators/library',
templateFiles: 'tools/generators/library'
}
]
});
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。