Skip to content
Permalink
Browse files

chore: make templates work in v6

  • Loading branch information
MarshallOfSound committed Oct 22, 2018
1 parent cddfb1f commit 22549d9293431515d7247577d05082d5e0a8d481
@@ -8,7 +8,7 @@ import { deps, devDeps, exactDevDeps } from './init-scripts/init-npm';

import { setInitialForgeConfig } from '../util/forge-config';
import { info, warn } from '../util/messages';
import installDepList from '../util/install-dependencies';
import installDepList, { DepType, DepVersionRestriction } from '../util/install-dependencies';
import { readRawPackageJson } from '../util/read-package-json';

const d = debug('electron-forge:import');
@@ -155,10 +155,10 @@ export default async ({
await installDepList(dir, deps);

d('installing devDependencies');
await installDepList(dir, devDeps, true);
await installDepList(dir, devDeps, DepType.DEV);

d('installing exactDevDependencies');
await installDepList(dir, exactDevDeps, true, true);
await installDepList(dir, exactDevDeps, DepType.DEV, DepVersionRestriction.EXACT);
});

packageJSON = await readRawPackageJson(dir);
@@ -1,12 +1,14 @@
import { asyncOra, ora } from '@electron-forge/async-ora';
import { asyncOra } from '@electron-forge/async-ora';
import debug from 'debug';
import fs from 'fs-extra';
import glob from 'glob';
import resolvePackage from 'resolve-package';
import path from 'path';

import { copy } from './init-starter-files';
import installDepList from '../../util/install-dependencies';
import installDepList, { DepType } from '../../util/install-dependencies';
import { PossibleModule } from '../../util/require-search';
import { ForgeTemplate } from '@electron-forge/shared-types';

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

@@ -41,15 +43,15 @@ export default async (dir: string, template: string) => {
}
});

let templateModule = require(templateModulePath);
let templateModule: PossibleModule<ForgeTemplate> = require(templateModulePath);

templateModule = templateModule.default || templateModule;

await asyncOra('Installing Template Dependencies', async () => {
d('installing dependencies');
await installDepList(dir, templateModule.dependencies || []);
d('installing devDependencies');
await installDepList(dir, templateModule.devDependencies || [], true);
await installDepList(dir, templateModule.devDependencies || [], DepType.DEV);
});

await asyncOra('Copying Template Files', async () => {
@@ -71,6 +73,6 @@ export default async (dir: string, template: string) => {
});

if (typeof templateModule.postCopy === 'function') {
await Promise.resolve(templateModule.postCopy(dir, ora));
await Promise.resolve(templateModule.postCopy(dir));
}
};
@@ -5,7 +5,7 @@ import path from 'path';
import username from 'username';

import { setInitialForgeConfig } from '../../util/forge-config';
import installDepList from '../../util/install-dependencies';
import installDepList, { DepType, DepVersionRestriction } from '../../util/install-dependencies';
import { readRawPackageJson } from '../../util/read-package-json';

const d = debug('electron-forge:init:npm');
@@ -43,11 +43,11 @@ export default async (dir: string) => {
await installDepList(dir, deps);

d('installing devDependencies');
await installDepList(dir, devDeps, true);
await installDepList(dir, devDeps, DepType.DEV);

d('installing exact dependencies');
d('installing exact devDependencies');
for (const packageName of exactDevDeps) {
await installDepList(dir, [packageName], true, true);
await installDepList(dir, [packageName], DepType.DEV, DepVersionRestriction.EXACT);
}
});
};
@@ -3,26 +3,36 @@ import { yarnOrNpmSpawn, hasYarn } from './yarn-or-npm';

const d = debug('electron-forge:dependency-installer');

export enum DepType {
PROD = 'PROD',
DEV = 'DEV',
}

export enum DepVersionRestriction {
EXACT = 'EXACT',
RANGE = 'RANGE',
}

