Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

Commit

Permalink
cooking-cli: support yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Oct 23, 2016
1 parent 7e768d1 commit 5756e58
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG

## [v1.2.0] 未发布
- cooking-cli:
- 支持 yarn,通过 `cooking config pm yarn` 将包管理设置成 yarn 即可

## [v1.1.4] 2016.10.13
- cooking:
- 去掉全局安装 cooking 的提示
Expand Down
4 changes: 2 additions & 2 deletions packages/cooking-cli/bin/cooking-config
Expand Up @@ -11,15 +11,15 @@ const value = program.args[1] || ''

if (!option) {
logger.log('--------------')
logger.log('配置信息')
logger.log('config info')
logger.log('--------------')

console.log(json.plain(config.get()))
process.exit()
}

if (!config.set(option, value)) {
logger.fatal('不存在配置项')
logger.fatal('The option is not exist')
}
config.get(option)
logger.success(option + ' = ' + config.get(option))
20 changes: 10 additions & 10 deletions packages/cooking-cli/util/config.js
Expand Up @@ -6,6 +6,14 @@ const PLUGIN_PATH = require('./path').PLUGIN_PATH

const filename = 'config.json'
const filePath = path.join(PLUGIN_PATH, filename)
const defaultConfig = {
template: 'vue',
pm: 'npm',
registry: '',
updateCheck: true,
github: '',
author: ''
}

const formatBoolean = value => {
if (value === 'true') {
Expand All @@ -22,15 +30,7 @@ const requireFile = () => {

exports.init = () => {
if (!fs.existsSync(filePath)) {
const config = {
template: 'vue',
registry: '',
updateCheck: true,
github: '',
author: ''
}

fs.writeFileSync(filePath, JSON.stringify(config, null, 2))
fs.writeFileSync(filePath, JSON.stringify(defaultConfig, null, 2))
}
}

Expand All @@ -45,7 +45,7 @@ exports.get = option => {
exports.set = (option, value) => {
const config = requireFile()

if (config[option] !== undefined) {
if (defaultConfig.hasOwnProperty(option)) {
config[option] = formatBoolean(value)
fs.writeFileSync(filePath, JSON.stringify(config, null, 2))

Expand Down
14 changes: 14 additions & 0 deletions packages/cooking-cli/util/npm-commands.json
@@ -0,0 +1,14 @@
{
"npm": {
"install": "install",
"uninstall": "uninstall",
"update": "update",
"name": "npm"
},
"yarn": {
"install": "add",
"uninstall": "remove",
"update": "upgrade",
"name": "yarn"
}
}
14 changes: 10 additions & 4 deletions packages/cooking-cli/util/npm.js
Expand Up @@ -5,6 +5,12 @@ const exec = require('./exec')
const PLUGIN_PATH = require('./path').PLUGIN_PATH
const checkRegistry = require('./check').registry
const config = require('./config')
const commands = require('./npm-commands.json')
const pm = commands[require('./config').get('pm')]
const logger = require('./logger')
if (!pm) {
logger.fatal('Only supports ' + Object.keys(commands).join(', '))
}

const npm = (options, registry) => {
registry = registry || config.get('registry')
Expand All @@ -17,11 +23,11 @@ const npm = (options, registry) => {

shelljs.cd(PLUGIN_PATH)
options = options.concat(['--save', '--silent', '--save-prefix=>='])
exec('npm', options, {stdio: 'inherit'})
exec(pm.name, options, {stdio: 'inherit'})
shelljs.cd(pwd)
}

exports.install = (name, registry) => npm(['install'].concat(name), registry)
exports.update = (name, registry) => npm(['update'].concat(name), registry)
exports.uninstall = name => npm(['uninstall'].concat(name))
exports.install = (name, registry) => npm([pm.install].concat(name), registry)
exports.update = (name, registry) => npm([pm.update].concat(name), registry)
exports.uninstall = name => npm([pm.uninstall].concat(name))
exports.list = () => npm(['list', '--depth=0'])

0 comments on commit 5756e58

Please sign in to comment.