From 059635979d06c885256e5723659d93045ff53861 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 2 Oct 2018 11:30:06 -0500 Subject: [PATCH] pipeline.js dapp config to allow easy toggling of typescript --- lib/pipeline/webpack.config.js | 7 ++++--- lib/pipeline/webpackProcess.js | 23 ++++++++++++++++++++++- templates/boilerplate/config/pipeline.js | 3 +++ templates/demo/config/pipeline.js | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 templates/boilerplate/config/pipeline.js create mode 100644 templates/demo/config/pipeline.js diff --git a/lib/pipeline/webpack.config.js b/lib/pipeline/webpack.config.js index 0e055b873..7639b51f8 100644 --- a/lib/pipeline/webpack.config.js +++ b/lib/pipeline/webpack.config.js @@ -20,8 +20,9 @@ const embarkPath = process.env.EMBARK_PATH; const embarkAliases = require(path.join(dappPath, '.embark/embark-aliases.json')); const embarkAssets = require(path.join(dappPath, '.embark/embark-assets.json')); -const embarkNodeModules = path.join(embarkPath, 'node_modules'); const embarkJson = require(path.join(dappPath, 'embark.json')); +const embarkNodeModules = path.join(embarkPath, 'node_modules'); +const embarkPipeline = require(path.join(dappPath, '.embark/embark-pipeline.json')); const buildDir = path.join(dappPath, embarkJson.buildDir); @@ -192,7 +193,7 @@ const baseBabelLoader = base.module.rules[3]; // ----------------------------------------------------------------------------- // should be false in configs that have isTypeScriptEnabled = true -const isFlowEnabled = true; +const isFlowEnabled = !embarkPipeline.typescript; if (isFlowEnabled) { // position @babel/plugin-transform-flow-strip-types per babel-preset-react-app baseBabelLoader.options.plugins.unshift( @@ -204,7 +205,7 @@ if (isFlowEnabled) { // ----------------------------------------------------------------------------- // should be false in configs that have isFlowEnabled = true -const isTypeScriptEnabled = false; +const isTypeScriptEnabled = !!embarkPipeline.typescript; if (isTypeScriptEnabled) { // position @babel/preset-typescript as the last preset (runs first) // see: https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/ diff --git a/lib/pipeline/webpackProcess.js b/lib/pipeline/webpackProcess.js index 8e75cdc17..f29174294 100644 --- a/lib/pipeline/webpackProcess.js +++ b/lib/pipeline/webpackProcess.js @@ -3,7 +3,16 @@ const fs = require('../core/fs'); const ProcessWrapper = require('../core/processes/processWrapper'); const webpack = require('webpack'); const writeFile = require('util').promisify(require('fs').writeFile); -const {errorMessage} = require('../utils/utils'); +const {errorMessage, recursiveMerge} = require('../utils/utils'); + +const defaultPipelineConfig = { + typescript: false +}; + +const pipelineConfigPath = fs.dappPath( + require(fs.dappPath('embark.json')).config || 'config/', + 'pipeline.js' +); let webpackProcess; @@ -31,6 +40,18 @@ class WebpackProcess extends ProcessWrapper { fs.dappPath('.embark/embark-assets.json'), JSON.stringify(assets) ); + let pipelineConfig = defaultPipelineConfig; + if (fs.existsSync(pipelineConfigPath)) { + delete require.cache[pipelineConfigPath]; + pipelineConfig = recursiveMerge( + recursiveMerge(true, pipelineConfig), + require(pipelineConfigPath) + ); + } + await writeFile( + fs.dappPath('.embark/embark-pipeline.json'), + JSON.stringify(pipelineConfig) + ); } catch (e) { return callback(errorMessage(e)); } diff --git a/templates/boilerplate/config/pipeline.js b/templates/boilerplate/config/pipeline.js new file mode 100644 index 000000000..3ba2b624c --- /dev/null +++ b/templates/boilerplate/config/pipeline.js @@ -0,0 +1,3 @@ +module.exports = { + typescript: false +}; diff --git a/templates/demo/config/pipeline.js b/templates/demo/config/pipeline.js new file mode 100644 index 000000000..3ba2b624c --- /dev/null +++ b/templates/demo/config/pipeline.js @@ -0,0 +1,3 @@ +module.exports = { + typescript: false +};