@@ -21,18 +21,19 @@ import {
2121 flags ,
2222 HttpClient ,
2323 configHandler ,
24- FlagInput
24+ FlagInput ,
2525} from "@contentstack/cli-utilities" ;
2626
2727import { BaseCommand } from "../../base-command" ;
28- import { AppManifest , AppType } from "../../types" ;
28+ import { AppManifest , AppType , BoilerplateAppType } from "../../types" ;
2929import { appCreate , commonMsg } from "../../messages" ;
3030import {
3131 getOrg ,
3232 getAppName ,
3333 getDirName ,
3434 getOrgAppUiLocation ,
35- sanitizePath
35+ sanitizePath ,
36+ selectedBoilerplate ,
3637} from "../../util" ;
3738
3839export default class Create extends BaseCommand < typeof Create > {
@@ -96,7 +97,18 @@ export default class Create extends BaseCommand<typeof Create> {
9697 message : this . messages . CONFIRM_CLONE_BOILERPLATE ,
9798 } ) )
9899 ) {
99- await this . boilerplateFlow ( ) ;
100+ const boilerplate : BoilerplateAppType = await selectedBoilerplate ( ) ;
101+
102+ if ( boilerplate ) {
103+ this . sharedConfig . boilerplateName = boilerplate . name
104+ . toLowerCase ( )
105+ . replace ( / / g, "-" ) ;
106+ this . sharedConfig . appBoilerplateGithubUrl = boilerplate . link ;
107+ this . sharedConfig . appName = await getAppName (
108+ this . sharedConfig . boilerplateName
109+ ) ;
110+ await this . boilerplateFlow ( ) ;
111+ }
100112 } else {
101113 this . manageManifestToggeling ( ) ;
102114 await this . registerTheAppOnDeveloperHub ( false ) ;
@@ -198,7 +210,11 @@ export default class Create extends BaseCommand<typeof Create> {
198210 const zip = new AdmZip ( filepath ) ;
199211 const dataDir = this . flags [ "data-dir" ] ?? process . cwd ( ) ;
200212 let targetPath = resolve ( dataDir , this . sharedConfig . appName ) ;
201- const sourcePath = resolve ( dataDir , this . sharedConfig . boilerplateName ) ;
213+
214+ // Get the directory inside the zip file
215+ const zipEntries = zip . getEntries ( ) ;
216+ const firstEntry = zipEntries [ 0 ] ;
217+ const sourcePath = resolve ( dataDir , firstEntry . entryName . split ( "/" ) [ 0 ] ) ;
202218
203219 if ( this . flags [ "data-dir" ] && ! existsSync ( this . flags [ "data-dir" ] ) ) {
204220 mkdirSync ( this . flags [ "data-dir" ] , { recursive : true } ) ;
@@ -235,10 +251,7 @@ export default class Create extends BaseCommand<typeof Create> {
235251 */
236252 manageManifestToggeling ( ) {
237253 // NOTE Use boilerplate manifest if exist
238- const manifestPath = resolve (
239- this . sharedConfig . folderPath || "" ,
240- "manifest.json"
241- ) ;
254+ const manifestPath = resolve ( this . sharedConfig . folderPath , "manifest.json" ) ;
242255
243256 if ( existsSync ( manifestPath ) ) {
244257 this . sharedConfig . manifestPath = manifestPath ;
@@ -301,7 +314,10 @@ export default class Create extends BaseCommand<typeof Create> {
301314 this . appData = merge ( this . appData , pick ( response , validKeys ) ) ;
302315 if ( saveManifest ) {
303316 writeFileSync (
304- resolve ( this . sharedConfig . folderPath , "manifest.json" ) ,
317+ resolve (
318+ this . sharedConfig . folderPath ,
319+ "manifest.json"
320+ ) ,
305321 JSON . stringify ( this . appData ) ,
306322 {
307323 encoding : "utf8" ,
0 commit comments