@@ -61,7 +61,7 @@ func (c *DeployCmd) Run(ctx *kong.Context, logWriters *LogWriters) (err error) {
6161 }
6262 }
6363
64- log .Info ().Msg (Green ("Deploying your node.js package to Account ID: %d, App ID: %d, Environment %s" ,c .AccountID , c .AppID , c .Environment ))
64+ log .Info ().Msg (Green ("Deploying your node.js package to Account ID: %d, App ID: %d, Environment %s" , c .AccountID , c .AppID , c .Environment ))
6565 if ! c .SkipValidation {
6666 errs := IsValidNodeApp (dir )
6767 if len (errs ) > 0 {
@@ -86,7 +86,7 @@ func (c *DeployCmd) Run(ctx *kong.Context, logWriters *LogWriters) (err error) {
8686 s .Stop ()
8787 log .Debug ().Msg ("Archiving files:" )
8888 for _ , file := range files {
89- log .Debug ().Str ("file" ,file )
89+ log .Debug ().Str ("file" , file )
9090 }
9191
9292 tempFile , err := ioutil .TempFile ("" , "sectionctl-deploy.*.tar.gz" )
@@ -130,11 +130,11 @@ func (c *DeployCmd) Run(ctx *kong.Context, logWriters *LogWriters) (err error) {
130130
131131 req .Header .Add ("section-token" , api .Token )
132132
133- log .Debug ().Str ("URL" ,req .URL .String ())
133+ log .Debug ().Str ("URL" , req .URL .String ())
134134
135135 artifactSizeMB := stat .Size () / 1024 / 1024
136136 log .Debug ().Msg (fmt .Sprintf ("Upload artifact is %dMB (%d bytes) large" , artifactSizeMB , stat .Size ()))
137- s = NewSpinner (fmt .Sprintf ("Uploading app (%dMB)..." , artifactSizeMB ),logWriters )
137+ s = NewSpinner (fmt .Sprintf ("Uploading app (%dMB)..." , artifactSizeMB ), logWriters )
138138 s .Start ()
139139 client := & http.Client {
140140 Timeout : c .Timeout ,
@@ -171,9 +171,24 @@ func (c *DeployCmd) Run(ctx *kong.Context, logWriters *LogWriters) (err error) {
171171// IsValidNodeApp detects if a Node.js app is present in a given directory
172172func IsValidNodeApp (dir string ) (errs []error ) {
173173 packageJSONPath := filepath .Join (dir , "package.json" )
174- if _ , err := os .Stat (packageJSONPath ); os .IsNotExist (err ) {
175- errs = append (errs , fmt .Errorf ("%s is not a file" , packageJSONPath ))
174+ if packageJSONContents , err := ioutil .ReadFile (packageJSONPath ); err != nil {
175+ if os .IsNotExist (err ) {
176+ log .Debug ().Msg (fmt .Sprintf ("[WARN] %s is not a file" , packageJSONPath ))
177+ } else {
178+ log .Info ().Err (err ).Msg ("Error reading your package.json" )
179+ }
180+ } else {
181+ packageJSON , err := ParsePackageJSON (string (packageJSONContents ))
182+ if err != nil {
183+ log .Info ().Err (err ).Msg ("Error parsing your package.json" )
184+ }
185+ if len (packageJSON .Section .StartScript ) == 0 && packageJSON .Scripts ["start" ] == "" {
186+ errs = append (errs , fmt .Errorf ("package.json does not include a start script. please add one" ))
187+ } else if len (packageJSON .Section .StartScript ) > 0 && len (packageJSON .Scripts [packageJSON .Section .StartScript ]) == 0 {
188+ errs = append (errs , fmt .Errorf ("package.json does not include the script: %s" , packageJSON .Section .StartScript ))
189+ }
176190 }
191+
177192 nodeModulesPath := filepath .Join (dir , "node_modules" )
178193 fi , err := os .Stat (nodeModulesPath )
179194 if os .IsNotExist (err ) {
0 commit comments