[caz](https://github.com/zce/caz)
zce / zce-cli Goto Github PK
View Code? Open in Web Editor NEWA CLI tool for my personal productivity, Scaffolding tools move to zce/caz 👉
Home Page: https://github.com/zce/caz
License: MIT License
A CLI tool for my personal productivity, Scaffolding tools move to zce/caz 👉
Home Page: https://github.com/zce/caz
License: MIT License
[caz](https://github.com/zce/caz)
wrapper.js
/**
* Wrapper plugin
* @param {Function} plugin Plugin function
* @return {Function} Plugin function
*/
const defaultPlugin = (files, app, next) => next()
module.exports = plugin => {
if (typeof plugin !== 'function') return defaultPlugin
const fnStr = plugin.toString()
const matches = /\(\s*([\s\S]*?)\s*\)/.exec(fnStr)
if (!matches) return defaultPlugin
const params = matches[1].split(/\s*,\s*/)
if (params.length !== 3) return defaultPlugin
// https://github.com/goatslacker/get-parameter-names/blob/master/index.js
const code = fnStr.replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, '')
const regexp = new RegExp(`${params[2]}\\(\\s*\\)`)
return regexp.test(code) ? plugin : defaultPlugin
}
.\bin\{{name}}.js
=> .\bin{{name}}.js
const path = require('path')
const { execSync } = require('child_process')
const validateName = require('validate-npm-package-name')
const semver = require('semver')
const rc = require('rc')
const util = require('./util')
const options = {}
const defaultPrompts = {
name: { type: 'input', message: 'name' }
}
const defaultValues = {
get name () {
return path.basename(options.dest)
},
get author () {
const npmrc = rc('npm', {
'init-author-name': '',
'init-author-email': '',
'init-author-url': ''
})
const email = npmrc['init-author-email']
const url = npmrc['init-author-url']
return npmrc['init-author-name'] + (email ? ` <${email}>` : '') + (url ? ` (${url})` : '')
},
get version () {
const npmrc = rc('npm', {
'init-version': '0.1.0'
})
return npmrc['init-version']
},
get license () {
const npmrc = rc('npm', {
'init-license': 'MIT'
})
return npmrc['init-license']
},
get repository () {
if (!util.execSync(options.dest)) return
try {
return execSync(`cd ${options.dest} && git config --local --get remote.origin.url`).toString().trim()
} catch (e) {}
}
}
const defaultValidates = {
name: input => {
const result = validateName(input)
if (result.validForNewPackages) return true
return `Sorry, ${(result.errors || []).concat(result.warnings || []).join(' and ')}.`
},
version: input => {
const result = semver.valid(input)
if (result) return true
return `Sorry, The '${input}' is not a semantic version.`
}
}
/**
* Convert all questions
* @param {Object} prompts Prompts
* @return {String} dest Destination path
* @return {Array} All questions
*/
module.exports = (dest, prompts) => {
// globally dest
options.dest = dest
prompts = Object.assign({}, defaultPrompts, prompts)
return Object.keys(prompts).map(key => {
const item = Object.assign({ name: key }, prompts[key])
// default value
if (typeof item.default === 'string' && item.default.startsWith('$')) {
item.default = defaultValues[item.default.substr(1)]
}
// default validate
const builtIn = defaultValidates[key]
if (builtIn) {
const custom = item.validate
item.validate = input => {
const result = builtIn(input)
if (result !== true) return result
return typeof custom !== 'function' ? true : custom(input)
}
}
return item
})
}
prompt when press ^C at any time.
Git init when init completed
Use Nunjucks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.