Skip to content

Commit

Permalink
refactor(importer): use readPackageJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Dec 30, 2016
1 parent 3b54855 commit e000eaf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/electron-forge-import.js
Expand Up @@ -10,6 +10,7 @@ import initGit from './init/init-git';
import { deps, devDeps } from './init/init-npm';

import installDepList from './util/install-dependencies';
import readPackageJSON from './util/read-package-json';

import './util/terminate';

Expand Down Expand Up @@ -47,8 +48,7 @@ const main = async () => {

await initGit(dir);

const packageJSONPath = path.resolve(dir, 'package.json');
let packageJSON = JSON.parse(await fs.readFile(packageJSONPath, 'utf8'));
let packageJSON = await readPackageJSON(dir);
if (packageJSON.config && packageJSON.config.forge) {
console.warn('It looks like this project is already configured for "electron-forge"'.green);
const { shouldContinue } = await inquirer.createPromptModule()({
Expand Down Expand Up @@ -115,7 +115,7 @@ const main = async () => {

const writeChanges = async () => {
const writeSpinner = ora.ora('Writing modified package.json file').start();
await fs.writeFile(packageJSONPath, `${JSON.stringify(packageJSON, null, 2)}\n`);
await fs.writeFile(path.resolve(dir, 'package.json'), `${JSON.stringify(packageJSON, null, 2)}\n`);
writeSpinner.succeed();
};

Expand Down Expand Up @@ -154,10 +154,11 @@ const main = async () => {
installSpinner.succeed();
}

packageJSON = JSON.parse(await fs.readFile(packageJSONPath, 'utf8'));
packageJSON = await readPackageJSON(dir);

packageJSON.config = packageJSON.config || {};
packageJSON.config.forge = JSON.parse(await fs.readFile(path.resolve(__dirname, '../tmpl/package.json'))).config.forge;
const templatePackageJSON = await readPackageJSON(path.resolve(__dirname, '../tmpl'));
packageJSON.config.forge = templatePackageJSON.config.forge;

await writeChanges();

Expand Down

0 comments on commit e000eaf

Please sign in to comment.