@@ -7,8 +7,14 @@ import { program } from 'commander';
77import inquirer from 'inquirer' ;
88import tildify from 'tildify' ;
99import { cloneTemplateIn } from './template' ;
10- import { detectManager , exec , normalizeOptions , isContentfulTemplate } from './utils' ;
11- import { CLIOptions } from './types' ;
10+ import {
11+ detectActivePackageManager ,
12+ getNormalizedPackageManager ,
13+ exec ,
14+ normalizeOptions ,
15+ isContentfulTemplate ,
16+ } from './utils' ;
17+ import type { CLIOptions , PackageManager } from './types' ;
1218import { code , error , highlight , success , warn , wrapInBlanks } from './logger' ;
1319import chalk from 'chalk' ;
1420import { CREATE_APP_DEFINITION_GUIDE_URL , EXAMPLES_REPO_URL } from './constants' ;
@@ -19,7 +25,15 @@ import fs from 'fs';
1925
2026const DEFAULT_APP_NAME = 'contentful-app' ;
2127
22- function successMessage ( folder : string , useYarn : boolean ) {
28+ function successMessage ( folder : string , packageManager : PackageManager ) {
29+ let command = '' ;
30+ if ( packageManager === 'yarn' ) {
31+ command = 'yarn create-app-definition' ;
32+ } else if ( packageManager === 'pnpm' ) {
33+ command = 'pnpm create-app-definition' ;
34+ } else {
35+ command = 'npm run create-app-definition' ;
36+ }
2337 console . log ( `
2438${ success ( 'Success!' ) } Created a new Contentful app in ${ highlight ( tildify ( folder ) ) } .`) ;
2539
@@ -28,7 +42,7 @@ ${success('Success!')} Created a new Contentful app in ${highlight(tildify(folde
2842 console . log ( `Now create an app definition for your app by running
2943
3044 ${ code ( `cd ${ tildify ( folder ) } ` ) }
31- ${ code ( useYarn ? 'yarn create-app-definition' : 'npm run create-app-definition' ) }
45+ ${ code ( command ) }
3246
3347 or you can create it manually in web app:
3448 ${ highlight ( CREATE_APP_DEFINITION_GUIDE_URL ) }
@@ -37,7 +51,7 @@ ${success('Success!')} Created a new Contentful app in ${highlight(tildify(folde
3751 console . log ( `Then kick it off by running
3852
3953 ${ code ( `cd ${ tildify ( folder ) } ` ) }
40- ${ code ( `${ useYarn ? 'yarn' : 'npm' } start` ) }
54+ ${ code ( `${ packageManager } start` ) }
4155 ` ) ;
4256}
4357
@@ -100,6 +114,9 @@ async function validateAppName(appName: string): Promise<string> {
100114
101115async function initProject ( appName : string , options : CLIOptions ) {
102116 const normalizedOptions = normalizeOptions ( options ) ;
117+ const activePackageManager = detectActivePackageManager ( ) ;
118+ const packageManager = getNormalizedPackageManager ( normalizedOptions , activePackageManager ) ;
119+
103120 try {
104121 appName = await validateAppName ( appName ) ;
105122
@@ -115,28 +132,28 @@ async function initProject(appName: string, options: CLIOptions) {
115132
116133 updatePackageName ( fullAppFolder ) ;
117134
118- const useYarn = normalizedOptions . yarn || detectManager ( ) === 'yarn' ;
119-
120135 wrapInBlanks (
121136 highlight (
122- `---- Installing the dependencies for your app (using ${ chalk . cyan (
123- useYarn ? 'yarn' : 'npm'
124- ) } )...`
137+ `---- Installing the dependencies for your app (using ${ chalk . cyan ( packageManager ) } )...`
125138 )
126139 ) ;
127- if ( useYarn ) {
140+
141+ if ( packageManager === 'yarn' ) {
128142 await exec ( 'yarn' , [ ] , { cwd : fullAppFolder } ) ;
143+ } else if ( packageManager === 'pnpm' ) {
144+ await exec ( 'pnpm' , [ 'install' ] , { cwd : fullAppFolder } ) ;
129145 } else {
130146 await exec ( 'npm' , [ 'install' , '--no-audit' , '--no-fund' ] , { cwd : fullAppFolder } ) ;
131147 }
132- successMessage ( fullAppFolder , useYarn ) ;
148+ successMessage ( fullAppFolder , packageManager ) ;
133149 } catch ( err ) {
134150 error ( `Failed to create ${ highlight ( chalk . cyan ( appName ) ) } ` , err ) ;
135151 process . exit ( 1 ) ;
136152 }
137153
138154 async function addAppExample ( fullAppFolder : string ) {
139- const isInteractive = ! normalizedOptions . example &&
155+ const isInteractive =
156+ ! normalizedOptions . example &&
140157 ! normalizedOptions . source &&
141158 ! normalizedOptions . javascript &&
142159 ! normalizedOptions . typescript &&
@@ -146,7 +163,7 @@ async function initProject(appName: string, options: CLIOptions) {
146163
147164 track ( {
148165 template : templateSource ,
149- manager : normalizedOptions . npm ? 'npm' : 'yarn' ,
166+ manager : packageManager ,
150167 interactive : isInteractive ,
151168 } ) ;
152169
@@ -163,7 +180,7 @@ async function initProject(appName: string, options: CLIOptions) {
163180 }
164181
165182 async function addFunctionTemplate ( fullAppFolder : string ) {
166- if ( ! fs . existsSync ( fullAppFolder ) ) {
183+ if ( ! fs . existsSync ( fullAppFolder ) ) {
167184 fs . mkdirSync ( fullAppFolder , { recursive : true } ) ;
168185 }
169186
@@ -188,7 +205,7 @@ async function initProject(appName: string, options: CLIOptions) {
188205 example : normalizedOptions . function ,
189206 language : normalizedOptions . javascript ? 'javascript' : 'typescript' ,
190207 name : functionName ,
191- keepPackageJson : normalizedOptions . skipUi === true
208+ keepPackageJson : normalizedOptions . skipUi === true ,
192209 } as any ) ;
193210 }
194211}
@@ -212,6 +229,7 @@ async function initProject(appName: string, options: CLIOptions) {
212229 )
213230 . argument ( '[app-name]' , 'app name' )
214231 . option ( '--npm' , 'use npm' )
232+ . option ( '--pnpm' , 'use pnpm' )
215233 . option ( '--yarn' , 'use Yarn' )
216234 . option ( '-ts, --typescript' , 'use TypeScript template (default)' )
217235 . option ( '-js, --javascript' , 'use JavaScript template' )
0 commit comments