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

electron-forge import #20

Merged
merged 15 commits into from
Dec 30, 2016
Merged

electron-forge import #20

merged 15 commits into from
Dec 30, 2016

Conversation

MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Dec 14, 2016

This adds a command that (at least in my testing) semi-automates the transition from other build tooling (gulp, babel, -builder, Etc.) to electron-forge. Currently it:

  • Asks to change the main pointer of the package.json file
  • Imports existing babel config to the .compilerc
  • Warns about the slight change in usage of the preload property
  • Adds the electron-forge output directory to the gitignore
  • Adds the template forge config to their package.json
  • Removes electron and electron-prebuilt and replaces them with electron-prebuilt-compile
  • Installs dependencies like electron-compile
  • Prunes no longer required modules

It does all this while warning the user that we will be writing to their files and in certain steps asking if we are doing the right thing.

This command isn't complete yet (I probably want import other configs like LESS and such if they exist) and I need to do some testing. But as an example when I ran this against my rather complex GPMDP and then ran electron-forge start it launched correctly 👍

Just looking for initial feedback and maybe some enhancements to the import process.

/cc @paulcbetts because you seemed quite keen for this 😆

TODO

  • Should prompt (and automate) replacement of electron with electron-prebuild-compile
  • Should prompt (and automate) the installation of electron-compile as dependency
  • Should prompt (and automate) the installation of linting tools if none are present (no longer doing this because of Support for custom template directories #35)
  • Should prompt the user to remove existing build tooling (babel, Electron Packager, etc.)

@MarshallOfSound MarshallOfSound changed the title Import electron-forge import Dec 14, 2016
const pruneSpinner = ora.ora('Pruning deleted modules').start();
await new Promise((resolve) => {
d('attempting to prune node_modules in:', dir);
const child = yarnOrNPMSpawn(hasYarn() ? [] : ['prune'], {
Copy link
Member

Choose a reason for hiding this comment

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

Ugh. I was hoping to avoid command specific behavior when implementing electron/packager#518 but I guess I'll have to do it.


await pify(rimraf)(path.resolve(dir, 'node_modules/.bin/electron'));
await pify(rimraf)(path.resolve(dir, 'node_modules/.bin/electron.cmd'));
await pify(rimraf)(path.resolve(dir, 'node_modules', electronName));
Copy link
Member

Choose a reason for hiding this comment

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

It occurs to me that we can replace rimraf calls with fs.remove since fs-promise uses fs-extra. But that can be for another PR.

const { shouldChangeMain } = await inquirer.createPromptModule()({
type: 'confirm',
name: 'shouldChangeMain',
message: 'Do you want us to change the "main" attribute of your package.json? If you are currently using babel and pointint to a "build" directory say yes.', // eslint-disable-line
Copy link
Member

Choose a reason for hiding this comment

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

pointing

' "electron-prebuilt-compile" '.cyan +
'dependency. This is the dependency you must version bump to get newer versions of Electron.\n\n' +
'We also tried to import any build tooling you already had but we can\'t get everything. You might need to convert any CLI/gulp/grunt tasks yourself.\n\n' +
'Thanks for using ' + 'electron-forge'.green + '!!!');
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this should be a multi-line templated string (if that works). Not a big fan of the +s and backslashes.

@@ -24,7 +24,7 @@ const main = async () => {
dir = path.resolve(dir, cwd);
}
})
.parse(process.argv);
.parse(process.argv.slice(0, 2));
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only parse the first two args (electron-forge and start, all the rest should be ignored or the CLI fails 😢

Copy link
Member

Choose a reason for hiding this comment

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

Ah. I completely missed the part below this where you take the rest of the arguments and pass them directly to electron.

packageJSON.scripts.lint = 'eslint src';
break;
default:
packageJSON.scripts.lint = 'echo "No linting yet..."';
Copy link
Member

Choose a reason for hiding this comment

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

"No linting configured"?

@malept
Copy link
Member

malept commented Dec 16, 2016

Is the last thing that's missing "remove Electron Packager and other existing build tools from (dev)Dependencies"?

@MarshallOfSound
Copy link
Member Author

@malept Pretty much yes.

Currently blocked though by electron-compile's usage of debug and debug not working well in a preload script. Upstream PR can be found here

debug-js/debug#377

@malept malept added the blocked/upstream Issues blocked by upstream bugs label Dec 17, 2016
@anaisbetts
Copy link
Contributor

@MarshallOfSound I fixed this in the latest version

@MarshallOfSound
Copy link
Member Author

/cc @malept There are a few bonus features in this PR now that seemed to be required for some projects to move over to electron-forge completely. In particular the --targets argument to the make command.

const bins = await pify(glob)(path.join(buildPath, '**/.bin/**/*'));
for (const bin of bins) {
await fs.remove(bin);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm probably missing something, but can we use --no-bin-links when yarn install is run?

Copy link
Member Author

Choose a reason for hiding this comment

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

What about during development or if users run yarn manually?

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm. Good point. For some reason I thought that Electron Packager ran npm install but it was just for its tests.

@MarshallOfSound MarshallOfSound removed the blocked/upstream Issues blocked by upstream bugs label Dec 28, 2016
@malept
Copy link
Member

malept commented Dec 28, 2016

I added automatic removal of all known Electron build tools from package.json, but I guess we should probably list them and confirm with the user before doing so?

@MarshallOfSound
Copy link
Member Author

@malept Probably should prompt for each removal to be sure 👍, maybe with an brief explanation as to how -forge replaces it.

@malept malept merged commit 2cc94aa into master Dec 30, 2016
@malept malept deleted the import branch December 30, 2016 03:50
dsanders11 pushed a commit that referenced this pull request Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants