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
33 changes: 31 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ module.exports = {
'processNode': true
},
rules: {
'ember/no-jquery': 'error',
'no-console': 'off'
'ember/no-jquery': 'error'
},
overrides: [
// node files
Expand Down Expand Up @@ -61,6 +60,36 @@ module.exports = {
// add your custom rules and overrides for node files here
'ember/avoid-leaking-state-in-ember-objects': 'off',
})
},
// forge template files
{
files: [
'forge/files/**/*.js'
],
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
'node/no-missing-require': ['error', {
'allowModules': [
'electron',
'ember-electron'
],
}]
})
},
// mocha files
{
files: [
'node-tests/**/*.js'
],
env: {
browser: false,
node: true,
mocha: true
}
}
]
};
3 changes: 3 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
file: [ 'node-tests/helpers/test-setup' ]
};
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- env: EMBER_TRY_SCENARIO=ember-canary

include:
# runs linting and fast integration/unit tests
# runs linting and fast tests
- stage: "Basic Tests"
script:
- yarn lint:hbs
Expand Down
2 changes: 0 additions & 2 deletions blueprints/ember-electron/files/ember-electron/test-main.js

This file was deleted.

4 changes: 1 addition & 3 deletions blueprints/ember-electron/files/testem-electron.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env node */
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
Expand All @@ -16,10 +15,9 @@ module.exports = {
// Note: Some these Chrome options may not be supported in Electron
// See https://electronjs.org/docs/api/chrome-command-line-switches
ci: [
// --no-sandbox may be needed when running inside a container
// --no-sandbox is needed when running Chrome inside a container
process.env.CI ? '--no-sandbox' : null,
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-software-rasterizer',
'--mute-audio',
Expand Down

This file was deleted.

131 changes: 7 additions & 124 deletions blueprints/ember-electron/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
// Workaround for https://github.com/adopted-ember-addons/ember-electron/issues/320,
// caused by https://github.com/ember-cli/ember-cli/issues/7431
Object.keys(require.cache).forEach((filename) => {
if (filename.indexOf('fs-extra') !== -1) {
delete require.cache[filename];
}
});

const fs = require('fs-extra');
const path = require('path');
const { all, denodeify } = require('rsvp');

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

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

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

afterInstall(/* options */) {
let logger = new Logger(this);

return this._checkForgeConfig(logger)
.then(() => this._installElectronTooling(logger))
.then(() => this._createResourcesDirectories(logger))
.then(() => this._ensureForgeConfig(logger));
}

_checkForgeConfig(logger) {
const readJson = denodeify(fs.readJson);

let packageJsonPath = path.join(this.project.root, 'package.json');

return readJson(packageJsonPath)
.then((packageJson) => {
let hasForgeConfig = false;
let message;

try {
hasForgeConfig = packageJson.config.forge !== undefined;
} catch(err) {
// no-op
}

this.hasForgeConfig = hasForgeConfig;
message = `Project ${hasForgeConfig ? 'has' : 'needs'} forge config`;

logger.message(message);
});
}

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);
async afterInstall(/* options */) {
this.ui.writeLine(chalk.green('Creating electron-forge project at `./electron`'));

logger.startProgress('Installing 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 api.init({
dir: 'electron',
interactive: true,
template: 'ember-electron/forge/template'
});
await npmInstall.run({
save: true,
verbose: false,
packages: ['electron-protocol-serve@^1.3.0'],
});
logger.message('Installed electron build tools');
}

_createResourcesDirectories(logger) {
const ensureFile = denodeify(fs.ensureFile);

logger.startProgress('Creating ember-electron resource dirs');

let rootDir = this.options.project.root;
let ensureResourceDirGitKeeps = [
'resources',
'resources-darwin',
'resources-linux',
'resources-win32',
]
.map((dirName) => path.join(rootDir, 'ember-electron', dirName))
.map((dirPath) => ensureFile(path.join(dirPath, '.gitkeep')));

return all(ensureResourceDirGitKeeps)
.then(() => logger.message('Created ember-electron resource dirs'));
}

