Skip to content

ganeshrvel/tutorial-electron-afterpack-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Electron Builder AfterPack configuration

Introduction

There isn't much information available on Electron Builder AfterPack configuration. I have created a sample code which cleans the junk locale directories from the packaged electron app.
I have spent a significant amount of time researching how to get this done. This was originally implemented inside OpenMTP - Advanced Android File Transfer Application for macOS.

Implementation

  • Add the below lines inside your package.json file
"build": {
    "afterPack": "./internals/scripts/AfterPack.js"
}
  • Create a file ./internals/scripts/AfterPack.js and add the below code
'use strict';

const path = require('path');
const glob = require('glob');
const fs = require('fs-extra');

exports.default = context => {
  const lprojRegEx = /(en)\.lproj/g;
  const APP_NAME = context.packager.appInfo.productFilename;
  const APP_OUT_DIR = context.appOutDir;
  const PLATFORM = context.packager.platform.name;

  const cwd = path.join(`${APP_OUT_DIR}`, `${APP_NAME}.app/Contents/Resources`);
  const lproj = glob.sync('*.lproj', { cwd });
  const _promises = [];

  switch (PLATFORM) {
    case 'mac':
      lproj.forEach(dir => {
        if (!lprojRegEx.test(dir)) {
          _promises.push(fs.remove(path.join(cwd, dir)));
        }
      });

      break;
    default:
      break;
  }

  return Promise.all(_promises);
};

Contribute

  • Fork the repo and create your branch from master.
  • Ensure that the changes pass linting.
  • Update the documentation if needed.
  • Make sure your code lints.
  • Issue a pull request!

When you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.

Buy me a coffee

Help me keep the app FREE and open for all. Paypal me: paypal.me/ganeshrvel

Contacts

Please feel free to contact me at ganeshrvel@outlook.com

More repos

License

tutorial-electron-afterpack-script is released under MIT License.

Copyright © 2018-Present Ganesh Rathinavel

Releases

No releases published

Packages

No packages published