export default async (
dir: string,
deps: string[],
areDev = false,
exact = false,
depType = DepType.PROD,
versionRestriction = DepVersionRestriction.RANGE,
) => {
d('installing', JSON.stringify(deps), 'in:', dir, `dev=${areDev},exact=${exact},withYarn=${hasYarn()}`);
d('installing', JSON.stringify(deps), 'in:', dir, `depType=${depType},versionRestriction=${versionRestriction},withYarn=${hasYarn()}`);
if (deps.length === 0) {
d('nothing to install, stopping immediately');
return Promise.resolve();
}
let cmd = ['install'].concat(deps);
if (hasYarn()) {
cmd = ['add'].concat(deps);
if (areDev) cmd.push('--dev');
if (exact) cmd.push('--exact');
if (depType === DepType.DEV) cmd.push('--dev');
if (versionRestriction === DepVersionRestriction.EXACT) cmd.push('--exact');
} else {
if (exact) cmd.push('--save-exact');
if (areDev) cmd.push('--save-dev');
if (!areDev) cmd.push('--save');
if (versionRestriction === DepVersionRestriction.EXACT) cmd.push('--save-exact');
if (depType === DepType.DEV) cmd.push('--save-dev');
if (depType === DepType.PROD) cmd.push('--save');
}
d('executing', JSON.stringify(cmd), 'in:', dir);
try {
@@ -2,7 +2,7 @@ import { expect } from 'chai';
import proxyquire from 'proxyquire';
import sinon, { SinonStub } from 'sinon';

import installDependencies from '../../src/util/install-dependencies';
import installDependencies, { DepType, DepVersionRestriction } from '../../src/util/install-dependencies';

describe('Install dependencies', () => {
let install: typeof installDependencies;
@@ -58,17 +58,17 @@ describe('Install dependencies', () => {
});

it('should install dev deps', () => {
install('mydir', ['eslint'], true);
install('mydir', ['eslint'], DepType.DEV);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['add', 'eslint', '--dev']);
});

it('should install exact deps', () => {
install('mydir', ['react-dom'], false, true);
install('mydir', ['react-dom'], DepType.PROD, DepVersionRestriction.EXACT);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['add', 'react-dom', '--exact']);
});

it('should install exact dev deps', () => {
install('mydir', ['mocha'], true, true);
install('mydir', ['mocha'], DepType.DEV, DepVersionRestriction.EXACT);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['add', 'mocha', '--dev', '--exact']);
});
});
@@ -84,17 +84,17 @@ describe('Install dependencies', () => {
});

it('should install dev deps', () => {
install('mydir', ['eslint'], true);
install('mydir', ['eslint'], DepType.DEV);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['install', 'eslint', '--save-dev']);
});

it('should install exact deps', () => {
install('mydir', ['react-dom'], false, true);
install('mydir', ['react-dom'], DepType.PROD, DepVersionRestriction.EXACT);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['install', 'react-dom', '--save-exact', '--save']);
});

it('should install exact dev deps', () => {
install('mydir', ['mocha'], true, true);
install('mydir', ['mocha'], DepType.DEV, DepVersionRestriction.EXACT);
expect(spawnSpy.firstCall.args[0]).to.be.deep.equal(['install', 'mocha', '--save-exact', '--save-dev']);
});
});
@@ -11,11 +11,12 @@
"test": "echo No Tests For Shared Types"
},
"dependencies": {
"@electron-forge/async-ora": "^6.0.0-beta.29",
"@types/electron-packager": "^12.0.0",
"electron-rebuild": "^1.6.0",
"ora": "^3.0.0"
},
"engines": {
"node": ">= 6.0"
}
}
}
@@ -1,5 +1,4 @@
/* tslint:disable ter-indent */

import { OraImpl } from '@electron-forge/async-ora';
import { ChildProcess } from 'child_process';
import { Options } from 'electron-packager';
import { RebuildOptions } from 'electron-rebuild/lib/src/rebuild';
@@ -116,3 +115,10 @@ export interface StartOptions {
*/
inspect?: boolean;
}

export interface ForgeTemplate {
dependencies?: string[];
devDependencies?: string[];
templateDirectory?: string;
postCopy?: (dir: string) => void;
}

0 comments on commit 22549d9

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