Socket
Socket
Sign inDemoInstall

arco-cli-init

Package Overview
Dependencies
367
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

lib/defaultQuestionList.d.ts

500

lib/init.js

@@ -11,2 +11,13 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -25,97 +36,13 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const locale_1 = __importDefault(require("./locale"));
const PACKAGE_NAME_TEMPLATE_CORE = '@arco-materials/template-core';
const PACKAGE_NAME_TEMPLATE_MONOREPO = '@arco-materials/template-monorepo';
// Available templates
// Temporarily change value of template via process.env.TEMPLATE
const MATERIAL_TYPE_MAP = new Proxy({
'react-component': {
name: locale_1.default.LABEL_COMPONENT,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'react-block': {
name: locale_1.default.LABEL_BLOCK,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'react-page': {
name: locale_1.default.LABEL_PAGE,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'react-library': {
name: locale_1.default.LABEL_LIBRARY,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'react-monorepo': {
name: locale_1.default.LABEL_MONOREPO,
template: PACKAGE_NAME_TEMPLATE_MONOREPO,
},
'vue-component': {
name: locale_1.default.LABEL_COMPONENT,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'vue-library': {
name: locale_1.default.LABEL_LIBRARY,
template: PACKAGE_NAME_TEMPLATE_CORE,
},
'vue-monorepo': {
name: locale_1.default.LABEL_MONOREPO,
template: PACKAGE_NAME_TEMPLATE_MONOREPO,
},
'arco-design-pro-react': {
name: locale_1.default.LABEL_ARCO_PRO,
template: 'arco-design-pro',
},
'arco-design-pro-vue': {
name: locale_1.default.LABEL_ARCO_PRO,
template: 'arco-design-pro-vue',
},
const TEMPLATE_PACKAGE_NAME = new Proxy({
core: '@arco-materials/template-core',
monorepo: '@arco-materials/template-monorepo',
'pro-react': 'arco-design-pro',
'pro-vue': 'arco-design-pro-vue',
'team-site-react': '@arco-materials/template-team-site',
}, {
get: (obj, propName) => {
const property = obj[propName];
return process.env.TEMPLATE ? Object.assign(Object.assign({}, property), { template: process.env.TEMPLATE }) : property;
},
get: (obj, propName) => process.env.TEMPLATE || obj[propName],
});
const TYPES_MATERIAL = ['react-component', 'react-block', 'react-page'];
const TYPES_FOR_REACT = [
'react-component',
'react-block',
'react-page',
'react-library',
'react-monorepo',
'arco-design-pro-react',
];
const TYPES_FOR_VUE = ['vue-component', 'vue-library', 'vue-monorepo', 'arco-design-pro-vue'];
// Templates for Monorepo
const VALID_TYPES_IN_MONOREPO = [
'react-component',
'react-block',
'react-page',
'react-library',
'vue-component',
'vue-library',
];
const CATEGORIES_COMPONENT = [
'数据展示',
'信息展示',
'表格',
'表单',
'筛选',
'弹出框',
'编辑器',
'其他',
];
const CATEGORIES_BLOCK = [
'基础模版',
'官网模版',
'注册登陆',
'数据展示',
'信息展示',
'表格',
'表单',
'筛选',
'弹出框',
'编辑器',
'可视化',
'其他',
];
const CATEGORIES_PAGE = CATEGORIES_BLOCK;
/**

@@ -139,10 +66,45 @@ * Init project

}
const getCreateProjectOptions = () => __awaiter(this, void 0, void 0, function* () {
// Create a pure project
if (isPureProject) {
return getPureProjectConfig();
let createProjectOptions = {
template: null,
};
if (isPureProject) {
const { template, name } = yield inquirer_1.default.prompt([
{
type: 'input',
name: 'template',
message: locale_1.default.TIP_INPUT_TEMPLATE_NAME_FOR_PURE_PROJECT,
// Template for Arco material team site
default: TEMPLATE_PACKAGE_NAME['team-site-react'],
},
{
type: 'input',
name: 'name',
message: locale_1.default.TIP_INPUT_PACKAGE_NAME_FOR_PURE_PROJECT,
},
]);
createProjectOptions = {
template,
packageJson: { name },
};
}
else {
const baseInfo = {
ENV_MONOREPO: isForMonorepo,
};
// Try to skip select framework if in a monorepo project
if (isForMonorepo) {
try {
const pathGitRoot = (0, arco_cli_dev_utils_1.getGitRootPath)();
const { dependencies, devDependencies } = fs_extra_1.default.readJsonSync(path_1.default.resolve(pathGitRoot, 'package.json')) || {};
if ((dependencies && dependencies.react) || (devDependencies && devDependencies.react)) {
baseInfo.framework = 'react';
}
else if ((dependencies && dependencies.vue) || (devDependencies && devDependencies.vue)) {
baseInfo.framework = 'vue';
}
}
catch (error) { }
}
// When the user specifies a template
// When the user specifies a template, get meta info from package.json
if (template) {
let metaInTemplate = {};
try {

@@ -158,34 +120,20 @@ let packageJson = null;

}
metaInTemplate = packageJson && packageJson[metaFileName];
const metaInTemplate = packageJson && packageJson[metaFileName];
if (metaInTemplate) {
baseInfo.meta = metaInTemplate;
baseInfo.type = metaInTemplate.type;
}
}
catch (e) { }
let materialType = metaInTemplate === null || metaInTemplate === void 0 ? void 0 : metaInTemplate.type;
if (!materialType) {
materialType = yield inquiryMaterialType({
template,
isForMonorepo,
});
}
return getComponentConfig({
type: materialType,
template,
metaFileName,
isForMonorepo,
meta: metaInTemplate,
});
}
const framework = yield inquiryFramework(isForMonorepo);
const materialType = yield inquiryMaterialType({
framework,
template,
isForMonorepo,
const infoFromUser = yield (0, arco_cli_dev_utils_1.getAnswerFromUser)({
command: 'init',
baseInfo,
});
switch (materialType) {
case 'arco-design-pro-vue':
case 'arco-design-pro-react':
return getArcoDesignProConfig(framework);
case 'react-monorepo':
case 'vue-monorepo':
return {
template: PACKAGE_NAME_TEMPLATE_MONOREPO,
// Material type is something like react-component/vue-component
const materialType = baseInfo.type || `${infoFromUser.framework}-${infoFromUser.type}`;
switch (infoFromUser.type) {
case 'monorepo': {
createProjectOptions = {
template: TEMPLATE_PACKAGE_NAME.monorepo,
customInitFunctionParams: {

@@ -195,14 +143,39 @@ type: materialType,

};
default:
return getComponentConfig({
type: materialType,
template,
metaFileName,
isForMonorepo,
});
break;
}
case 'pro': {
createProjectOptions = {
template: TEMPLATE_PACKAGE_NAME[`pro-${infoFromUser.framework}`],
beforeGitCommit: () => null,
customInitFunctionParams: {
framework: infoFromUser.arcoProOptions.framework,
simple: infoFromUser.arcoProOptions.type === 'simple',
},
};
break;
}
default: {
const _a = infoFromUser.meta, { name, version, description } = _a, rest = __rest(_a, ["name", "version", "description"]);
createProjectOptions = {
template: TEMPLATE_PACKAGE_NAME.core,
packageJson: {
name,
version,
description,
[metaFileName]: Object.assign({ type: materialType }, rest),
},
customInitFunctionParams: {
isForMonorepo,
type: materialType,
packageName: name,
},
};
break;
}
}
});
const extraOptions = yield getCreateProjectOptions();
}
if (template) {
createProjectOptions.template = template;
}
return (0, arco_cli_create_project_1.default)(Object.assign({ root,
template,
projectName,

@@ -214,3 +187,3 @@ isForMonorepo, beforeGitCommit: () => {

}
} }, extraOptions)).catch((err) => {
} }, createProjectOptions)).catch((err) => {
arco_cli_dev_utils_1.print.error(err);

@@ -222,256 +195,1 @@ throw err;

exports.default = default_1;
/**
* Ask the type of material to be created
*/
function inquiryMaterialType({ framework = 'react', template, isForMonorepo, }) {
return __awaiter(this, void 0, void 0, function* () {
arco_cli_dev_utils_1.print.info(`\n${locale_1.default.TIP_INFO_ABOUT_TEMPLATE}\n`);
const { type } = yield inquirer_1.default.prompt([
{
type: 'list',
name: 'type',
message: template ? locale_1.default.TIP_SELECT_TYPE_OF_MATERIAL : locale_1.default.TIP_SELECT_TYPE_OF_PROJECT,
choices: Object.entries(MATERIAL_TYPE_MAP)
.filter(([key]) => {
if (template) {
return TYPES_MATERIAL.indexOf(key) > -1;
}
return ((framework === 'react' && TYPES_FOR_REACT.indexOf(key) > -1) ||
(framework === 'vue' && TYPES_FOR_VUE.indexOf(key) > -1));
})
.filter(([key]) => !isForMonorepo || VALID_TYPES_IN_MONOREPO.indexOf(key) !== -1)
.map(([key, { name }]) => ({ name, value: key })),
},
]);
return type;
});
}
/**
* Ask the meta information of the material
*/
function inquiryMaterialMeta(meta) {
return __awaiter(this, void 0, void 0, function* () {
let categories = [];
switch (meta.type) {
case 'vue-component':
categories = CATEGORIES_COMPONENT;
break;
case 'react-component':
categories = CATEGORIES_COMPONENT;
break;
case 'react-block':
categories = CATEGORIES_PAGE;
break;
case 'react-page':
break;
default:
break;
}
return inquirer_1.default.prompt([
{
type: 'input',
name: 'name',
message: locale_1.default.TIP_INPUT_PACKAGE_NAME,
default: meta.name,
validate: (input) => {
return input.trim() ? true : locale_1.default.ERROR_NO_PACKAGE_NAME;
},
},
{
type: 'input',
name: 'title',
message: locale_1.default.TIP_INPUT_TITLE,
default: meta.title || '',
validate: (input) => {
return input.trim() ? true : locale_1.default.ERROR_NO_TITLE;
},
},
{
type: 'input',
name: 'description',
message: locale_1.default.TIP_INPUT_DESCRIPTION,
default: meta.description || '',
},
{
type: 'input',
name: 'version',
message: locale_1.default.TIP_INPUT_VERSION,
default: '0.1.0',
},
{
type: 'checkbox',
name: `category`,
message: locale_1.default.TIP_SELECT_CATEGORY,
choices: categories,
default: meta.category || categories[categories.length - 1],
when: () => categories.length,
},
]);
});
}
/**
* Ask framework
*/
function inquiryFramework(isForMonorepo) {
return __awaiter(this, void 0, void 0, function* () {
let framework = null;
// Try to get the framework dependencies of the current warehouse
if (isForMonorepo) {
try {
const pathGitRoot = (0, arco_cli_dev_utils_1.getGitRootPath)();
const { dependencies, devDependencies } = fs_extra_1.default.readJsonSync(path_1.default.resolve(pathGitRoot, 'package.json')) || {};
if ((dependencies && dependencies.react) || (devDependencies && devDependencies.react)) {
framework = 'react';
}
else if ((dependencies && dependencies.vue) || (devDependencies && devDependencies.vue)) {
framework = 'vue';
}
}
catch (error) { }
}
if (!framework) {
const answer = yield inquirer_1.default.prompt({
type: 'list',
name: 'framework',
message: locale_1.default.TIP_SELECT_FRAMEWORK,
choices: ['React', 'Vue'],
});
framework = answer.framework.toLowerCase();
}
return framework;
});
}
/**
* Get the template to create Arco Pro
*/
function getArcoDesignProConfig(framework) {
return __awaiter(this, void 0, void 0, function* () {
// Avoid creating arco.config.js before git commit
const beforeGitCommit = () => null;
if (framework === 'vue') {
const vueProQuestion = [
{
type: 'list',
name: 'type',
message: locale_1.default.TIP_SELECT_PRO_VUE_TEMPLATE,
choices: [
{
name: locale_1.default.PRO_VUE_TEMPLATE_SIMPLE,
value: 'simple',
},
{
name: locale_1.default.PRO_VUE_TEMPLATE_COMPLETE,
value: 'full',
},
],
},
];
const answer = yield inquirer_1.default.prompt(vueProQuestion);
return {
template: MATERIAL_TYPE_MAP['arco-design-pro-vue'].template,
beforeGitCommit,
// TODO List for Vue Pro
customInitFunctionParams: {
framework: 'vite',
simple: answer.type === 'simple',
},
};
}
const question = [
{
type: 'list',
name: 'framework',
message: locale_1.default.TIP_SELECT_ARCO_PRO_TYPE,
choices: [
{
name: 'Next (https://nextjs.org/)',
value: 'next',
},
{
name: 'Vite (https://vitejs.dev/)',
value: 'vite',
},
{
name: 'Create React App (https://create-react-app.dev)',
value: 'cra',
},
],
},
{
type: 'list',
name: 'type',
message: locale_1.default.TIP_SELECT_PRO_REACT_TEMPLATE,
choices: [
{
name: locale_1.default.PRO_REACT_TEMPLATE_SIMPLE,
value: 'simple',
},
{
name: locale_1.default.PRO_REACT_TEMPLATE_COMPLETE,
value: 'full',
},
],
when: () => framework === 'react',
},
];
const answer = yield inquirer_1.default.prompt(question);
return {
template: MATERIAL_TYPE_MAP['arco-design-pro-react'].template,
beforeGitCommit,
customInitFunctionParams: {
framework: answer.framework,
simple: answer.type === 'simple',
},
};
});
}
/**
* Get template, Arco version, packageJson information needed to create the project
*/
function getComponentConfig({ type, template = MATERIAL_TYPE_MAP[type].template, metaFileName, meta, isForMonorepo, }) {
return __awaiter(this, void 0, void 0, function* () {
meta = meta || {};
meta.type = type;
const answer = yield inquiryMaterialMeta(meta);
const packageInfo = {
name: answer.name,
version: answer.version,
description: answer.description,
[metaFileName]: Object.assign(Object.assign({}, meta), { title: answer.title, category: [...new Set((answer.category || []).concat(meta.category || []))] }),
};
return {
template,
packageJson: packageInfo,
customInitFunctionParams: {
type,
isForMonorepo,
packageName: packageInfo.name,
},
};
});
}
/**
* Get the parameters needed to create non-material items
*/
function getPureProjectConfig() {
return __awaiter(this, void 0, void 0, function* () {
const { template, name } = yield inquirer_1.default.prompt([
{
type: 'input',
name: 'template',
message: locale_1.default.TIP_INPUT_TEMPLATE_NAME_FOR_PURE_PROJECT,
// Template for Arco material team site
default: '@arco-materials/template-team-site',
},
{
type: 'input',
name: 'name',
message: locale_1.default.TIP_INPUT_PACKAGE_NAME_FOR_PURE_PROJECT,
},
]);
return {
template,
packageJson: { name },
};
});
}
{
"name": "arco-cli-init",
"version": "1.1.0",
"version": "1.2.0",
"description": "A module of Arco CLI to init a project",

@@ -14,4 +14,4 @@ "main": "lib/init.js",

"arco-cli-config": "^1.0.0",
"arco-cli-create-project": "^1.0.0",
"arco-cli-dev-utils": "^1.0.0",
"arco-cli-create-project": "^1.0.1",
"arco-cli-dev-utils": "^1.1.0",
"fs-extra": "^9.0.1",

@@ -23,3 +23,4 @@ "inquirer": "^7.2.0"

],
"license": "MIT"
"license": "MIT",
"gitHead": "3a876b41778a8e7576c7d456bbe2c49f447dd1df"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc