chore: make templates work in v6
This commit is contained in:
Родитель
cddfb1f581
Коммит
22549d9293
|
@ -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,4 +1,4 @@
|
|||
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';
|
||||
|
@ -6,7 +6,9 @@ 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,7 +43,7 @@ export default async (dir: string, template: string) => {
|
|||
}
|
||||
});
|
||||
|
||||
let templateModule = require(templateModulePath);
|
||||
let templateModule: PossibleModule<ForgeTemplate> = require(templateModulePath);
|
||||
|
||||
templateModule = templateModule.default || templateModule;
|
||||
|
||||
|
@ -49,7 +51,7 @@ export default async (dir: string, template: string) => {
|
|||
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,13 +3,23 @@ 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();
|
||||
|
@ -17,12 +27,12 @@ export default async (
|
|||
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,6 +11,7 @@
|
|||
"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"
|
||||
|
@ -18,4 +19,4 @@
|
|||
"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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче