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 1 commit
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: 2 additions & 1 deletion blueprints/ember-electron/files/testem-electron.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed=1',
bendemboski marked this conversation as resolved.
Show resolved Hide resolved
disable_watching: true,
launchers: {
Electron: require('ember-electron/lib/test-support/test-runner'),
Expand Down
35 changes: 32 additions & 3 deletions blueprints/ember-electron/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const Blueprint = require('ember-cli/lib/models/blueprint');
const { api } = require('@electron-forge/core');
const chalk = require('chalk');
const { electronProjectPath } = require('../../lib/utils/build-paths');
const path = require('path');
const denodeify = require('denodeify');
const fs = require('fs');
const readFile = denodeify(fs.readFile);
jacobq marked this conversation as resolved.
Show resolved Hide resolved
const writeFile = denodeify(fs.writeFile);

module.exports = class EmberElectronBlueprint extends Blueprint {
constructor(options) {
Expand All @@ -13,13 +19,36 @@ module.exports = class EmberElectronBlueprint extends Blueprint {
return entityName;
}

async afterInstall(/* options */) {
this.ui.writeLine(chalk.green('Creating electron-forge project at `./electron`'));
async afterInstall() {
this.ui.writeLine(chalk.green(`Creating electron-forge project at './${electronProjectPath}'`));

await api.init({
dir: 'electron',
dir: electronProjectPath,
interactive: true,
template: 'ember-electron/forge/template'
});

this.ui.writeLine(chalk.green(`Updating './${electronProjectPath}/package.json'`));

const keysToCopy = [
'name',
'version',
'description',
'author',
'license'
];

let packageJsonPath = path.join(electronProjectPath, 'package.json');
let packageJson = JSON.parse(await readFile(packageJsonPath));

for (let key of keysToCopy) {
if (Object.keys(this.project.pkg).includes(key)) {
packageJson[key] = this.project.pkg[key];
}
}

// special-case productName since forge creates it, but a lot of apps don't
packageJson.productName = this.project.pkg.productName || packageJson.name;
await writeFile(packageJsonPath, JSON.stringify(packageJson, { spaces: 2 }));
}
};
3 changes: 2 additions & 1 deletion forge/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const readFile = denodeify(require('fs').readFile);
const writeFile = denodeify(require('fs').writeFile);
const rimraf = denodeify(require('rimraf'));
const ncp = denodeify(require('ncp'));
const { emberBuildDir } = require('../lib/utils/build-paths');
const { emberBuildDir, emberTestBuildDir } = require('../lib/utils/build-paths');

module.exports = {
devDependencies: [
Expand All @@ -27,6 +27,7 @@ module.exports = {
contents.toString(),
'# Ember build',
`${emberBuildDir}/`,
`${emberTestBuildDir}/`,
''
].join('\n'));
}
Expand Down
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const replace = require('broccoli-string-replace');

function injectScript(scriptName) {
let dirname = __dirname || process.cwd();
Expand Down Expand Up @@ -49,4 +50,17 @@ module.exports = {
}
}
},

postprocessTree(type, node) {
if (type === 'all' && process.env.EMBER_CLI_ELECTRON) {
node = replace(node, {
files: [ 'tests/index.html' ],
pattern: {
match: /src="[^"]*testem\.js"/,
replacement: 'src="http://testemserver/testem.js"',
},
});
}
return node;
}
};
4 changes: 0 additions & 4 deletions lib/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const Command = require('ember-cli/lib/models/command');
const ElectronTask = require('../tasks/electron');
const ElectronMakeTask = require('../tasks/make');
const ElectronPackageTask = require('../tasks/package');
const ElectronTestServerTask = require('../tasks/test-server');
const ElectronTestTask = require('../tasks/test');
const YarnOrNpmTask = require('../tasks/yarn-or-npm');
const Win = require('ember-cli/lib/utilities/windows-admin');
const fs = require('fs');
Expand All @@ -21,8 +19,6 @@ module.exports = Command.extend({
'Electron': ElectronTask,
'ElectronMake': ElectronMakeTask,
'ElectronPackage': ElectronPackageTask,
'ElectronTestServer': ElectronTestServerTask,
'ElectronTest': ElectronTestTask,
'YarnOrNpm': YarnOrNpmTask
});
},
Expand Down
42 changes: 33 additions & 9 deletions lib/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
'use strict';

