Skip to content

Commit

Permalink
adjust setup
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 27, 2017
1 parent 1de71c5 commit c263967
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 91 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
## Development Setup

This project uses a monorepo setup that requires [Lerna](https://github.com/lerna/lerna) and [Yarn](https://yarnpkg.com).
This project uses a monorepo setup that requires using [Yarn](https://yarnpkg.com) because it relies on [Yarn workspaces](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/).

``` sh
# install root dependencies
# install dependencies
yarn

# bootstrap packages
lerna bootstrap

# link `vue` executable
cd packages/@vue/cli
yarn link

# create a test project in /packages
# note the name must be "test" so that dependencies can be linked properly
# create test projects in /packages/test
cd -
cd packages
vue create test
cd test
cd packages/test
vue create test-app
cd test-app
yarn
yarn dev
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"private": true,
"workspaces": [
"packages/test",
"packages/@vue/*"
"packages/@vue/*",
"packages/test/*"
],
"scripts": {
"lint": "eslint --fix packages/**/*.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/util/resolveClientEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function resolveClientEnv () {

// TODO load .env files

const env = { NODE_ENV }
const env = { NODE_ENV: JSON.stringify(NODE_ENV) }
Object.keys(process.env).forEach(key => {
if (prefixRE.test(key)) {
env[key] = JSON.stringify(process.env[key])
Expand Down
27 changes: 16 additions & 11 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ const debug = require('debug')
const rcPath = path.join(os.homedir(), '.vuerc')
const isMode = _mode => ({ mode }) => _mode === mode

const hasYarn = (() => {
try {
execSync('yarnpkg --version', { stdio: 'ignore' })
return true
} catch (e) {
return false
}
})()

const defaultOptions = {
features: ['eslint', 'unit'],
eslint: 'eslint-only',
unit: 'mocha',
assertionLibrary: 'chai'
assertionLibrary: 'chai',
packageManager: hasYarn ? 'yarn' : 'npm'
}

module.exports = class Creator {
Expand Down Expand Up @@ -79,6 +89,10 @@ module.exports = class Creator {
this.files['package.json'] = JSON.stringify(this.pkg, null, 2)
// write file tree to disk
await writeFileTree(path, this.files)

if (options.packageManager) {
// TODO install deps
}
}

resolveIntroPrompts () {
Expand Down Expand Up @@ -125,7 +139,7 @@ module.exports = class Creator {
message: 'Save the preferences for future projects?'
}
]
if (hasYarn()) {
if (hasYarn) {
outroPrompts.unshift({
name: 'packageManager',
when: isMode('manual'),
Expand Down Expand Up @@ -220,12 +234,3 @@ module.exports = class Creator {
debug('files')(this.files)
}
}

function hasYarn () {
try {
execSync('yarnpkg --version', { stdio: 'ignore' })
return true
} catch (e) {
return false
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallow } from 'vue-test-utils'
<%_ if (options.assertionLibrary === 'expect') { _%>
<%_ if (options.assertionLibrary === 'expect' && options.unit !== 'jest') { _%>
import { expect } from 'expect'
<%_ } _%>
<%_ if (options.assertionLibrary === 'chai') { _%>
Expand All @@ -13,7 +13,7 @@ describe('Hello.vue', () => {
const wrapper = shallow(HelloWorld, {
context: { props: { msg } }
})
<%_ if (options.assertionLibrary === 'expect') { _%>
<%_ if (options.assertionLibrary === 'expect' || options.unit === 'jest') { _%>
expect(wrapper.text()).toBe(msg)
<%_ } else if (options.assertionLibrary === 'chai') { _%>
expect(wrapper.text()).to.equal(msg)
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli/lib/generators/unit/jest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = (api, options) => {
options.assertionLibrary = 'expect'
api.renderFiles('./files')
api.extendPackage({
scripts: {
Expand Down
Empty file added packages/test/.gitkeep
Empty file.
Loading

0 comments on commit c263967

Please sign in to comment.