Skip to content
Permalink
Browse files

refactor(importer): use readPackageJSON

  • Loading branch information
malept committed Dec 30, 2016
1 parent 3b54855 commit e000eaf1d362d3ddccd2515f0f020e6e0f736f77
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/electron-forge-import.js
@@ -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';

@@ -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()({
@@ -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();
};

@@ -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();

0 comments on commit e000eaf

Please sign in to comment.
You can’t perform that action at this time.