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

Use babel-preset-env in 'init' #47

Merged
merged 1 commit into from
Jan 2, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/electron-forge-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const main = async () => {

await initDirectory(dir);
await initGit(dir);
await initNPM(dir, program.template ? undefined : program.lintstyle);
await initStarter(dir, program.template ? undefined : program.lintstyle);
await initNPM(dir, program.template ? undefined : program.lintstyle);
Copy link
Member

Choose a reason for hiding this comment

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

Was moving this call intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we have to have .compilerc laid down before we can edit it

if (!program.template) {
if (program.lintstyle === 'standard') {
await initStandardFix(dir);
Expand Down
19 changes: 18 additions & 1 deletion src/init/init-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import asyncOra from '../util/ora-handler';
const d = debug('electron-forge:init:npm');

export const deps = ['electron-compile'];
export const devDeps = ['babel-preset-stage-0'];
export const devDeps = ['babel-preset-env', 'babel-preset-react', 'babel-plugin-transform-async-to-generator'];
export const exactDevDeps = ['electron-prebuilt-compile'];
export const standardDeps = ['standard'];
export const airbnDeps = ['eslint', 'eslint-config-airbnb', 'eslint-plugin-import',
Expand All @@ -22,6 +22,7 @@ export default async (dir, lintStyle) => {
packageJSON.productName = packageJSON.name = path.basename(dir).toLowerCase();
packageJSON.config.forge.electronWinstallerConfig.name = packageJSON.name.replace(/-/g, '_');
packageJSON.author = await username();

switch (lintStyle) {
case 'standard':
packageJSON.scripts.lint = 'standard';
Expand All @@ -40,12 +41,15 @@ export default async (dir, lintStyle) => {
await asyncOra('Installing NPM Dependencies', async () => {
d('installing dependencies');
await installDepList(dir, deps);

d('installing devDependencies');
await installDepList(dir, devDeps, true);

d('installing exact dependencies');
for (const packageName of exactDevDeps) {
await installDepList(dir, [packageName], true, true);
}

switch (lintStyle) {
case 'standard':
d('installing standard linting dependencies');
Expand All @@ -59,5 +63,18 @@ export default async (dir, lintStyle) => {
d('not installing linting deps');
break;
}

// NB: For babel-preset-env to work correctly, it needs to know the
// actual version of Electron that we installed
const content = JSON.parse(await fs.readFile(path.join(dir, '.compilerc'), 'utf8'));
const electronPrebuilt = require(
path.join(dir, 'node_modules', 'electron-prebuilt-compile', 'package.json'));

for (const profile of ['development', 'production']) {
const envTarget = content.env[profile]['application/javascript'].presets.find(x => x[0] === 'env');
envTarget[1].targets.electron = electronPrebuilt.version;
}

await fs.writeFile(path.join(dir, '.compilerc'), JSON.stringify(content, null, 2), 'utf8');
});
};
2 changes: 1 addition & 1 deletion src/init/init-starter-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async (dir, lintStyle) => {

d('creating directory:', path.resolve(dir, 'src'));
await fs.mkdirs(path.resolve(dir, 'src'));
const rootFiles = ['_gitignore'];
const rootFiles = ['_gitignore', '_compilerc'];
if (lintStyle === 'airbnb') rootFiles.push('_eslintrc');
const srcFiles = ['index.js', 'index.html'];

Expand Down
24 changes: 24 additions & 0 deletions tmpl/_compilerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"development": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": "1.4.0" } }],
"react"
],
"plugins": ["transform-async-to-generator"],
"sourceMaps": "inline"
}
},
"production": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": "1.4.0" } }],
"react"
],
"plugins": ["transform-async-to-generator"],
"sourceMaps": "none"
}
}
}
}