let TestCommand = require('ember-cli/lib/commands/test');
let TestTask = require('../tasks/test');
let TestServerTask = require('../tasks/test-server');
const TestCommand = require('ember-cli/lib/commands/test');
const { emberTestBuildPath } = require('../utils/build-paths');

module.exports = TestCommand.extend({
name: 'electron:test',
description: 'Runs your app\'s test suite in Electron.',

init() {
this._super(...arguments);
this.tasks.TestServer = TestServerTask;
this.tasks.Test = TestTask;
},
availableOptions: [
{
name: 'environment',
type: String,
default: 'test',
aliases: ['e'],
description: 'Possible values are "development", "production", and "test".',
},
{
name: 'config-file',
type: String,
default: 'testem-electron.js',
aliases: ['c', 'cf']
},
{ name: 'server', type: Boolean, default: false, aliases: ['s'] },
{ name: 'filter', type: String, aliases: ['f'], description: 'A string to filter tests to run' },
{ name: 'module', type: String, aliases: ['m'], description: 'The name of a test module to run' },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{
name: 'reporter',
type: String,
aliases: ['r'],
description: 'Test reporter to use [tap|dot|xunit] (default: tap)',
},
{ name: 'silent', type: Boolean, default: false, description: 'Suppress any output except for the test report' },
{ name: 'testem-debug', type: String, description: 'File to write a debug log from testem' },
{ name: 'test-page', type: String, description: 'Test page to invoke' },
{ name: 'query', type: String, description: 'A query string to append to the test page URL.' },
],
bendemboski marked this conversation as resolved.
Show resolved Hide resolved

rmTmp() {
if (process.platform === 'win32') {
Expand All @@ -26,8 +49,9 @@ module.exports = TestCommand.extend({
return this._super(...arguments);
},

run() {
run(commandOptions) {
process.env.EMBER_CLI_ELECTRON = true;
commandOptions.outputPath = emberTestBuildPath;
return this._super(...arguments);
},
});
15 changes: 7 additions & 8 deletions lib/resources/shim-test-head.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//
// This allows testem to extract the ID of this run so it can communicate with
// the testem server (the query param is added to the test URL by
// test-runner.js)
// testem looks for a function called getTestemId, and if present, uses it to
// determine the ID of this test run so it can communicate back to the testem
// server -- see https://github.com/testem/testem/commit/4a51acc2fc0c3a23273fea838fd166b4691c2300.
//
// The testemId query param is added to the test URL by test-runner.js.
//
window.getTestemId = function() {
// FIXME: It should be safe to replace "\?" with "?" below due to context -- need to check though
// eslint-disable-next-line no-useless-escape
let match = window.location.search.match(/[\?&]testemId=([^\?&]+)/);

let match = window.location.search.match(/[?&]testemId=([^?&]+)/);
jacobq marked this conversation as resolved.
Show resolved Hide resolved
return match ? match[1] : null;
};
};
6 changes: 0 additions & 6 deletions lib/tasks/test-server.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/tasks/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/test-support/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (process.platform === 'win32') {

let emberAppDir = resolve(dirname(indexPath), '..');
let relPath = relative(emberAppDir, indexPath);
const emberAppLocation = `serve://dist/${relPath}${indexQuery}`;
let emberAppLocation = `serve://dist/${relPath}${indexQuery}`;
jacobq marked this conversation as resolved.
Show resolved Hide resolved

if (typeof protocol.registerSchemesAsPrivileged === 'function') {
protocol.registerSchemesAsPrivileged([{
Expand Down
17 changes: 9 additions & 8 deletions lib/test-support/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ module.exports = {
};

async function main() {
let path = require('path');
let url = require('url');
let fileUrl = require('file-url');
let treeKill = require('tree-kill');
const path = require('path');
const url = require('url');
const fileUrl = require('file-url');
const treeKill = require('tree-kill');
const { api } = require('@electron-forge/core');
const { electronProjectPath } = require('ember-electron/lib/utils/build-paths');

let [, , buildDir, testemUrl, testPageUrl, id] = process.argv;
let [, , emberAppDir, testemUrl, testPageUrl, id] = process.argv;

// The testPageUrl points to the testem server, so we need to turn it into a
// file URL and add the testem ID to the query params.
let emberAppDir = path.join(buildDir, 'ember');
let {
pathname: testPagePath,
query: testPageQuery,
} = url.parse(testPageUrl, true);
let indexPath = path.resolve(emberAppDir, path.join.apply(null, testPagePath.split('/')));
let indexObj = url.parse(fileUrl(indexPath));
indexObj.query = testPageQuery;
// Set this so the script in shim-test-head.js can expose it to testem
indexObj.query.testemId = id;
let testUrl = url.format(indexObj);
// On windows the testUrl argv is truncated before the first '&' by the time
Expand All @@ -55,8 +56,8 @@ async function main() {

// Start electron
let { pid } = await api.start({
appPath: buildDir,
dir: buildDir,
dir: path.join(process.cwd(), electronProjectPath),
appPath: './tests',
args: [
'--', // needed because https://github.com/electron/electron/pull/13039
testUrl,
Expand Down
10 changes: 8 additions & 2 deletions lib/utils/build-paths.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const path = require('path');

const electronProjectPath = 'electron';
const electronProjectPath = 'electron-app';

const emberBuildDir = 'ember-dist';
const emberBuildPath = path.join(electronProjectPath, emberBuildDir);

const emberTestBuildDir = 'ember-test';
const emberTestBuildPath = path.join(electronProjectPath, emberTestBuildDir);

module.exports = {
electronProjectPath,
emberBuildDir,
emberBuildPath
emberBuildPath,
emberTestBuildDir,
emberTestBuildPath
};
10 changes: 0 additions & 10 deletions lib/utils/test-task-mixin.js

This file was deleted.

25 changes: 12 additions & 13 deletions node-tests/acceptance/end-to-end-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use strict';

const { electronProjectPath } = require('../../lib/utils/build-paths');
const path = require('path');
const {
copySync,
existsSync,
readFileSync,
readJsonSync,
removeSync,
writeFileSync,
writeJsonSync,
} = require('fs-extra');
const denodeify = require('denodeify');
const ncp = denodeify(require('ncp'));
const execa = require('execa');
const tmp = require('tmp');

const { expect } = chai;
const { expect } = require('chai');

function run(cmd, args, opts = {}) {
opts.stdio = opts.stdio || 'inherit';
Expand Down Expand Up @@ -129,7 +130,7 @@ describe('end-to-end', function() {

it('builds', () => {
return ember('electron:build').then(() => {
expect(existsSync(path.join('electron-out', 'ember'))).to.be.ok;
expect(existsSync(path.join('electron-app', 'ember-dist'))).to.be.ok;
});
});

Expand All @@ -150,19 +151,17 @@ describe('end-to-end', function() {
it('extra checks pass', () => {
let fixturePath = path.resolve(__dirname, '..', 'fixtures', 'ember-test');

// Append our extra test content to the end of test-main.js
let testMainPath = path.join('ember-electron', 'test-main.js');
let extraContentPath = path.join(fixturePath, 'test-main-extra.js');
// Append our extra test content to the end of test-index.js
let testIndexPath = path.join('electron-app', 'tests', 'index.js');
let extraContentPath = path.join(fixturePath, 'test-index-extra.js');
let content = [
readFileSync(testMainPath),
readFileSync(testIndexPath),
readFileSync(extraContentPath),
].join('\n');
writeFileSync(path.join('ember-electron', 'test-main.js'), content);
writeFileSync(testIndexPath, content);

// Copy the lib and resources directories over
['lib', 'resources'].forEach((dir) => {
copySync(path.join(fixturePath, dir), path.join('ember-electron', dir));
});
// Copy the source files over
ncp(path.join(fixturePath, 'src'), path.join(electronProjectPath, 'src'));

return expect(ember('electron:test')).to.eventually.be.fulfilled;
});
Expand Down
Empty file.
Empty file.
26 changes: 0 additions & 26 deletions node-tests/fixtures/ember-build/index.html

This file was deleted.

1 change: 0 additions & 1 deletion node-tests/fixtures/ember-test/resources/foo.txt

This file was deleted.

6 changes: 6 additions & 0 deletions node-tests/fixtures/ember-test/test-index-extra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Make sure dependencies (node_modules) are loadable
const fileUrl = require('file-url');
fileUrl('foo.html');
// Make sure local libraries are loadable
const helper = require('../src/helper');
helper();
Loading