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

Update to electron-forge 6 & simplify build pipeline/project structure #418

Merged
merged 24 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3d7eb02
chore: update yarn.lock
bendemboski Nov 17, 2019
44ecbcf
chore: Remove unneeded dependencies
bendemboski Nov 17, 2019
9fd0475
chore: Put ember-cli in peerDependencies
bendemboski Nov 17, 2019
452b154
feat: Update to electron-forge 6
bendemboski Nov 17, 2019
3da0858
feat: simplify build pipeline
bendemboski Nov 18, 2019
0c13c7c
test: Get tests working
bendemboski Nov 19, 2019
d40a30a
feat: Enable live reload server
bendemboski Nov 19, 2019
a58c680
chore: Improve blueprint messaging
bendemboski Nov 20, 2019
70e3dda
chore: Update .travis.yml from blueprint
bendemboski Nov 20, 2019
2c4f18e
fix: Fix linting
bendemboski Nov 20, 2019
69e7511
feat: Build for production by default when making/packaging
bendemboski Nov 21, 2019
ec8983d
docs: Documentation!
bendemboski Nov 21, 2019
47fe0bf
chore: Remove semantic release
bendemboski Nov 21, 2019
f87227a
Update appveyor config
bendemboski Nov 21, 2019
e10f43b
fix: better solution for hidepassed
bendemboski Nov 21, 2019
2e0735f
chore: Remove windows query string workaround
bendemboski Nov 21, 2019
8e2bc67
chore: Prevent redundant appveyor build
bendemboski Nov 21, 2019
992fcda
Remove denodeify
bendemboski Nov 22, 2019
f97f80e
Run CI on Node 8
bendemboski Nov 22, 2019
1445f59
Build available options based on base command for inherited commands
bendemboski Nov 22, 2019
5bcea88
Update documentation language
bendemboski Nov 22, 2019
ca81655
Linting, dependencies, and output dirs/files
bendemboski Nov 24, 2019
e83276d
fix: don't assume POSIX path separator
jacobq Nov 24, 2019
09b5fc5
fixup! fix: don't assume POSIX path separator
jacobq Nov 24, 2019
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
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ module.exports = {
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
'ember/avoid-leaking-state-in-ember-objects': 'off',
'node/no-unpublished-require': ['error', {
'allowModules': ['ember-cli']
}]
})
}
]
Expand Down
5 changes: 0 additions & 5 deletions blueprints/ember-electron/files/ember-electron/.compilerc

This file was deleted.

42 changes: 18 additions & 24 deletions blueprints/ember-electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const path = require('path');
const { all, denodeify } = require('rsvp');

const Blueprint = require('ember-cli/lib/models/blueprint');
const efImport = require('electron-forge/dist/api/import').default;
const { setupForgeEnv, shouldUseYarn } = require('../../lib/utils/yarn-or-npm');
const { api } = require('@electron-forge/core');
const { setupForgeEnv } = require('../../lib/utils/yarn-or-npm');

const Logger = require('../../lib/utils/logger');

Expand Down Expand Up @@ -59,28 +59,28 @@ module.exports = class EmberElectronBlueprint extends Blueprint {
});
}

