├── .editorconfig
├── .gitattributes
├── .gitignore
├── README.md
├── bin
└── vuepack
├── index.js
├── lib
├── files
│ └── component.js
├── generate.js
├── generateComponent.js
└── init.js
└── package.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 2
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /src
2 | # Logs
3 | logs
4 | *.log
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18 | .grunt
19 |
20 | # node-waf configuration
21 | .lock-wscript
22 |
23 | # Compiled binary addons (http://nodejs.org/api/addons.html)
24 | build/Release
25 |
26 | # Dependency directory
27 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
28 | node_modules
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VuePack cli
2 |
3 | Cli tool and generator for [VuePack](https://github.com/egoist/vuepack)
4 |
5 | ## Install
6 |
7 | If you are using Windows you should install UNIX tools brought by Git for Windows.
8 |
9 | ```bash
10 | npm install -g vuepack
11 | ```
12 |
13 | ## Usage
14 |
15 | ```bash
16 | vue init HelloWorld
17 | # for chinese users
18 | vue init HelloWorld --cn
19 | # a specific version of Vuepack
20 | # check out all available versions at
21 | # https://github.com/egoist/vuepack/releases
22 | vue init HelloWorld --tag 0.0.2
23 | # be more verbose
24 | vue init HelloWorld --verbose
25 | # generate a component
26 | vue g/generate component counter
27 | ```
28 |
29 | ## License
30 |
31 | MIT.
32 |
--------------------------------------------------------------------------------
/bin/vuepack:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | global.log = require('typelog')
3 | global.argv = require('minimist')(process.argv.slice(2), { '--': true })
4 | const updateNotifier = require('update-notifier')
5 | const pkg = require('../package')
6 | updateNotifier({ pkg: pkg }).notify()
7 | require('colorful').toxic()
8 |
9 | if (argv.v || argv.version) {
10 | console.log(`${pkg.name.magenta} ~ ${pkg.version.cyan}`)
11 | process.exit()
12 | } else if (argv.h || argv.help) {
13 | console.log(`
14 | ${'VuePack'.white.bold}
15 |
16 | ${'Usages'.underline}:
17 |
18 | -v/--version: Print version
19 | -h/--help: Print docs
20 | -f/--force: Force command
21 | init [name]: Initial a project
22 | g/generate component [name]: Gennerate a component
23 |
24 | `)
25 | process.exit()
26 | }
27 |
28 | require('..')()
29 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const init = require('./lib/init')
2 | const generate = require('./lib/generate')
3 |
4 | module.exports = () => {
5 | switch (argv._[0]) {
6 | case 'init':
7 | return init()
8 | case 'generate':
9 | case 'g':
10 | return generate()
11 | default:
12 | return log.warn('Bad options:', argv._)
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lib/files/component.js:
--------------------------------------------------------------------------------
1 | module.exports = function (cssName) {
2 | return `
3 |
4 |
5 |
6 |
16 | `
17 | }
18 |
--------------------------------------------------------------------------------
/lib/generate.js:
--------------------------------------------------------------------------------
1 | const generateComponent = require('./generateComponent')
2 |
3 | module.exports = function () {
4 | const type = argv._[1]
5 | switch (type) {
6 | case 'component':
7 | return generateComponent()
8 | default:
9 | return
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/lib/generateComponent.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const fs = require('fs')
3 | const exists = require('path-exists')
4 | const mkdirp = require('mkdirp')
5 |
6 | mkdirp.sync(path.join(process.cwd(), 'src/components'))
7 | mkdirp.sync(path.join(process.cwd(), 'src/css'))
8 |
9 | module.exports = function () {
10 | const componentName = argv._[2]
11 | if (!componentName) {
12 | log.error(`You have to specific a ${'component name'.white.bold} first!`)
13 | } else {
14 | const cssPath = join('css', componentName)
15 | const componentPath = join('component', componentName)
16 | const cssPathExists = exists.sync(cssPath)
17 | const componentPathExists = exists.sync(componentPath)
18 | const force = argv.f || argv.force
19 | const forceText = force ? ' force' : ''
20 | if (!force && (cssPathExists || componentPathExists)) {
21 | if (cssPathExists) {
22 | log.error(`${'CSS file'.white.bold} of the ${'Component'.white.bold} exists, use ${'-f/--force'.white.bold} to force create!`)
23 | }
24 | if (componentPathExists) {
25 | log.error(`The ${'Component'.white.bold} exists, use ${'-f/--force'.white.bold} to force create!`)
26 | }
27 | } else {
28 | const componentFile = require('./files/component')(componentName)
29 | const cssFile = ''
30 | fs.writeFileSync(componentPath, componentFile, 'utf-8')
31 | fs.writeFileSync(cssPath, cssFile, 'utf-8')
32 | log.success(`Component ${componentName.white.bold} is${forceText} created!`)
33 | }
34 | }
35 | }
36 |
37 | function join(type, filename) {
38 | var typeDir = type
39 | var ext = '.css'
40 | if (type === 'component') {
41 | typeDir += 's'
42 | ext = '.vue'
43 | }
44 | return path.join(process.cwd(), `src/${typeDir}`, `${filename}${ext}`)
45 | }
46 |
--------------------------------------------------------------------------------
/lib/init.js:
--------------------------------------------------------------------------------
1 | const elegantSpinner = require('elegant-spinner')
2 | const logUpdate = require('log-update')
3 | const frame = elegantSpinner()
4 | const path = require('path')
5 | const fetch = require('node-fetch')
6 | const Download = require('download')
7 | const pathExists = require('path-exists')
8 | const home = require('user-home')
9 | const mkdir = require('mkdirp')
10 | const spawn = require('cross-spawn')
11 | require('shelljs/global')
12 |
13 | function spin (text) {
14 | const frames = ['-', '\\', '|', '/']
15 | var i = 0
16 | setInterval(() => {
17 | const frame = frames[i = ++i % frames.length];
18 |
19 | logUpdate(
20 | `
21 | ♥♥
22 | ${frame} ${text} ${frame}
23 | ♥♥
24 | `
25 | );
26 | }, 80)
27 | }
28 |
29 | module.exports = () => {
30 | const name = argv._[1]
31 | if (!name) {
32 | return log.error('You have to specific the name of your new Vue project!')
33 | }
34 | spin('Processing')
35 | fetch('https://cdn.rawgit.com/egoist/vuepack/master/package.json')
36 | .then(data => data.json())
37 | .then(data => {
38 | const version = argv.tag || data.version
39 | const appFolder = `${home}/.vuepack/vuepack-${version}`
40 | const vueHome = `${home}/.vuepack`
41 | const destFolder = process.cwd() + '/' + name
42 | mkdir.sync(vueHome)
43 | if (!pathExists.sync(appFolder)) {
44 | new Download({mode: '755', extract: true})
45 | .get(`https://github.com/egoist/vuepack/archive/v${version}.tar.gz`)
46 | .dest(vueHome)
47 | .run((err, files) => {
48 | logUpdate.clear()
49 | logUpdate.done()
50 | if (err) {
51 | log.error(err)
52 | process.exit()
53 | }
54 | copyApp()
55 | })
56 | } else {
57 |
58 | logUpdate.clear()
59 | logUpdate.done()
60 | copyApp()
61 | }
62 |
63 | function copyApp () {
64 | const exists = pathExists.sync(destFolder)
65 | if (exists && !argv.f && !argv.force) {
66 | log.error(`Folder ${name} exists, use -f/--force to override it`)
67 | process.exit()
68 | }
69 | if (exists) {
70 | exec('rm -rf ' + destFolder)
71 | }
72 | cp('-R', appFolder, process.cwd())
73 | mv(`vuepack-${version}`, name)
74 | cd(name)
75 | log.info('NPM installing...')
76 | var npmInstall = ['install']
77 | if (argv.cn) {
78 | npmInstall.push('--registry', 'https://registry.npm.taobao.org')
79 | }
80 | if (argv.verbose) {
81 | npmInstall.push('--verbose')
82 | }
83 | spawn.sync('npm', npmInstall, { stdio: 'inherit' })
84 | log.success('Cheers! Let the hacking begin!')
85 | log.info(`Run 'cd ${name} && npm run dev' to start!`)
86 | process.exit()
87 | }
88 | })
89 | }
90 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vuepack",
3 | "version": "0.1.6",
4 | "description": "cli tool for vuepack",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "bin": {
10 | "vue": "./bin/vuepack"
11 | },
12 | "preferGlobal": true,
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/egoist/vuepack-cli.git"
16 | },
17 | "keywords": [
18 | "vuepack",
19 | "vue",
20 | "cli",
21 | "tool"
22 | ],
23 | "author": "EGOIST",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/egoist/vuepack-cli/issues"
27 | },
28 | "homepage": "https://github.com/egoist/vuepack-cli#readme",
29 | "dependencies": {
30 | "colorful": "^2.1.0",
31 | "cross-spawn": "^2.1.0",
32 | "download": "^4.4.1",
33 | "elegant-spinner": "^1.0.1",
34 | "log-update": "^1.0.2",
35 | "minimist": "^1.2.0",
36 | "mkdirp": "^0.5.1",
37 | "node-fetch": "^1.3.3",
38 | "path-exists": "^2.0.0",
39 | "shelljs": "^0.5.3",
40 | "typelog": "^0.1.1",
41 | "update-notifier": "^0.6.0",
42 | "user-home": "^2.0.0"
43 | },
44 | "engine": {
45 | "node": ">= 4.0.0"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------