import * as execa from "execa" ; import { existsSync } from "fs" ; import path from "path" ; import * as semver from "semver" ; import updateNotifier from "update-notifier" ; returns export function updateNotify ( ) { const pkg = require ( "../../package.json" ) ; const notifier = updateNotifier ( { pkg , updateCheckInterval : 1000 * 60 * 60 , } ) ; notifier . notify ( ) ; return pkg . version ; } /**
 * Call this to check if we match the engine policy
 */ export function checkEngineStrict ( ) { const pkg = require ( "../../package.json" ) ; const minNodeVersion = pkg ?. engines ?. node ; if ( ! ! minNodeVersion && ! semver . satisfies ( process . version , minNodeVersion ) ) { console . error ( `create-plasmic-app only works on Node ${ minNodeVersion }` ) ; return false ; } return true ; } param cmd param workingDir returns export async function spawn ( cmd , workingDir ? ) { console . log ( cmd ) ; const cp = await execa . command ( cmd , { shell : true , stdio : "inherit" , cwd : workingDir , } ) ; return cp . exitCode === 0 ; } param pkg param opts returns export async function installUpgrade ( pkg , opts = { } ) { const cmd = installCommand ( pkg , opts ) ; const r = await spawn ( cmd , opts . workingDir ) ; if ( r ) { console . log ( `Successfully added ${ pkg } dependency.` ) ; return true ; } else { console . warn ( `Cannot add ${ pkg } to your project dependencies. Please add it manually.` ) ; return false ; } } param pkg param opts returns function installCommand ( pkg , opts = { } ) { const mgr = detectPackageManager ( opts . workingDir ) ; if ( mgr === "yarn" ) { if ( opts . global ) { return `yarn global add ${ pkg }` ; } else if ( opts . dev ) { return `yarn add --dev --ignore-scripts -W ${ pkg }` ; } else { return `yarn add --ignore-scripts -W ${ pkg }` ; } } else { if ( opts . global ) { return `npm install -g ${ pkg }` ; } else if ( opts . dev ) { return `npm install --save-dev --ignore-scripts ${ pkg }` ; } else { return `npm install --ignore-scripts ${ pkg }` ; } } } param dir returns export function detectPackageManager ( dir ? ) { const yarnLock = existsSync ( path . join ( dir ? dir : "" , "yarn.lock" ) ) ; if ( yarnLock ) { return "yarn" ; } else { return "npm" ; } }