@@ -8,9 +8,36 @@ const babelPlugin = toPlugin('@vue/cli-plugin-babel')
8
8
const eslintPlugin = toPlugin ( '@vue/cli-plugin-eslint' )
9
9
const globalConfigPlugin = require ( './lib/globalConfigPlugin' )
10
10
11
- function resolveEntry ( entry ) {
12
- const context = process . cwd ( )
11
+ const context = process . cwd ( )
13
12
13
+ function warnAboutNpmScript ( cmd ) {
14
+ const packageJsonPath = path . join ( context , 'package.json' )
15
+
16
+ if ( ! fs . existsSync ( packageJsonPath ) ) {
17
+ return
18
+ }
19
+
20
+ let pkg
21
+ try {
22
+ pkg = require ( packageJsonPath )
23
+ } catch ( e ) {
24
+ return
25
+ }
26
+
27
+ if ( ! pkg . scripts || ! pkg . scripts [ cmd ] ) {
28
+ return
29
+ }
30
+
31
+ let script = `npm run ${ cmd } `
32
+ if ( fs . existsSync ( path . join ( context , 'yarn.lock' ) ) ) {
33
+ script = `yarn ${ cmd } `
34
+ }
35
+
36
+ console . log ( `There's a ${ chalk . yellow ( 'package.json' ) } in the current directory.` )
37
+ console . log ( `Did you mean ${ chalk . yellow ( script ) } ?` )
38
+ }
39
+
40
+ function resolveEntry ( entry , cmd ) {
14
41
entry = entry || findExisting ( context , [
15
42
'main.js' ,
16
43
'index.js' ,
@@ -21,14 +48,21 @@ function resolveEntry (entry) {
21
48
if ( ! entry ) {
22
49
console . log ( chalk . red ( `Failed to locate entry file in ${ chalk . yellow ( context ) } .` ) )
23
50
console . log ( chalk . red ( `Valid entry file should be one of: main.js, index.js, App.vue or app.vue.` ) )
51
+
52
+ console . log ( )
53
+ warnAboutNpmScript ( cmd )
24
54
process . exit ( 1 )
25
55
}
26
56
27
57
if ( ! fs . existsSync ( path . join ( context , entry ) ) ) {
28
58
console . log ( chalk . red ( `Entry file ${ chalk . yellow ( entry ) } does not exist.` ) )
59
+
60
+ console . log ( )
61
+ warnAboutNpmScript ( cmd )
29
62
process . exit ( 1 )
30
63
}
31
64
65
+ warnAboutNpmScript ( cmd )
32
66
return {
33
67
context,
34
68
entry
@@ -50,12 +84,12 @@ function createService (context, entry, asLib) {
50
84
}
51
85
52
86
exports . serve = ( _entry , args ) => {
53
- const { context, entry } = resolveEntry ( _entry )
87
+ const { context, entry } = resolveEntry ( _entry , 'serve' )
54
88
createService ( context , entry ) . run ( 'serve' , args )
55
89
}
56
90
57
91
exports . build = ( _entry , args ) => {
58
- const { context, entry } = resolveEntry ( _entry )
92
+ const { context, entry } = resolveEntry ( _entry , 'build' )
59
93
const asLib = args . target && args . target !== 'app'
60
94
if ( asLib ) {
61
95
args . entry = entry
0 commit comments