@@ -12,8 +12,9 @@ const config = require('../config.js')
1212const path = require ( 'path' )
1313
1414const validateGeneratedArtifacts = async ( project ) => {
15- const generatedProjectDirPath = path . join ( process . cwd ( ) , config . GENERATED_PROJECTS_DIR , project )
16- const generatedArtifacts = await fs . readdirSync ( generatedProjectDirPath )
15+ try {
16+ const generatedProjectDirPath = path . join ( process . cwd ( ) , config . GENERATED_PROJECTS_DIR , project )
17+ const generatedArtifacts = fs . readdirSync ( generatedProjectDirPath )
1718
1819 return new Promise ( ( resolve , reject ) => {
1920 const missingArtifacts = diffArrays (
@@ -25,31 +26,40 @@ const validateGeneratedArtifacts = async (project) => {
2526 `Generated project (${ project } ) is missing one or more artifacts: ${ missingArtifacts } `
2627 )
2728 } else {
28- resolve ( `Successfully validated generated artifacts for: ${ project } ` )
29- }
30- } )
29+ resolve ( `Successfully validated generated artifacts for: ${ project } ` )
30+ }
31+ } )
32+ } catch ( err ) {
33+ reject ( `Generated project (${ project } ) is missing one or more artifacts: ${ err } ` )
34+ }
3135}
3236
33- const validateExtensibilityConfig = async ( project ) => {
37+ const validateExtensibilityConfig = async ( project , templateVersion ) => {
3438 const pkgPath = path . join ( process . cwd ( ) , config . GENERATED_PROJECTS_DIR , project , 'package.json' )
3539 const pkg = require ( pkgPath )
3640 return new Promise ( ( resolve , reject ) => {
3741 if (
38- pkg . hasOwnProperty ( 'ccExtensibility' ) &&
39- pkg [ 'ccExtensibility' ] . hasOwnProperty ( 'extends' ) &&
40- pkg [ 'ccExtensibility' ] . hasOwnProperty ( 'overridesDir' ) &&
41- pkg [ 'ccExtensibility' ] . extends === '@salesforce/retail-react-app' &&
42- pkg [ 'ccExtensibility' ] . overridesDir === 'overrides'
42+ ! pkg . hasOwnProperty ( 'ccExtensibility' ) ||
43+ ! pkg [ 'ccExtensibility' ] . hasOwnProperty ( 'extends' ) ||
44+ ! pkg [ 'ccExtensibility' ] . hasOwnProperty ( 'overridesDir' ) ||
45+ ! pkg [ 'ccExtensibility' ] . extends === '@salesforce/retail-react-app' ||
46+ ! pkg [ 'ccExtensibility' ] . overridesDir === 'overrides'
4347 ) {
44- resolve ( `Successfully validated extensibility config for ${ project } `)
48+ reject ( `Generated project ${ project } is missing extensibility config in package.json `)
4549 }
46- reject ( `Generated project ${ project } is missing extensibility config in package.json` )
50+
51+ if ( templateVersion && pkg . version !== templateVersion ) {
52+ reject (
53+ `Generated project ${ project } is using an incorrect template version. Expected ${ templateVersion } , but got ${ pkg . version } .`
54+ )
55+ }
56+ resolve ( `Successfully validated extensibility config for ${ project } ` )
4757 } )
4858}
4959
5060const main = async ( opts ) => {
5161 const { args} = opts
52- const [ project ] = args
62+ const [ project , templateVersion ] = args
5363 if ( opts . args . length !== 1 ) {
5464 console . log ( program . helpInformation ( ) )
5565 process . exit ( 1 )
@@ -58,22 +68,24 @@ const main = async (opts) => {
5868 try {
5969 console . log ( await validateGeneratedArtifacts ( project ) )
6070 if ( project === 'retail-app-ext' || project === 'retail-app-ext' ) {
61- console . log ( await validateExtensibilityConfig ( project ) )
71+ console . log ( await validateExtensibilityConfig ( project , templateVersion ) )
6272 }
6373 } catch ( err ) {
6474 console . error ( err )
6575 }
6676}
6777
68- program . description ( `Validate project generated by generator using the key <project-key>` )
69-
70- program . addArgument (
71- new Argument ( '<project-key>' , 'project key' ) . choices ( [
72- 'retail-app-demo' ,
73- 'retail-app-ext' ,
74- 'retail-app-no-ext'
75- ] )
76- )
78+ program
79+ . description ( `Validate project generated by generator using the key <project-key>` )
80+ . addArgument (
81+ new Argument ( '<project-key>' , 'project key' ) . choices ( [
82+ 'retail-app-demo' ,
83+ 'retail-app-ext' ,
84+ 'retail-app-no-ext' ,
85+ 'retail-app-private-client'
86+ ] )
87+ )
88+ . option ( '--templateVersion <templateVersion>' , 'Template version used to generate the project' )
7789
7890program . parse ( process . argv )
7991
0 commit comments