_ensureForgeConfig(logger) {
const readJson = denodeify(fs.readJson);
const writeFile = denodeify(fs.writeFile);
const writeJson = denodeify(fs.writeJson);

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

// 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.
if (this.hasForgeConfig) {
return;
}

logger.startProgress('Extracting ember-electron forge config');

// Move the forge config generated by the import command out of package.json
// and into its own file, updating package.json to point to the file.
return readJson(packageJsonPath)
.then((packageJson) => {
let forgeConfig = packageJson.config.forge;

if (typeof packageJson.config.forge === 'string') {
return;
}

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

packageJson.config.forge = forgeConfigPath;

return all([
writeFile(forgeConfigPath, `module.exports = ${forgeConfig};`),
writeJson(packageJsonPath, packageJson, { spaces: 2 }),
])
.then(() => logger.message('Extracted ember-electron forge config'));
});
}
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-env node */
/* eslint-disable no-console */
const { app, BrowserWindow, protocol } = require('electron');
const { dirname, join, resolve } = require('path');
const protocolServe = require('electron-protocol-serve');
Expand All @@ -21,7 +21,7 @@ else {
protocol.registerStandardSchemes(['serve'], { secure: true });
}
protocolServe({
cwd: join(__dirname || resolve(dirname('')), '..', 'ember'),
cwd: join(__dirname || resolve(dirname('')), '..', 'ember-dist'),
app,
protocol,
});
Expand Down
1 change: 1 addition & 0 deletions forge/files/tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('ember-electron/lib/test-support/test-index');
33 changes: 33 additions & 0 deletions forge/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const denodeify = require('denodeify');
const path = require('path');
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');

module.exports = {
devDependencies: [
'devtron'
],
dependencies: [
'electron-protocol-serve'
],
async initializeTemplate(dir) {
// delete source directory with default files
await rimraf(path.join(dir, 'src'));

// copy our initial content
await ncp(path.join(__dirname, 'files'), dir);

// add our ember build directory to .gitignore
let gitIgnorePath = path.join(dir, '.gitignore');
let contents = await readFile(gitIgnorePath);
await writeFile(gitIgnorePath, [
contents.toString(),
'# Ember build',
`${emberBuildDir}/`,
''
].join('\n'));
}
};
20 changes: 1 addition & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const assembleTree = require('./lib/utils/assemble-tree');

function injectScript(scriptName) {
let dirname = __dirname || process.cwd();
Expand Down Expand Up @@ -32,26 +29,11 @@ module.exports = {
'electron': require('./lib/commands/electron'),
'electron:test': require('./lib/commands/test'),
'electron:build': require('./lib/commands/build'),
'electron:assemble': require('./lib/commands/assemble'),
'electron:package': require('./lib/commands/package'),
'electron:make': require('./lib/commands/make'),
};
},

postprocessTree(type, tree) {
// Check if we're supposed to be assembling as part of the build
if (type === 'all' && process.env.EMBER_CLI_ELECTRON_ASSEMBLE) {
tree = assembleTree({
ui: this.ui,
project: this.project,
platform: process.env.EMBER_CLI_ELECTRON_PLATFORM,
inputNode: tree,
});
}

return tree;
},

contentFor(type) {
const { env: { EMBER_CLI_ELECTRON } } = process;

Expand Down
26 changes: 0 additions & 26 deletions lib/commands/assemble.js

This file was deleted.

53 changes: 53 additions & 0 deletions lib/commands/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

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');
const { electronProjectPath } = require('../utils/build-paths');
const SilentError = require('silent-error');

const upgradeDocumentationUrl = 'https://adopted-ember-addons.github.io/ember-electron/docs/guides/upgrade';

module.exports = Command.extend({
init() {
this._super(...arguments);
Object.assign(this.tasks, {
'Electron': ElectronTask,
'ElectronMake': ElectronMakeTask,
'ElectronPackage': ElectronPackageTask,
'ElectronTestServer': ElectronTestServerTask,
'ElectronTest': ElectronTestTask,
'YarnOrNpm': YarnOrNpmTask
});
},

async prepareRun() {
if (!fs.existsSync(electronProjectPath)) {
return Promise.reject(
new SilentError([
`No './${electronProjectPath}' folder found. This folder must exist and`,
`contain an electron-forge project. It should have been generated by`,
`ember-electron's blueprint when you first ran 'ember install`,
`ember-electron'. If you are upgrading from ember-electron v2, you`,
`should read the upgrade documentation at ${upgradeDocumentationUrl}.`,
].join(' '))
);
}

// Set up the yarn/npm environment variable so forge uses the right package
// manager
await this.runTask('YarnOrNpm');

// Tell our addon that we're building for electron, so it should inject
// shims, etc.
process.env.EMBER_CLI_ELECTRON = true;

await Win.checkIfSymlinksNeedToBeEnabled(this.ui);
}
});
Loading