Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
fix: allow snapshot only in release (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitko-Kerezov authored Mar 1, 2018
1 parent adb896c commit 2dd9adc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/after-prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const utils = require("./utils");

module.exports = function ($mobileHelper, $projectData, hookArgs) {
const env = hookArgs.env || {};
if (env.snapshot && utils.shouldSnapshot($mobileHelper, hookArgs.platform, hookArgs.appFilesUpdaterOptions.bundle)) {
const shouldSnapshotOptions = {
platform: hookArgs.platform,
bundle: hookArgs.appFilesUpdaterOptions.bundle,
release: hookArgs.appFilesUpdaterOptions.release
};

if (env.snapshot && utils.shouldSnapshot($mobileHelper, shouldSnapshotOptions)) {
snapshotGenerator.installSnapshotArtefacts($projectData.projectDir);
}
}
7 changes: 4 additions & 3 deletions lib/before-prepareJS.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const { runWebpackCompiler } = require("./compiler");

module.exports = function ($mobileHelper, $projectData, hookArgs) {
module.exports = function ($mobileHelper, $projectData, $logger, hookArgs) {
const env = hookArgs.config.env || {};
const platform = hookArgs.config.platform;
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
const config = {
env,
platform,
bundle: appFilesUpdaterOptions.bundle
bundle: appFilesUpdaterOptions.bundle,
release: appFilesUpdaterOptions.release,
};
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, hookArgs);
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, $logger, hookArgs);
return result;
}
5 changes: 3 additions & 2 deletions lib/before-watch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { runWebpackCompiler } = require("./compiler");

module.exports = function ($mobileHelper, $projectData, hookArgs) {
module.exports = function ($mobileHelper, $projectData, $logger, hookArgs) {
if (hookArgs.config) {
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
if (appFilesUpdaterOptions.bundle) {
Expand All @@ -11,10 +11,11 @@ module.exports = function ($mobileHelper, $projectData, hookArgs) {
env,
platform,
bundle: appFilesUpdaterOptions.bundle,
release: appFilesUpdaterOptions.release,
watch: true
};

return runWebpackCompiler(config, $mobileHelper, $projectData, hookArgs);
return runWebpackCompiler(config, $mobileHelper, $projectData, $logger, hookArgs);
}));
}
}
Expand Down
12 changes: 10 additions & 2 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ const { AppDirectoryLocation } = require("./constants");
let hasBeenInvoked = false;

let webpackProcess = null;
let hasLoggedSnapshotWarningMessage = false;

function logdSnapshotWarningMessage($logger) {
if (!hasLoggedSnapshotWarningMessage) {
$logger.warn("Stripping the snapshot flag. Bear in mind that snapshot is only available in release builds and is NOT available on Windows systems.");
}
}

exports.getWebpackProcess = function getWebpackProcess() {
return webpackProcess;
}

exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, hookArgs, originalArgs, originalMethod) {
exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, $logger, hookArgs) {
if (config.bundle) {
return new Promise(function (resolveBase, rejectBase) {
if (webpackProcess) {
Expand All @@ -37,7 +44,8 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
const envFlagNames = Object.keys(config.env).concat([config.platform.toLowerCase()]);

const snapshotEnvIndex = envFlagNames.indexOf("snapshot");
if (snapshotEnvIndex !== -1 && !utils.shouldSnapshot($mobileHelper, config.platform, config.bundle)) {
if (snapshotEnvIndex !== -1 && !utils.shouldSnapshot($mobileHelper, config)) {
logdSnapshotWarningMessage($logger);
envFlagNames.splice(snapshotEnvIndex, 1);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const os = require("os");

function shouldSnapshot($mobileHelper, platform, bundle) {
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(platform);
function shouldSnapshot($mobileHelper, config) {
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(config.platform);
const osSupportsSnapshot = os.type() !== "Windows_NT";
return bundle && platformSupportsSnapshot && osSupportsSnapshot;
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot;
}

module.exports.shouldSnapshot = shouldSnapshot;

0 comments on commit 2dd9adc

Please sign in to comment.