import { JSONSchemaForNPMPackageJsonFiles as PackageJson } from "@schemastore/package" ; import chalk from "chalk" ; import * as fs from "fs" ; import globalModules from "global-modules" ; import * as logger from "../utils/logger" ; function printHostingInstructions ( appPackage , publicUrl , publicPath , buildFolder , useYarn ) { if ( publicUrl && publicUrl . includes ( ".github.io/" ) ) { const publicPathname = new URL ( publicPath ) . pathname ; const hasDeployScript = typeof appPackage . scripts !== "undefined" && typeof appPackage . scripts . deploy !== "undefined" ; printBaseMessage ( buildFolder , publicPathname ) ; printDeployInstructions ( publicUrl , hasDeployScript , useYarn ) ; } else if ( publicPath !== "/" ) { printBaseMessage ( buildFolder , publicPath ) ; } else { printBaseMessage ( buildFolder , publicUrl ) ; printStaticServerInstructions ( buildFolder , useYarn ) ; } logger . log ( ) ; logger . log ( "Find out more about deployment here:" ) ; logger . log ( ) ; logger . log ( `  ${ chalk . yellow ( "https://cra.link/deployment" ) }` ) ; logger . log ( ) ; } function printBaseMessage ( buildFolder , hostingLocation ) { logger . log ( `The project was built assuming it is hosted at ${ chalk . green ( hostingLocation || "the server root" ) }.` ) ; logger . log ( `You can control this with the ${ chalk . green ( "homepage" ) } field in your ${ chalk . cyan ( "package.json" ) }.` ) ; if ( ! hostingLocation ) { logger . log ( "For example, add this to build it for GitHub Pages:" ) ; logger . log ( ) ; logger . log ( `  ${ chalk . green ( '"homepage"' ) } ${ chalk . cyan ( ":" ) } ${ chalk . green ( '"http://myname.github.io/myapp"' ) }${ chalk . cyan ( "," ) }` ) ; } logger . log ( ) ; logger . log ( `The ${ chalk . cyan ( buildFolder ) } folder is ready to be deployed.` ) ; } function printDeployInstructions ( publicUrl , hasDeployScript , useYarn ) { logger . log ( `To publish it at ${ chalk . green ( publicUrl ) } , run:` ) ; logger . log ( ) ; if ( ! hasDeployScript ) { if ( useYarn ) { logger . log ( `  ${ chalk . cyan ( "yarn" ) } add --dev gh-pages` ) ; } else { logger . log ( `  ${ chalk . cyan ( "npm" ) } install --save-dev gh-pages` ) ; } logger . log ( ) ; logger . log ( `Add the following script in your ${ chalk . cyan ( "package.json" ) }.` ) ; logger . log ( ) ; logger . log ( `    ${ chalk . dim ( "// ..." ) }` ) ; logger . log ( `    ${ chalk . yellow ( '"scripts"' ) }: {` ) ; logger . log ( `      ${ chalk . dim ( "// ..." ) }` ) ; logger . log ( `      ${ chalk . yellow ( '"predeploy"' ) }: ${ chalk . yellow ( `"${ useYarn ? "yarn" : "npm run" } build",` ) }` ) ; logger . log ( `      ${ chalk . yellow ( '"deploy"' ) }: ${ chalk . yellow ( '"gh-pages -d build"' ) }` ) ; logger . log ( "    }" ) ; logger . log ( ) ; logger . log ( "Then run:" ) ; logger . log ( ) ; } logger . log ( `  ${ chalk . cyan ( useYarn ? "yarn" : "npm" ) } run deploy` ) ; } function printStaticServerInstructions ( buildFolder , useYarn ) { logger . log ( "You may serve it with a static server:" ) ; logger . log ( ) ; if ( ! fs . existsSync ( `${ globalModules }/serve` ) ) { if ( useYarn ) { logger . log ( `  ${ chalk . cyan ( "yarn" ) } global add serve` ) ; } else { logger . log ( `  ${ chalk . cyan ( "npm" ) } install -g serve` ) ; } } logger . log ( `  ${ chalk . cyan ( "serve" ) } -s ${ buildFolder }` ) ; } export default printHostingInstructions ;