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

fix: allow snapshot only in release #448

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;