Skip to content

Commit

Permalink
fix(importer): adjust Forge config defaults just like in init
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #354
  • Loading branch information
malept committed Nov 10, 2017
1 parent dbc2a4b commit 38f9a3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/api/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from 'path';
import initGit from '../init/init-git';
import { deps, devDeps, exactDevDeps } from '../init/init-npm';

import { setInitialForgeConfig } from '../util/forge-config';
import asyncOra from '../util/ora-handler';
import { info, warn } from '../util/messages';
import installDepList from '../util/install-dependencies';
Expand Down Expand Up @@ -191,6 +192,7 @@ export default async (providedOptions = {}) => {
packageJSON.config = packageJSON.config || {};
const templatePackageJSON = await readPackageJSON(path.resolve(__dirname, '../../tmpl'));
packageJSON.config.forge = templatePackageJSON.config.forge;
setInitialForgeConfig(packageJSON);

await writeChanges();

Expand Down
6 changes: 2 additions & 4 deletions src/init/init-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import fs from 'fs-extra';
import path from 'path';
import username from 'username';

import { setInitialForgeConfig } from '../util/forge-config';
import installDepList from '../util/install-dependencies';
import readPackageJSON from '../util/read-package-json';
import asyncOra from '../util/ora-handler';
import yarnOrNpm from '../util/yarn-or-npm';

const d = debug('electron-forge:init:npm');

Expand All @@ -21,10 +21,8 @@ export default async (dir, lintStyle) => {
await asyncOra('Initializing NPM Module', async () => {
const packageJSON = await readPackageJSON(path.resolve(__dirname, '../../tmpl'));
packageJSON.productName = packageJSON.name = path.basename(dir).toLowerCase();
packageJSON.config.forge.electronWinstallerConfig.name = packageJSON.name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = packageJSON.productName.replace(/-/g, '');
packageJSON.config.forge.electronPackagerConfig.packageManager = yarnOrNpm();
packageJSON.author = await username();
setInitialForgeConfig(packageJSON);

switch (lintStyle) {
case 'standard':
Expand Down
12 changes: 12 additions & 0 deletions src/util/forge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs-extra';
import path from 'path';
import _template from 'lodash.template';
import readPackageJSON from './read-package-json';
import yarnOrNpm from './yarn-or-npm';

const underscoreCase = str => str.replace(/(.)([A-Z][a-z]+)/g, '$1_$2').replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();

Expand Down Expand Up @@ -37,6 +38,17 @@ const proxify = (object, envPrefix) => {
});
};

/**
* Sets sensible defaults for the `config.forge` object.
*/
export function setInitialForgeConfig(packageJSON) {
/* eslint-disable no-param-reassign */
packageJSON.config.forge.electronWinstallerConfig.name = packageJSON.name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = packageJSON.productName.replace(/-/g, '');
packageJSON.config.forge.electronPackagerConfig.packageManager = yarnOrNpm();
/* eslint-enable no-param-reassign */
}

export default async (dir) => {
const packageJSON = await readPackageJSON(dir);
let forgeConfig = packageJSON.config.forge;
Expand Down

0 comments on commit 38f9a3d

Please sign in to comment.