-
Notifications
You must be signed in to change notification settings - Fork 918
feat: add React logo and spinners to make init
UI nicer
#292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
090be77
7bd4bab
8c6895e
87ff7fb
333b371
1324484
ce3d2e3
45cf422
47679a0
c012f4d
5a587d5
da844c5
f544d9d
8280944
b972cf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @flow | ||
import chalk from 'chalk'; | ||
|
||
const reactLogoArray = [ | ||
' ', | ||
' ###### ###### ', | ||
' ### #### #### ### ', | ||
' ## ### ### ## ', | ||
' ## #### ## ', | ||
' ## #### ## ', | ||
' ## ## ## ## ', | ||
' ## ### ### ## ', | ||
' ## ######################## ## ', | ||
' ###### ### ### ###### ', | ||
' ### ## ## ## ## ### ', | ||
' ### ## ### #### ### ## ### ', | ||
' ## #### ######## #### ## ', | ||
' ## ### ########## ### ## ', | ||
' ## #### ######## #### ## ', | ||
' ### ## ### #### ### ## ### ', | ||
' ### ## ## ## ## ### ', | ||
' ###### ### ### ###### ', | ||
' ## ######################## ## ', | ||
' ## ### ### ## ', | ||
' ## ## ## ## ', | ||
' ## #### ## ', | ||
' ## #### ## ', | ||
' ## ### ### ## ', | ||
' ### #### #### ### ', | ||
' ###### ###### ', | ||
' ', | ||
]; | ||
|
||
const welcomeMessage = | ||
' Welcome to React Native! '; | ||
const learnOnceMessage = | ||
' Learn Once Write Anywhere '; | ||
|
||
export default `${chalk.blue(reactLogoArray.join('\n'))} | ||
|
||
${chalk.yellow.bold(welcomeMessage)} | ||
${chalk.gray(learnOnceMessage)} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ import { | |
executePostInitScript, | ||
} from './template'; | ||
import {changePlaceholderInTemplate} from './editTemplate'; | ||
import * as PackageManager from '../../tools/PackageManager'; | ||
import * as PackageManager from '../../tools/packageManager'; | ||
import {processTemplateName} from './templateName'; | ||
import banner from './banner'; | ||
import {getLoader} from '../../tools/loader'; | ||
|
||
type Options = {| | ||
template?: string, | ||
|
@@ -39,50 +41,99 @@ async function createFromExternalTemplate( | |
templateName: string, | ||
npm?: boolean, | ||
) { | ||
logger.info('Initializing new project from external template'); | ||
logger.debug('Initializing new project from external template'); | ||
logger.log(banner); | ||
|
||
let {uri, name} = await processTemplateName(templateName); | ||
const Loader = getLoader(); | ||
|
||
installTemplatePackage(uri, npm); | ||
name = adjustNameIfUrl(name); | ||
const templateConfig = getTemplateConfig(name); | ||
copyTemplate(name, templateConfig.templateDir); | ||
changePlaceholderInTemplate(projectName, templateConfig.placeholderName); | ||
const loader = new Loader({text: 'Downloading template'}); | ||
loader.start(); | ||
|
||
if (templateConfig.postInitScript) { | ||
executePostInitScript(name, templateConfig.postInitScript); | ||
} | ||
try { | ||
let {uri, name} = await processTemplateName(templateName); | ||
|
||
await installTemplatePackage(uri, npm); | ||
loader.succeed(); | ||
loader.start('Copying template'); | ||
|
||
name = adjustNameIfUrl(name); | ||
const templateConfig = getTemplateConfig(name); | ||
copyTemplate(name, templateConfig.templateDir); | ||
|
||
loader.succeed(); | ||
loader.start('Preparing template'); | ||
|
||
PackageManager.installAll({preferYarn: !npm}); | ||
changePlaceholderInTemplate(projectName, templateConfig.placeholderName); | ||
|
||
loader.succeed(); | ||
const {postInitScript} = templateConfig; | ||
if (postInitScript) { | ||
// Leaving trailing space because there may be stdout from the script | ||
loader.start('Executing post init script '); | ||
await executePostInitScript(name, postInitScript); | ||
loader.succeed(); | ||
} | ||
|
||
loader.start('Installing all required dependencies'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both sound good :P |
||
await PackageManager.installAll({preferYarn: !npm, silent: true}); | ||
loader.succeed(); | ||
} catch (e) { | ||
loader.fail(); | ||
throw new Error(e); | ||
} | ||
} | ||
|
||
async function createFromReactNativeTemplate( | ||
projectName: string, | ||
version: string, | ||
npm?: boolean, | ||
) { | ||
logger.info('Initializing new project'); | ||
logger.debug('Initializing new project'); | ||
logger.log(banner); | ||
|
||
if (semver.valid(version) && !semver.satisfies(version, '0.60.0')) { | ||
throw new Error( | ||
'Cannot use React Native CLI to initialize project with version less than 0.60.0', | ||
); | ||
} | ||
const Loader = getLoader(); | ||
const loader = new Loader({text: 'Downloading template'}); | ||
loader.start(); | ||
|
||
const TEMPLATE_NAME = 'react-native'; | ||
try { | ||
if (semver.valid(version) && !semver.gte(version, '0.60.0')) { | ||
throw new Error( | ||
'Cannot use React Native CLI to initialize project with version less than 0.60.0', | ||
); | ||
} | ||
|
||
const {uri} = await processTemplateName(`${TEMPLATE_NAME}@${version}`); | ||
const TEMPLATE_NAME = 'react-native'; | ||
|
||
installTemplatePackage(uri, npm); | ||
const templateConfig = getTemplateConfig(TEMPLATE_NAME); | ||
copyTemplate(TEMPLATE_NAME, templateConfig.templateDir); | ||
changePlaceholderInTemplate(projectName, templateConfig.placeholderName); | ||
const {uri} = await processTemplateName(`${TEMPLATE_NAME}@${version}`); | ||
|
||
if (templateConfig.postInitScript) { | ||
executePostInitScript(TEMPLATE_NAME, templateConfig.postInitScript); | ||
} | ||
await installTemplatePackage(uri, npm); | ||
|
||
loader.succeed(); | ||
loader.start('Copying template'); | ||
|
||
const templateConfig = getTemplateConfig(TEMPLATE_NAME); | ||
copyTemplate(TEMPLATE_NAME, templateConfig.templateDir); | ||
|
||
PackageManager.installAll({preferYarn: !npm}); | ||
loader.succeed(); | ||
loader.start('Processing template'); | ||
|
||
changePlaceholderInTemplate(projectName, templateConfig.placeholderName); | ||
|
||
loader.succeed(); | ||
const {postInitScript} = templateConfig; | ||
if (postInitScript) { | ||
loader.start('Executing post init script'); | ||
await executePostInitScript(TEMPLATE_NAME, postInitScript); | ||
loader.succeed(); | ||
} | ||
|
||
loader.start('Installing all required dependencies'); | ||
await PackageManager.installAll({preferYarn: !npm, silent: true}); | ||
loader.succeed(); | ||
} catch (e) { | ||
loader.fail(); | ||
throw new Error(e); | ||
} | ||
} | ||
|
||
function createProject(projectName: string, options: Options, version: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ | |
|
||
import type {ContextT} from '../../tools/types.flow'; | ||
import logger from '../../tools/logger'; | ||
import * as PackageManager from '../../tools/PackageManager'; | ||
import * as PackageManager from '../../tools/packageManager'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you changed module name from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable name left uppercased because it is a grouping of all methods in |
||
import link from '../link/link'; | ||
import loadConfig from '../../tools/config'; | ||
|
||
async function install(args: Array<string>, ctx: ContextT) { | ||
const name = args[0]; | ||
|
||
logger.info(`Installing "${name}"...`); | ||
PackageManager.install([name]); | ||
await PackageManager.install([name]); | ||
|
||
// Reload configuration to see newly installed dependency | ||
const newConfig = loadConfig(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.