New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-qbi-app

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-qbi-app - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0-beta

bin/utils/inquirer.js

85

bin/create.js

@@ -1,47 +0,50 @@

const fs = require('fs');
const rimraf = require('rimraf');
const child_process = require('child_process');
const logger = require('./utils/logger');
const { FRAMEWORK_BRANCH, GIT } = require('./utils/config');
const path = require('path');
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createApp = void 0;
const fs = require("fs");
const child_process_1 = require("child_process");
const logger_1 = require("./utils/logger");
const config_1 = require("./utils/config");
const path = require("path");
const cwd = process.cwd();
const execSync = child_process.execSync;
/**
* 从 git 仓库拉取模板代码并写入目标目录
*/
function createApp(projectName, framework) {
const branch = FRAMEWORK_BRANCH[framework];
const cmd = `git clone --quiet --depth=1 --branch=${branch} ${GIT} ./${projectName}`;
execSync(cmd);
logger.info(`Creating new ${framework} project "${projectName}" ...`);
logger.info(cmd);
const projectPackage = path.resolve(cwd, `./${projectName}/package.json`);
fs.readFile(projectPackage, 'utf8', function (err, data) {
if (err) {
rimraf.sync(path.resolve(cwd, `./${projectName}`));
throw new Error(err);
}
rimraf.sync(path.resolve(cwd, `./${projectName}/.git`));
const json = JSON.parse(data);
json.name = projectName;
json.version = '0.1.0';
fs.writeFile(projectPackage, JSON.stringify(json, null, 2), function () {
logger.done(
`Create success! Learn more: https://www.yuque.com/u2227425/ia1pn8/xaia8g#XmLfe`,
);
function createApp(projectName, branch) {
return __awaiter(this, void 0, void 0, function* () {
const cmd = `git clone --quiet --depth=1 --branch=${branch} ${config_1.GIT} ./${projectName}`;
(0, child_process_1.execSync)(cmd);
logger_1.default.info(`Creating new project "${projectName}" ...`);
logger_1.default.info(cmd);
const projectPackage = path.resolve(cwd, `./${projectName}/package.json`);
fs.readFile(projectPackage, 'utf8', function (err, data) {
if (err) {
fs.rmSync(path.resolve(cwd, `./${projectName}`), {
recursive: true,
force: true,
});
throw err;
}
fs.rmSync(path.resolve(cwd, `./${projectName}/.git`), {
recursive: true,
force: true,
});
const json = JSON.parse(data);
json.name = projectName;
json.version = '0.1.0';
fs.writeFile(projectPackage, JSON.stringify(json, null, 2), function () {
logger_1.default.done(`Create success! Learn more: https://www.yuque.com/u2227425/ia1pn8/xaia8g#XmLfe`);
});
});
});
});
}
module.exports = {
createApp,
};
exports.createApp = createApp;
#! /usr/bin/env node
const program = require('commander');
const { createApp } = require('./create');
const packageJson = require('../package.json');
const {
validate,
validateProjectName,
validateUniqueProjectName,
validateFrameworkName,
} = require('./utils/validate.js');
const logger = require('./utils/logger');
const { FRAMEWORK_ORIGIN, FRAMEWORK_BRANCH } = require('./utils/config');
const framework = Object.keys(FRAMEWORK_BRANCH);
const projectNameValidator = validate([
validateProjectName,
validateUniqueProjectName,
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const inquirer = require("inquirer");
const create_1 = require("./create");
const packageJson = require("../package.json");
const validate_1 = require("./utils/validate");
const logger_1 = require("./utils/logger");
const config_1 = require("./utils/config");
const inquirer_1 = require("./utils/inquirer");
const program = new commander_1.Command();
inquirer.registerPrompt('list-desc', inquirer_1.DescList);
const pureTemplate = (0, config_1.templateFilter)(config_1.TEMPLATES);
const projectNameValidator = (0, validate_1.validate)([
validate_1.validateProjectName,
validate_1.validateUniqueProjectName,
]);
const frameworkValidator = validate([validateFrameworkName]);
const legacyVersionValidator = (0, validate_1.validate)([validate_1.validateLegacyVersion]);
program
.version(packageJson.version, '-v, --version', 'output the current version')
.option(
'-f, --framework [framework]',
`choose a framework you want to work in! the value must be within (${framework.join(
' | ',
)})`,
FRAMEWORK_ORIGIN,
);
.version(packageJson.version, '-v, --version', 'Output the current version.')
.option('-t, --template [template]', `Choose a template you want to work in. the value must be within (${pureTemplate
.map(each => `"${each.name}"`)
.join(' | ')}).`)
.option('-l, --legacy [legacy]', `Use template of legacy version. the value must be within (${Object.keys(config_1.LEGACY_VERSION)
.map(each => `"${each}"`)
.join(' | ')}).`);
program.parse(process.argv);
try {
const projectName = program.args[0];
if (
projectNameValidator(projectName) &&
frameworkValidator(program.framework)
) {
createApp(projectName, program.framework);
}
} catch (err) {
logger.error(err);
process.exit(1);
function run() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
let projectName = program.args[0];
if (!projectName) {
const answer = yield inquirer.prompt({
message: 'Please input project name.',
type: 'input',
name: 'projectName',
});
projectName = answer.projectName;
}
// must enter a project name
if (projectNameValidator(projectName)) {
let templateBranch;
let templateChoices = config_1.TEMPLATES;
// use legacy version template
if (program.legacy === true) {
const answer = yield inquirer.prompt({
message: 'Please choose a legacy version.',
type: 'list',
name: 'legacyVersion',
choices: Object.keys(config_1.LEGACY_VERSION),
});
templateChoices = config_1.LEGACY_VERSION[answer.legacyVersion];
}
else if (program.legacy && legacyVersionValidator(program.legacy)) {
templateChoices = config_1.LEGACY_VERSION[program.legacy];
}
const templateNameValidator = (0, validate_1.validate)([
(0, validate_1.validateTemplate)(templateChoices),
]);
if (!program.template) {
const answer = yield inquirer.prompt({
message: 'Please choose a template.',
type: 'list-desc',
name: 'template',
choices: templateChoices,
});
templateBranch = answer.template;
}
else if (program.template && templateNameValidator(program.template)) {
templateBranch = (_a = (0, config_1.templateFilter)(templateChoices).find(each => each.name === program.template)) === null || _a === void 0 ? void 0 : _a.value;
}
yield (0, create_1.createApp)(projectName, templateBranch);
}
}
catch (err) {
logger_1.default.error(err);
console.log(`\nExample: yarn create qbi-app myChart\n\n${program.helpInformation()}`);
process.exit(1);
}
});
}
if (!program.args.length) {
program.help();
}
run();

@@ -1,19 +0,59 @@

const FRAMEWORK_ORIGIN = 'origin';
const FRAMEWORK_REACT = 'react';
const FRAMEWORK_VUE = 'vue';
const FRAMEWORK_BRANCH = {
[FRAMEWORK_ORIGIN]: 'template/origin',
[FRAMEWORK_REACT]: 'template/react',
[FRAMEWORK_VUE]: 'template/vue',
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GIT = exports.templateFilter = exports.LEGACY_VERSION = exports.LEGACY_V312_TEMPLATES = exports.TEMPLATES = void 0;
const inquirer_1 = require("inquirer");
// latest version templates
exports.TEMPLATES = [
new inquirer_1.Separator('[custom chart]'),
{
name: 'chart',
value: 'template/origin',
description: 'Custom chart template',
},
{
name: 'chart-react',
value: 'template/react',
description: 'Custom chart template using React framework',
},
{
name: 'chart-vue',
value: 'template/vue',
description: 'Custom chart template using Vue framework',
},
new inquirer_1.Separator('[custom menu]'),
{
name: 'menu-dashboard-card',
value: 'template/menu-dashboard-card',
description: 'Custom menu of dashboard card',
},
{
name: 'menu-excel',
value: 'template/menu-excel',
description: 'Custom menu of web excel',
},
];
// legacy version v3.12 templates
exports.LEGACY_V312_TEMPLATES = [
new inquirer_1.Separator('[custom chart]'),
{
name: 'chart',
value: 'legacy/v3.12/template/origin',
description: '(v3.12) Custom chart template',
},
{
name: 'chart-react',
value: 'legacy/v3.12/template/react',
description: '(v3.12) Custom chart template using React framework',
},
{
name: 'chart-vue',
value: 'legacy/v3.12/template/vue',
description: '(v3.12) Custom chart template using Vue framework',
},
];
exports.LEGACY_VERSION = {
'v3.12': exports.LEGACY_V312_TEMPLATES,
};
const GIT = 'https://github.com/haili042/create-qbi-app.git';
module.exports = {
FRAMEWORK_ORIGIN,
FRAMEWORK_REACT,
FRAMEWORK_BRANCH,
FRAMEWORK_VUE,
GIT,
};
const templateFilter = (list) => list.filter(each => !(each instanceof inquirer_1.Separator));
exports.templateFilter = templateFilter;
exports.GIT = 'https://github.com/haili042/create-qbi-app.git';

@@ -0,43 +1,40 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getLogText(args) {
return Array.from(args).join(' ');
return Array.from(args).join(' ');
}
class Logger {
/**
* Outputs arguments with the "done" tag / colors
*
* @param {...*} arguments - arguments passed through to console.info
*/
static done(/* arguments */) {
console.info('\x1B[32m%s\x1B[0m', getLogText(arguments));
}
/**
* Outputs arguments with the "info" tag / colors
*
* @param {...*} arguments - arguments passed through to console.info
*/
static info(/* arguments */) {
console.info('\x1B[34m%s\x1B[0m', getLogText(arguments));
}
/**
* Outputs arguments with the "warn" tag / colors
*
* @param {...*} arguments - arguments passed through to console.warn
*/
static warn(/* arguments */) {
console.warn('\x1B[33m%s\x1B[0m', getLogText(arguments));
}
/**
* Outputs arguments with the "error" tag / colors
*
* @param {...*} arguments - arguments passed through to console.error
*/
static error(/* arguments */) {
console.error('\x1B[31m%s\x1B[0m', getLogText(arguments));
}
/**
* Outputs arguments with the "done" tag / colors
*
* @param {...*} arguments - arguments passed through to console.info
*/
static done(...args) {
console.info('\x1B[32m%s\x1B[0m', getLogText(args));
}
/**
* Outputs arguments with the "info" tag / colors
*
* @param {...*} arguments - arguments passed through to console.info
*/
static info(...args) {
console.info('\x1B[34m%s\x1B[0m', getLogText(args));
}
/**
* Outputs arguments with the "warn" tag / colors
*
* @param {...*} arguments - arguments passed through to console.warn
*/
static warn(...args) {
console.warn('\x1B[33m%s\x1B[0m', getLogText(args));
}
/**
* Outputs arguments with the "error" tag / colors
*
* @param {...*} arguments - arguments passed through to console.error
*/
static error(...args) {
console.error('\x1B[31m%s\x1B[0m', getLogText(args));
}
}
module.exports = Logger;
exports.default = Logger;

@@ -1,60 +0,67 @@

const fs = require('fs');
const path = require('path');
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateLegacyVersion = exports.validateTemplate = exports.validateUniqueProjectName = exports.validateProjectName = exports.validate = void 0;
const fs = require("fs");
const path = require("path");
const config_1 = require("./config");
const cwd = process.cwd();
const { FRAMEWORK_BRANCH } = require('./config');
// 校验多个规则
function validate(validators = []) {
return function (value) {
let errorMsg;
validators.find(validator => {
const msg = validator(value);
if (typeof msg === 'string') {
errorMsg = msg;
function validate(validators) {
return (value) => {
let errorMsg;
(validators || []).find(validator => {
const msg = validator(value);
if (typeof msg === 'string') {
errorMsg = msg;
return true;
}
if (msg === true) {
errorMsg = `${value} is invalid`;
return true;
}
return false;
});
if (errorMsg) {
throw new Error(errorMsg);
}
return true;
}
if (msg === true) {
errorMsg = `${value} is invalid`;
return true;
}
return false;
});
if (errorMsg) {
throw new Error(errorMsg);
}
return true;
};
};
}
exports.validate = validate;
// 校验项目名
function validateProjectName(projectName) {
if (projectName === undefined || projectName === null) {
return 'You must enter a project name';
}
if (!/^[a-z][a-z0-9_-]+$/.test(projectName)) {
return `The project must start with a letter and can only contain these symbols: a-z, 0-9, -, _`;
}
}
const validateProjectName = projectName => {
if (projectName === undefined || projectName === null) {
return 'You must enter a project name';
}
if (!/^[a-z][a-z0-9_-]+$/.test(projectName)) {
return `The project name must start with a letter and can only contain these symbols: a-z, 0-9, -, _`;
}
};
exports.validateProjectName = validateProjectName;
// 校验项目名是否重名
function validateUniqueProjectName(projectName) {
const pathName = path.resolve(cwd, projectName);
if (fs.existsSync(pathName)) {
return `File or folder "${pathName}" already exists`;
}
}
const validateUniqueProjectName = projectName => {
const pathName = path.resolve(cwd, projectName);
if (fs.existsSync(pathName)) {
return `File or folder "${pathName}" already exists`;
}
};
exports.validateUniqueProjectName = validateUniqueProjectName;
// 校验框架名
function validateFrameworkName(framework) {
if (FRAMEWORK_BRANCH[framework] === undefined) {
return `Expect the framework name to be within (${Object.keys(FRAMEWORK_BRANCH).join(' | ')}), but got "${framework}"`;
}
}
module.exports = {
validate,
validateProjectName,
validateUniqueProjectName,
validateFrameworkName,
const validateTemplate = (templates) => (templateName => {
const templateList = (0, config_1.templateFilter)(templates);
const tpl = templateList.find(each => each.name === templateName);
if (tpl === undefined) {
return `Expect the framework name to be within (${templateList
.map(each => `"${each.name}""`)
.join(' | ')}), but got "${templateName}"`;
}
});
exports.validateTemplate = validateTemplate;
const validateLegacyVersion = version => {
if (config_1.LEGACY_VERSION[version] === undefined) {
return `Expect the legacy version to be within (${Object.keys(config_1.LEGACY_VERSION)
.map(e => `"${e}"`)
.join(' | ')}), but got "${version}"`;
}
};
exports.validateLegacyVersion = validateLegacyVersion;
{
"name": "create-qbi-app",
"version": "0.0.3",
"version": "0.1.0-beta",
"description": "Command line tool for developing component for Quick BI",

@@ -8,2 +8,5 @@ "author": "Quick BI",

"scripts": {
"watch": "tsc -w --sourceMap",
"start": "ts-node -P ./tsconfig.json ./src/index.ts",
"build": "rm -rf bin && rm -rf .cache && tsc",
"prepublishOnly": "yarn version",

@@ -24,4 +27,9 @@ "postpublish": "git push --tag"

"commander": "6.2.0",
"rimraf": "^2.6.1"
"inquirer": "^8.2.0"
},
"devDependencies": {
"@types/inquirer": "^8.1.3",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc