From bdc7d86d54595fddfb681914997fa56df55ee307 Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 12:03:46 -0700 Subject: [PATCH 1/7] minor fixes, and auto setup of .env file for hf template --- .../scripts/utils/frontierInit.js | 38 +++++++++++++------ packages/react-scripts/template/.env | 2 - 2 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 packages/react-scripts/template/.env diff --git a/packages/react-scripts/scripts/utils/frontierInit.js b/packages/react-scripts/scripts/utils/frontierInit.js index 868b946e4b1..2fad0fa3377 100644 --- a/packages/react-scripts/scripts/utils/frontierInit.js +++ b/packages/react-scripts/scripts/utils/frontierInit.js @@ -56,7 +56,6 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) { if (additionalFeatures.includes('header-footer')) { configureHF(appPath, useYarn, ownPath); } - injectPolymerCode(appPath); const defaultModules = ['http-proxy-middleware@0.19.0', 'fs-webdev/exo']; @@ -81,7 +80,7 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) { }; packageJson.scripts = { ...packageJson.scripts, ...additionalScripts }; packageJson.eslintConfig = { - extends: ['frontier/recommended'], + extends: ['@fs/eslint-config-frontier-react'], }; return packageJson; }); @@ -112,6 +111,7 @@ function configurePolymer(appPath, useYarn) { return packageJson; }); + injectPolymerCode(appPath); const polymerModules = ['vendor-copy@2.0.0', '@webcomponents/webcomponentsjs@2.1.3']; installModulesSync(polymerModules, useYarn, true); } @@ -139,7 +139,7 @@ function configureEF(appPath, useYarn, ownPath) { alterPackageJsonFile(appPath, appPackage => { const packageJson = { ...appPackage }; const additionalScripts = { - "heroku-prebuild": "./heroku-prebuild.sh" + 'heroku-prebuild': './heroku-prebuild.sh', }; packageJson.scripts = sortScripts({ ...packageJson.scripts, ...additionalScripts }); return packageJson; @@ -147,27 +147,27 @@ function configureEF(appPath, useYarn, ownPath) { } function configureHF(appPath, useYarn, ownPath) { - const templatePath = path.join(ownPath, 'template-hf'); fs.copySync(templatePath, appPath, { overwrite: true }); alterPackageJsonFile(appPath, appPackage => { const packageJson = { ...appPackage }; const additionalScripts = { - "build:prod": "PUBLIC_URL=https://edge.fscdn.org/assets/ react-scripts build", - "heroku-postbuild": "npm run build:prod" + 'build:prod': 'PUBLIC_URL=https://edge.fscdn.org/assets/ react-scripts build', + 'heroku-postbuild': 'npm run build:prod', }; packageJson.scripts = sortScripts({ ...packageJson.scripts, ...additionalScripts }); - packageJson.main = "./server.js"; + packageJson.main = './server.js'; return packageJson; }); + setupEnvars(appPath); let modules = [ 'github:fs-webdev/hf#cra', 'github:fs-webdev/snow#cra', 'github:fs-webdev/startup', - ] + ]; installModulesSync(modules, useYarn); } @@ -197,10 +197,24 @@ function buildInstallCommandAndArgs(useYarn, saveDev = false) { return { command, args }; } -function sortScripts(scripts){ +function setupEnvars(appPath) { + console.log('about to run setupEnvars'); + osUtils.runExternalCommandSync('npx', ['@fs/fr-cli', 'env', 'local']); + const envPath = path.join(appPath, '.env'); + console.log('envPath: ', envPath); + console.log('about to run readFileSync'); + let envFile = fs.readFileSync(envPath, 'UTF8'); + + envFile += `\nSKIP_PREFLIGHT_CHECK=true`; + fs.writeFileSync(envPath, envFile); +} + +function sortScripts(scripts) { const sortedScripts = {}; - Object.keys(scripts).sort().forEach(function(key) { - sortedScripts[key] = scripts[key]; - }); + Object.keys(scripts) + .sort() + .forEach(function(key) { + sortedScripts[key] = scripts[key]; + }); return sortedScripts; } diff --git a/packages/react-scripts/template/.env b/packages/react-scripts/template/.env deleted file mode 100644 index 93740cd04a4..00000000000 --- a/packages/react-scripts/template/.env +++ /dev/null @@ -1,2 +0,0 @@ -#dont worry about using newer versions of libraries than react-scripts -SKIP_PREFLIGHT_CHECK=true From 3b8dc39e4dad0250e98d9033ff2d588497dcf408 Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 12:04:48 -0700 Subject: [PATCH 2/7] removing console.logs --- packages/react-scripts/scripts/utils/frontierInit.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/react-scripts/scripts/utils/frontierInit.js b/packages/react-scripts/scripts/utils/frontierInit.js index 2fad0fa3377..a636cc7ecfc 100644 --- a/packages/react-scripts/scripts/utils/frontierInit.js +++ b/packages/react-scripts/scripts/utils/frontierInit.js @@ -198,11 +198,8 @@ function buildInstallCommandAndArgs(useYarn, saveDev = false) { } function setupEnvars(appPath) { - console.log('about to run setupEnvars'); osUtils.runExternalCommandSync('npx', ['@fs/fr-cli', 'env', 'local']); const envPath = path.join(appPath, '.env'); - console.log('envPath: ', envPath); - console.log('about to run readFileSync'); let envFile = fs.readFileSync(envPath, 'UTF8'); envFile += `\nSKIP_PREFLIGHT_CHECK=true`; From ab9445f49c90a63491805fc590de91bb5a9c8e36 Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 12:13:42 -0700 Subject: [PATCH 3/7] keeping the default .env in case the hf option isnt selected --- packages/react-scripts/template/.env | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packages/react-scripts/template/.env diff --git a/packages/react-scripts/template/.env b/packages/react-scripts/template/.env new file mode 100644 index 00000000000..93740cd04a4 --- /dev/null +++ b/packages/react-scripts/template/.env @@ -0,0 +1,2 @@ +#dont worry about using newer versions of libraries than react-scripts +SKIP_PREFLIGHT_CHECK=true From a5af82ef3b4d0a278c38f100fb431965322a349d Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 13:38:51 -0700 Subject: [PATCH 4/7] changing function name --- packages/react-scripts/scripts/utils/frontierInit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/utils/frontierInit.js b/packages/react-scripts/scripts/utils/frontierInit.js index a636cc7ecfc..4b4dfa3677f 100644 --- a/packages/react-scripts/scripts/utils/frontierInit.js +++ b/packages/react-scripts/scripts/utils/frontierInit.js @@ -162,7 +162,7 @@ function configureHF(appPath, useYarn, ownPath) { return packageJson; }); - setupEnvars(appPath); + createLocalEnvFile(appPath); let modules = [ 'github:fs-webdev/hf#cra', 'github:fs-webdev/snow#cra', @@ -197,7 +197,7 @@ function buildInstallCommandAndArgs(useYarn, saveDev = false) { return { command, args }; } -function setupEnvars(appPath) { +function createLocalEnvFile(appPath) { osUtils.runExternalCommandSync('npx', ['@fs/fr-cli', 'env', 'local']); const envPath = path.join(appPath, '.env'); let envFile = fs.readFileSync(envPath, 'UTF8'); From ff9527e127a77f1030d7e3ba3e694e0048b0683f Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 13:50:25 -0700 Subject: [PATCH 5/7] removing the useYarn option from frontierInit code. --- packages/react-scripts/scripts/init.js | 61 ++++--------------- .../scripts/utils/frontierInit.js | 52 +++++----------- 2 files changed, 29 insertions(+), 84 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 57436f1472e..3092d67f392 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -76,17 +76,9 @@ function tryGitInit(appPath) { } } -module.exports = async function( - appPath, - appName, - verbose, - originalDirectory, - template -) { +module.exports = async function(appPath, appName, verbose, originalDirectory, template) { const answers = await frontierInit.promptForConfig(appPath); - const ownPath = path.dirname( - require.resolve(path.join(__dirname, '..', 'package.json')) - ); + const ownPath = path.dirname(require.resolve(path.join(__dirname, '..', 'package.json'))); const appPackage = require(path.join(appPath, 'package.json')); const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock')); @@ -120,10 +112,7 @@ module.exports = async function( const readmeExists = fs.existsSync(path.join(appPath, 'README.md')); if (readmeExists) { - fs.renameSync( - path.join(appPath, 'README.md'), - path.join(appPath, 'README.old.md') - ); + fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md')); } // Copy the files for the user @@ -133,20 +122,14 @@ module.exports = async function( if (fs.existsSync(templatePath)) { fs.copySync(templatePath, appPath); } else { - console.error( - `Could not locate supplied template: ${chalk.green(templatePath)}` - ); + console.error(`Could not locate supplied template: ${chalk.green(templatePath)}`); return; } // Rename gitignore after the fact to prevent npm from renaming it to .npmignore // See: https://github.com/npm/npm/issues/1862 try { - fs.moveSync( - path.join(appPath, 'gitignore'), - path.join(appPath, '.gitignore'), - [] - ); + fs.moveSync(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), []); } catch (err) { // Append if there's already a `.gitignore` file there if (err.code === 'EEXIST') { @@ -171,10 +154,7 @@ module.exports = async function( args.push('react', 'react-dom'); // Install additional template dependencies, if present - const templateDependenciesPath = path.join( - appPath, - '.template.dependencies.json' - ); + const templateDependenciesPath = path.join(appPath, '.template.dependencies.json'); if (fs.existsSync(templateDependenciesPath)) { const templateDependencies = require(templateDependenciesPath).dependencies; args = args.concat( @@ -199,7 +179,7 @@ module.exports = async function( } } - frontierInit.installFrontierDependencies(appPath, answers, useYarn, ownPath); + frontierInit.installFrontierDependencies(appPath, answers, ownPath); if (useTypeScript) { verifyTypeScriptSetup(); @@ -223,8 +203,6 @@ module.exports = async function( // Change displayed command to yarn instead of yarnpkg const displayedCommand = useYarn ? 'yarn' : 'npm'; - frontierInit.cleanupFrontierCode(appPath); - console.log(); console.log(`Success! Created ${appName} at ${appPath}`); console.log('Inside that directory, you can run several commands:'); @@ -232,23 +210,15 @@ module.exports = async function( console.log(chalk.cyan(` ${displayedCommand} start`)); console.log(' Starts the development server.'); console.log(); - console.log( - chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}build`) - ); + console.log(chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}build`)); console.log(' Bundles the app into static files for production.'); console.log(); console.log(chalk.cyan(` ${displayedCommand} test`)); console.log(' Starts the test runner.'); console.log(); - console.log( - chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}eject`) - ); - console.log( - ' Removes this tool and copies build dependencies, configuration files' - ); - console.log( - ' and scripts into the app directory. If you do this, you can’t go back!' - ); + console.log(chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}eject`)); + console.log(' Removes this tool and copies build dependencies, configuration files'); + console.log(' and scripts into the app directory. If you do this, you can’t go back!'); console.log(); console.log('We suggest that you begin by typing:'); console.log(); @@ -256,11 +226,7 @@ module.exports = async function( console.log(` ${chalk.cyan(`${displayedCommand} start`)}`); if (readmeExists) { console.log(); - console.log( - chalk.yellow( - 'You had a `README.md` file, we renamed it to `README.old.md`' - ) - ); + console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`')); } console.log(); console.log('Happy hacking!'); @@ -270,7 +236,6 @@ function isReactInstalled(appPackage) { const dependencies = appPackage.dependencies || {}; return ( - typeof dependencies.react !== 'undefined' && - typeof dependencies['react-dom'] !== 'undefined' + typeof dependencies.react !== 'undefined' && typeof dependencies['react-dom'] !== 'undefined' ); } diff --git a/packages/react-scripts/scripts/utils/frontierInit.js b/packages/react-scripts/scripts/utils/frontierInit.js index 4b4dfa3677f..6d1522c30f7 100644 --- a/packages/react-scripts/scripts/utils/frontierInit.js +++ b/packages/react-scripts/scripts/utils/frontierInit.js @@ -11,7 +11,6 @@ module.exports = { installFrontierDependencies, promptForConfig, packageJsonWritten, - cleanupFrontierCode, }; async function promptForConfig() { @@ -44,17 +43,17 @@ async function promptForConfig() { function packageJsonWritten() {} -function installFrontierDependencies(appPath, answers, useYarn, ownPath) { +function installFrontierDependencies(appPath, answers, ownPath) { const { additionalFeatures } = answers; if (additionalFeatures.includes('polymer')) { - configurePolymer(appPath, useYarn); + configurePolymer(appPath); } if (additionalFeatures.includes('electric-flow')) { - configureEF(appPath, useYarn, ownPath); + configureEF(appPath, ownPath); } if (additionalFeatures.includes('header-footer')) { - configureHF(appPath, useYarn, ownPath); + configureHF(appPath, ownPath); } const defaultModules = ['http-proxy-middleware@0.19.0', 'fs-webdev/exo']; @@ -66,8 +65,8 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) { 'webpack@4.19.1', ]; - installModulesSync(defaultModules, useYarn); - installModulesSync(defaultDevModules, useYarn, true); + installModulesSync(defaultModules); + installModulesSync(defaultDevModules, true); alterPackageJsonFile(appPath, appPackage => { const packageJson = { ...appPackage }; @@ -94,7 +93,7 @@ function alterPackageJsonFile(appPath, extendFunction) { ); } -function configurePolymer(appPath, useYarn) { +function configurePolymer(appPath) { alterPackageJsonFile(appPath, appPackage => { const packageJson = { ...appPackage }; packageJson.vendorCopy = [ @@ -113,7 +112,7 @@ function configurePolymer(appPath, useYarn) { injectPolymerCode(appPath); const polymerModules = ['vendor-copy@2.0.0', '@webcomponents/webcomponentsjs@2.1.3']; - installModulesSync(polymerModules, useYarn, true); + installModulesSync(polymerModules, true); } function injectPolymerCode(appPath) { @@ -129,7 +128,7 @@ function injectPolymerCode(appPath) { fs.writeFileSync(indexPath, indexHtml); } -function configureEF(appPath, useYarn, ownPath) { +function configureEF(appPath, ownPath) { // TODO - modify package.json to make sure name is correct for blueprint // TODO - use blueprint.yml as a template @@ -146,7 +145,7 @@ function configureEF(appPath, useYarn, ownPath) { }); } -function configureHF(appPath, useYarn, ownPath) { +function configureHF(appPath, ownPath) { const templatePath = path.join(ownPath, 'template-hf'); fs.copySync(templatePath, appPath, { overwrite: true }); @@ -168,33 +167,14 @@ function configureHF(appPath, useYarn, ownPath) { 'github:fs-webdev/snow#cra', 'github:fs-webdev/startup', ]; - installModulesSync(modules, useYarn); + installModulesSync(modules); } -function cleanupFrontierCode(appPath) {} - -function installModulesSync(modules, useYarn, saveDev = false) { - const { command, args } = buildInstallCommandAndArgs(useYarn, saveDev); - osUtils.runExternalCommandSync(command, args.concat(modules)); -} - -function buildInstallCommandAndArgs(useYarn, saveDev = false) { - let command; - let args; - if (useYarn) { - command = 'yarnpkg'; - args = ['add']; - if (saveDev) { - args.push('--dev'); - } - } else { - command = 'npm'; - args = ['install', '--save']; - if (saveDev) { - args[1] = '--save-dev'; - } - } - return { command, args }; +function installModulesSync(modules, saveDev = false) { + osUtils.runExternalCommandSync( + 'npm', + ['install', `--save${saveDev ? '-dev' : ''}`].concat(modules) + ); } function createLocalEnvFile(appPath) { From cb0ab516f8170f18701dbed17d1d2e1cbc91cb30 Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 14:06:51 -0700 Subject: [PATCH 6/7] going to let `fr env` handle setting the SKIP_PREFLIGHT_CKECK=true --- .../react-scripts/scripts/utils/frontierInit.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/react-scripts/scripts/utils/frontierInit.js b/packages/react-scripts/scripts/utils/frontierInit.js index 6d1522c30f7..5d62e61bdfe 100644 --- a/packages/react-scripts/scripts/utils/frontierInit.js +++ b/packages/react-scripts/scripts/utils/frontierInit.js @@ -161,7 +161,7 @@ function configureHF(appPath, ownPath) { return packageJson; }); - createLocalEnvFile(appPath); + createLocalEnvFile(); let modules = [ 'github:fs-webdev/hf#cra', 'github:fs-webdev/snow#cra', @@ -171,19 +171,13 @@ function configureHF(appPath, ownPath) { } function installModulesSync(modules, saveDev = false) { - osUtils.runExternalCommandSync( - 'npm', - ['install', `--save${saveDev ? '-dev' : ''}`].concat(modules) - ); + const command = 'npm'; + const args = ['install', `--save${saveDev ? '-dev' : ''}`].concat(modules); + osUtils.runExternalCommandSync(command, args); } -function createLocalEnvFile(appPath) { +function createLocalEnvFile() { osUtils.runExternalCommandSync('npx', ['@fs/fr-cli', 'env', 'local']); - const envPath = path.join(appPath, '.env'); - let envFile = fs.readFileSync(envPath, 'UTF8'); - - envFile += `\nSKIP_PREFLIGHT_CHECK=true`; - fs.writeFileSync(envPath, envFile); } function sortScripts(scripts) { From ba7b1d0a353b90bfec8f0d75841cf9076d03c311 Mon Sep 17 00:00:00 2001 From: Joey Cozza Date: Fri, 22 Feb 2019 14:11:08 -0700 Subject: [PATCH 7/7] removing .env file with the SKIP_PREFLIGHT_CHECK flag --- packages/react-scripts/template/.env | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 packages/react-scripts/template/.env diff --git a/packages/react-scripts/template/.env b/packages/react-scripts/template/.env deleted file mode 100644 index 93740cd04a4..00000000000 --- a/packages/react-scripts/template/.env +++ /dev/null @@ -1,2 +0,0 @@ -#dont worry about using newer versions of libraries than react-scripts -SKIP_PREFLIGHT_CHECK=true