Skip to content

Commit

Permalink
Merge pull request #11437 from matheusccastroo/add-platforms-flag-for…
Browse files Browse the repository at this point in the history
…-meteor-build

Add platforms options to meteor build:
  • Loading branch information
StorytellerCZ committed May 17, 2021
2 parents c94e08d + 5ca8956 commit 319a6c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tools/cli/commands.js
Expand Up @@ -934,7 +934,8 @@ var buildCommands = {
// like progress bars and spinners are unimportant.
headless: { type: Boolean },
verbose: { type: Boolean, short: "v" },
'allow-incompatible-update': { type: Boolean }
'allow-incompatible-update': { type: Boolean },
platforms: { type: String }
},
catalogRefresh: new catalog.Refresh.Never()
};
Expand Down Expand Up @@ -1014,6 +1015,19 @@ var buildCommand = function (options) {
// _bundleOnly implies serverOnly
const serverOnly = options._bundleOnly || !!options['server-only'];

let selectedPlatforms;
if (options.platforms) {
const platformsArray = options.platforms.split(",");

platformsArray.forEach((plat) => {
if (!excludableWebArchs.concat(['android', 'ios']).includes(plat)) {
throw new Error(`Not allowed platform on '--platforms' flag: ${plat}`)
}
})

selectedPlatforms = platformsArray;
}

// options['mobile-settings'] is used to set the initial value of
// `Meteor.settings` on mobile apps. Pass it on to options.settings,
// which is used in this command.
Expand All @@ -1029,6 +1043,10 @@ var buildCommand = function (options) {
if (!serverOnly) {
cordovaPlatforms = projectContext.platformList.getCordovaPlatforms();

if (selectedPlatforms) {
cordovaPlatforms = _.intersection(selectedPlatforms, cordovaPlatforms)
}

if (process.platform !== 'darwin' && _.contains(cordovaPlatforms, 'ios')) {
cordovaPlatforms = _.without(cordovaPlatforms, 'ios');
Console.warn("Currently, it is only possible to build iOS apps \
Expand All @@ -1054,6 +1072,21 @@ on an OS X system.");
cordovaPlatforms = [];
}

// If we specified some platforms, we need to build what was specified. For example, if we want to build only android,
// there is no need to build web.browser.
let webArchs;
if (selectedPlatforms) {
const filteredArchs = projectContext.platformList.getWebArchs().filter((arch) => selectedPlatforms.includes(arch));

if (! _.isEmpty(cordovaPlatforms)) {
if (filteredArchs.indexOf("web.cordova") < 0) {
filteredArchs.push("web.cordova");
}
}

webArchs = filteredArchs.length ? filteredArchs : undefined;
}

var buildDir = projectContext.getProjectLocalDirectory('build_tar');
var outputPath = files.pathResolve(options.args[0]); // get absolute path

Expand Down Expand Up @@ -1094,6 +1127,7 @@ ${Console.command("meteor build ../output")}`,
// packages with binary npm dependencies
serverArch: bundleArch,
buildMode: options.debug ? 'development' : 'production',
webArchs,
},
});
if (bundleResult.errors) {
Expand Down
2 changes: 2 additions & 0 deletions tools/cli/help.txt
Expand Up @@ -425,6 +425,8 @@ Options:
downgraded to versions that are potentially incompatible
with the current versions, if required to satisfy all
package version constraints.
--platforms Builds only the specified platforms (when available).



>>> lint
Expand Down

0 comments on commit 319a6c9

Please sign in to comment.