Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platforms options to meteor build: #11437

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to initialize with null

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be includes instead of indexOf

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