From 22af37a8963e16dd82f97472a8c2edbed690b93a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 28 Jul 2016 18:32:10 +0200 Subject: [PATCH] Add module cache generation --- build/build.js | 4 ++++ build/lib/generate-module-cache.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 build/lib/generate-module-cache.js diff --git a/build/build.js b/build/build.js index cf7001ee9..24aa8ef0d 100644 --- a/build/build.js +++ b/build/build.js @@ -2,12 +2,15 @@ 'use strict' +require('coffee-script/register') + const cleanOutputDirectory = require('./lib/clean-output-directory') const copyAssets = require('./lib/copy-assets') const transpileBabelPaths = require('./lib/transpile-babel-paths') const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths') const transpileCsonPaths = require('./lib/transpile-cson-paths') const transpilePegJsPaths = require('./lib/transpile-peg-js-paths') +const generateModuleCache = require('./lib/generate-module-cache') const packageApplication = require('./lib/package-application') cleanOutputDirectory() @@ -16,4 +19,5 @@ transpileBabelPaths() transpileCoffeeScriptPaths() transpileCsonPaths() transpilePegJsPaths() +generateModuleCache() packageApplication() diff --git a/build/lib/generate-module-cache.js b/build/lib/generate-module-cache.js new file mode 100644 index 000000000..4013e7578 --- /dev/null +++ b/build/lib/generate-module-cache.js @@ -0,0 +1,30 @@ +'use strict' + +const fs = require('fs') +const path = require('path') +const ModuleCache = require('../../src/module-cache') + +const CONFIG = require('../config') + +module.exports = function () { + console.log(`Generating module cache for ${CONFIG.intermediateAppPath}...`) + for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) { + ModuleCache.create(path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)) + } + ModuleCache.create(CONFIG.intermediateAppPath) + const newMetadata = JSON.parse(fs.readFileSync(path.join(CONFIG.intermediateAppPath, 'package.json'))) + for (let folder of newMetadata._atomModuleCache.folders) { + if (folder.paths.indexOf('') !== -1) { + folder.paths = [ + '', + 'exports', + 'spec', + 'src', + 'src/main-process', + 'static', + 'vendor' + ] + } + } + fs.writeFileSync(path.join(CONFIG.intermediateAppPath, 'package.json'), JSON.stringify(newMetadata)) +}