_installElectronTooling(logger) {
async _installElectronTooling(logger) {
// n.b. addPackageToProject does not let us save prod deps, so we task
let npmInstall = this.taskFor('npm-install');
setupForgeEnv(this.project.root);

logger.startProgress('Installing electron build tools');

return efImport({
updateScripts: false,
outDir: 'electron-out',
})
.then(() => npmInstall.run({
'save-dev': true,
verbose: false,
packages: ['devtron@^1.4.0'],
}))
.then(() => npmInstall.run({
save: true,
verbose: false,
packages: ['electron-protocol-serve@^1.3.0'],
}))
.then(() => logger.message('Installed electron build tools'));
await api.import({
shouldUpdateScript: () => false,
outDir: 'electron-out',
});
await npmInstall.run({
'save-dev': true,
verbose: false,
packages: ['devtron@^1.4.0'],
});
await npmInstall.run({
save: true,
verbose: false,
packages: ['electron-protocol-serve@^1.3.0'],
});
logger.message('Installed electron build tools');
}

_createResourcesDirectories(logger) {
Expand Down Expand Up @@ -109,7 +109,6 @@ module.exports = class EmberElectronBlueprint extends Blueprint {

let packageJsonPath = path.join(this.project.root, 'package.json');
let forgeConfigPath = './ember-electron/electron-forge-config.js';
let isUsingYarn = shouldUseYarn(this.project.root);

// If we had a forge config before running forge import, then it may be
// customized by the user, so let's not mess with it.
Expand All @@ -129,11 +128,6 @@ module.exports = class EmberElectronBlueprint extends Blueprint {
return;
}

// required to force the package manager to use yarn when the project uses yarn
if (isUsingYarn) {
forgeConfig.electronPackagerConfig.packageManager = 'yarn';
}

forgeConfig = JSON.stringify(forgeConfig, null, 2);

packageJson.config.forge = forgeConfigPath;
Expand Down
67 changes: 34 additions & 33 deletions lib/commands/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Command = require('ember-cli/lib/models/command');
const Builder = require('../models/builder');
const Watcher = require('ember-cli/lib/models/watcher');
const Logger = require('../utils/logger');
const efStart = require('electron-forge/dist/api/start').default;
const { api } = require('@electron-forge/core');

const { Promise } = RSVP;

Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = Command.extend({
return buildWatcher;
},

_startElectron({ outputPath, verbose }, logger = new Logger(this)) {
async _startElectron({ outputPath, verbose }, logger = new Logger(this)) {
const argv = this._getArgv();

let electronArgs = [];
Expand All @@ -83,37 +83,38 @@ module.exports = Command.extend({

outputPath = path.resolve(outputPath);

return efStart({ appPath: outputPath, dir: outputPath, args: electronArgs })
.then((handle) => new Promise((resolve/* , reject */) => {
handle.on('close', (code, signal) => {
if (verbose) {
logger.section([
'Electron closed',
` - with code: ${code}`,
` - with signal: ${signal}`,
]);
}
});

handle.on('disconnect', () => {
if (verbose) {
logger.message('Electron disconnected.');
}
});

handle.on('error', (err) => {
logger.error(err);
});

handle.on('exit', (/* code, signal */) => {
logger.message('Electron exited.');
resolve();
});

handle.on('message', (message) => {
logger.message(message);
});
}));
let handle = await api.start({ appPath: outputPath, dir: outputPath, args: electronArgs });

handle.on('close', (code, signal) => {
if (verbose) {
logger.section([
'Electron closed',
` - with code: ${code}`,
` - with signal: ${signal}`,
]);
}
});

handle.on('disconnect', () => {
if (verbose) {
logger.message('Electron disconnected.');
}
});

handle.on('error', (err) => {
logger.error(err);
});

handle.on('message', (message) => {
logger.message(message);
});

await new Promise((resolve) => {
handle.on('exit', () => {
logger.message('Electron exited.');
resolve();
});
});
},

// For test instrumentation
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class AssembleTask extends Task {

pruneCommand() {
if (shouldUseYarn(this.project.root)) {
return 'yarn install --production --no-bin-links';
jacobq marked this conversation as resolved.
Show resolved Hide resolved
return 'yarn';
} else {
return 'npm install --production --no-bin-links';
return 'npm install';
}
}

Expand Down
60 changes: 27 additions & 33 deletions lib/tasks/make.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const chalk = require('chalk');
const { resolve } = require('rsvp');
const Task = require('ember-cli/lib/models/task');
const PackageTask = require('./package');
const forgeMake = require('electron-forge/dist/api/make').default;
const { api } = require('@electron-forge/core');

//
// A task that runs electron-forge make to make installers. The skipPackage
Expand All @@ -15,43 +14,38 @@ const forgeMake = require('electron-forge/dist/api/make').default;
// rather than re-assembling/rebuilding.
//
class MakeTask extends Task {
run(options) {
async run(options) {
let { ui, analytics, project } = this;
let { skipPackage, outputPath, platform, arch, targets } = options;

let packagePromise;
if (skipPackage) {
// Nothing to do -- we assume the packaged app is present and let forge
// do the rest
packagePromise = resolve();
} else {
// If skipPackage is set, we assume the packaged app is present and let
// forge do the rest
if (!skipPackage) {
let packageTask = new PackageTask({ ui, analytics, project });
packagePromise = packageTask.run(options);
await packageTask.run(options);
}

return packagePromise.then(() => {
ui.writeLine(chalk.green('Making Electron project.'));

let overrideTargets;
if (typeof targets === 'string') {
overrideTargets = targets.split(',');
}

let options = {
dir: project.root,
outDir: outputPath,
skipPackage: true,
overrideTargets,
};
if (platform) {
options.platform = platform;
}
if (arch) {
options.arch = arch;
}

return forgeMake(options);
});
ui.writeLine(chalk.green('Making Electron project.'));

let overrideTargets;
if (typeof targets === 'string') {
overrideTargets = targets.split(',');
}

let makeOptions = {
dir: project.root,
outDir: outputPath,
skipPackage: true,
overrideTargets,
};
if (platform) {
makeOptions.platform = platform;
}
if (arch) {
makeOptions.arch = arch;
}

return await api.make(makeOptions);
}
}

Expand Down
52 changes: 26 additions & 26 deletions lib/tasks/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

const chalk = require('chalk');
const childProcess = require('child_process');
const { resolve } = require('rsvp');
const quickTemp = require('quick-temp');
const Task = require('ember-cli/lib/models/task');
const AssembleTask = require('./assemble');
const { setupForgeEnv } = require('../utils/yarn-or-npm');
const forgePackage = require('electron-forge/dist/api/package').default;
const { api } = require('@electron-forge/core');

//
// A task that runs electron-forge pacakge to package the app. The
Expand All @@ -16,46 +15,47 @@ const forgePackage = require('electron-forge/dist/api/package').default;
// app rather than re-assembling/rebuilding.
//
class PackageTask extends Task {
run(options) {
async run(options) {
let { ui, analytics, project } = this;
let { projectPath, outputPath, platform, arch } = options;

let assemblePromise;
if (projectPath) {
// We have a path to an assembled project, so just pass it to forge
assemblePromise = resolve();
} else {
// Assemble the project and pass to forge
projectPath = quickTemp.makeOrRemake(this, '-tmpPath');

if (process.platform !== 'win32') {
childProcess.execSync(`chmod a+x ${projectPath}`);
let cleanupFn;
try {
// If projectPath is set then we already have an assembled project
if (!projectPath) {
// Assemble the project and pass to forge
projectPath = quickTemp.makeOrRemake(this, '-tmpPath');
cleanupFn = () => quickTemp.remove(this, '-tmpPath');

if (process.platform !== 'win32') {
childProcess.execSync(`chmod a+x ${projectPath}`);
}

options.outputPath = projectPath;
let assembleTask = new AssembleTask({ ui, analytics, project });
await assembleTask.run(options);
}

options.outputPath = projectPath;
let assembleTask = new AssembleTask({ ui, analytics, project });
assemblePromise = assembleTask.run(options);
}

return assemblePromise.then(() => {
setupForgeEnv(this.project.root);
ui.writeLine(chalk.green('Packaging Electron project.'));

let options = {
let packageOptions = {
dir: projectPath,
outDir: outputPath,
};
if (platform) {
options.platform = platform;
packageOptions.platform = platform;
}
if (arch) {
options.arch = arch;
packageOptions.arch = arch;
}

return forgePackage(options);
}).finally(() => {
quickTemp.remove(this, '-tmpPath');
});
return await api.package(packageOptions);
} finally {
if (cleanupFn) {
cleanupFn();
}
}
}
}

Expand Down
Loading