Skip to content

Commit

Permalink
fix(generator): ENOENT error
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 19, 2019
1 parent 1b2a90c commit a792f58
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ module.exports = (api, options, rootOptions) => {
api.onCreateComplete(async () => {
const execa = require('execa')

function run (program, args) {
return execa(program, args, {
preferLocal: true,
})
}

if (options.addExamples) {
const appPath = api.resolve('src/App.vue')
if (fs.existsSync(appPath)) {
Expand Down Expand Up @@ -139,7 +145,7 @@ module.exports = (api, options, rootOptions) => {
}
}

await execa('vue-cli-service', [
await run('vue-cli-service', [
'apollo:schema:generate',
])
}
Expand Down Expand Up @@ -184,47 +190,9 @@ module.exports = (api, options, rootOptions) => {
}
}

// Linting
if (api.hasPlugin('eslint')) {
// ESlint ignore
if (options.addServer) {
const filePath = api.resolve('.eslintignore')
let content

if (fs.existsSync(filePath)) {
content = fs.readFileSync(filePath, { encoding: 'utf8' })
} else {
content = ''
}

if (content.indexOf('schema.graphql') === -1) {
content += '\nschema.graphql\n'

fs.writeFileSync(filePath, content, { encoding: 'utf8' })
}
}

// Lint generated/modified files
try {
const files = ['*.js', '.*.js', 'src']
if (api.hasPlugin('apollo')) {
files.push('apollo-server')
}
execa.sync('vue-cli-service lint', [
'--silent',
...files,
], {
cleanup: true,
shell: true,
})
} catch (e) {
// No ESLint vue-cli plugin
}
}

// Schema publish
if (options.publishSchema) {
await execa('vue-cli-service', [
await run('vue-cli-service', [
'apollo:schema:publish',
])
}
Expand Down

0 comments on commit a792f58

Please sign in to comment.