当前位置:网站首页>Scaffold development foundation
Scaffold development foundation
2022-07-05 10:48:00 【Code Bruce Lee】
Basics
The goal is
v create demo
The plugin is introduced
commander
Document address
explain : Command line plug-ins
Usage method :
const { program } = require(‘commander’)
program.version(‘0.0.1’)
program.option(“-n “, “ Output name ”)
// Parameters must use <> Wrapped in the form of
program.option(”-t --type ”, “ Project type ”)
// Output options
// const options = program.opts()
// console.log(“opts=>”, options)
program.opts()
program
// command
.command(“create ”)
// describe
.description(“ Create a standard Vue project ”)
// Behavior
.action(name => {
console.log(“ Creating Vue project , The name is :” + name)
})
// Must pass parse Only by analyzing the way , Need to be at the end
program.parse(process.argv)
figlet
Document address
explain : Large character - The terminal prints large text
Usage method :
// callback form
const figlet = require(“figlet”)
figlet(‘Hello World!!’, function (err, data) {
if (err) {
console.log(‘Something went wrong…’)
console.dir(err)
return
}
console.log(data)
});
// async form
let { promisify } = require(“util”)
let figlet = require(“figlet”)
let asyncFiglet = promisify(require(“figlet”))
async function run() {
try {
let data = await asyncFiglet(“Vue 3”)
console.log(data)
} catch (error) {
console.log(error)
}
}
run()
inquirer
Document address
explain : Command line parameter input interaction
Usage method :
let inquirer = require(“inquirer”)
// prompt Accept an array , You can ask multiple
inquirer.prompt([
{
name: “userName”,// Printed text
type: “input”, // type There are many types of list, input, checkbox…
message: “ What is your name? ?” // Options
},
{
name: “age”,
type: “checkbox”,
message: “ How old are you ?”,
choices: [“20-25”, “25-30”, “30-40”, “40 above ”]
}
]).then(answer => {
console.log(“ Answer content :”, answer)
}).catch((error) => {
if (error.isTryError) { } else { }
})
chalk
Document address
explain : Color text - Beautify terminal character display
Usage method :
let chalk = require(“chalk”)
const log = console.log
log(chalk.blue(‘hello’) + ’ world’ + chalk.red(‘!’))
ora
Document address
explain :loading effect
Usage method :
const ora = require(‘ora’)
const spinner = ora(‘Loading unicorns’).start()
setTimeout(() => {
spinner.color = ‘yellow’
spinner.text = ‘Loading rainbows’
setTimeout(() => {
spinner.stop()
}, 1000)
}, 2000)
download-git-repo
Document address
explain : Warehouse downloading
Usage method :
let download = require(“download-git-repo”)
// direct:git Address , demo1 It means where to put it
download(‘direct:https://xxx.git’, ‘Demo1’, { clone: true }, function (err) {
console.log(err ? ‘Error’ : ‘Success’)
})
Scaffold development process
Create an empty project / Folder
adopt npm/yarn initialization package file
npm init
yarn init
Installing a plug-in
npm install commander figlet inquirer chalk ora download-git-repo -S
yarn add commander figlet inquirer chalk ora download-git-repo -S
establish bin Catalog
|-bin
|–index.js
|–init.js
package.json
Development command line
/**
- Develop backstage scaffolding , Quickly generate standards Vue Background architecture
*/
let program = require(“commander”)
let { promisify } = require(‘util’)
let asyncFiglet = promisify(require(“figlet”))
let chalk = require(“chalk”)
let inquirer = require(“inquirer”)
let init = require(“./init”)
// Log print function
const log = content => console.log(chalk.yellow(content))
// Set version and parameters
program.version(“1.0.0”);
program.option(“-n --name ”, “output name”);
// Print LOGO
async function printLogo() {
let data = await asyncFiglet(“v-cli”);
log(data);
}
program
.command(“create ”)
.description(“ establish Vue project ”)
.action(async (name) => {
await printLogo()
log(“ Ready to create project …”)
let answer = await inquirer.prompt([
{
name: “language”,
type: “list”,
message: “ Please select the language version ”,
choices: [“Javascript”, “Typescript”]
}
])
if (answer.language == “Javascript”) {
// Download framework
log(“ You chose Javascript edition , About to enter download mode .”)
init(name);
} else {
log(“ Coming soon !!!”)
}
})
// Argument parsing
program.parse(process.argv)
// init.js
/**
- Project cloning
*/
let { promisify } = require(‘util’)
const ora = require(“ora”)
const download = promisify(require(“download-git-repo”))
const shell = require(“shelljs”)
let chalk = require(“chalk”)
// Log print function
const log = content => console.log(chalk.yellow(content))
module.exports = async (appName) => {
log( Create project ${appName}
)
shell.rm(“-rf”, appName);
const spinner = ora(“ In the download …”).start();
try {
await download(“direct:https://xxx.git”, appName, { clone: true })
spinner.succeed(“ Download complete ”)
log(`
Download complete , Please execute the following command to start the project :
cd ${appName}
yarn perhaps npm init
npm run dev
perhaps
yarn dev
) } catch (error) { log(
Download failed `, error)
spinner.stop();
}
}
边栏推荐
- BOM//
- Learning notes 5 - high precision map solution
- Taro advanced
- Implementation of wechat applet bottom loading and pull-down refresh
- Lazy loading scheme of pictures
- A usage example that can be compatible with various database transactions
- Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
- Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
- Buried point 111
- 数据类型、
猜你喜欢
5g NR system architecture
"Everyday Mathematics" serial 58: February 27
32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
SAP UI5 ObjectPageLayout 控件使用方法分享
Go language learning notes - first acquaintance with go language
ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
Honing · fusion | know that the official website of Chuangyu mobile terminal is newly launched, and start the journey of digital security!
非技術部門,如何參與 DevOps?
Based on shengteng AI Yisa technology, it launched a full target structured solution for video images, reaching the industry-leading level
Secteur non technique, comment participer à devops?
随机推荐
上拉加载原理
非技術部門,如何參與 DevOps?
Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework
Pseudo class elements -- before and after
C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
QT implements JSON parsing
【Vite】1371- 手把手开发 Vite 插件
关于vray5.2怎么关闭日志窗口
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
Taro进阶
PWA (Progressive Web App)
中职组网络安全2021年江苏省省赛题目5套题目环境+解析全有需要的私信我
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
LSTM应用于MNIST数据集分类(与CNN做对比)
Taro advanced
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
2021年山东省赛题库题目抓包
go语言学习笔记-初识Go语言
小红书自研KV存储架构如何实现万亿量级存储与跨云多活
图片懒加载的方案