pipeline.js dapp config to allow easy toggling of typescript

This commit is contained in:
Michael Bradley, Jr 2018-10-02 11:30:06 -05:00 committed by Pascal Precht
parent 6534c30200
commit 059635979d
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 32 additions and 4 deletions

View File

@ -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/

View File

@ -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));
}

View File

@ -0,0 +1,3 @@
module.exports = {
typescript: false
};

View File

@ -0,0 +1,3 @@
module.exports = {
typescript: false
};