Skip to content
Permalink
Browse files

feat(initializer): add userland templates to forge

resolve local templates aswell as global templates, prioritizes global templates
  • Loading branch information
MarshallOfSound authored and malept committed Jan 11, 2017
1 parent 7755ce3 commit bcba06a2045d65c5b68fc2272bfb182699b6970d
Showing with 37 additions and 2 deletions.
  1. +4 −0 package.json
  2. +8 −2 src/init/init-custom.js
  3. +25 −0 test/slow/api_spec_slow.js
@@ -95,6 +95,10 @@
"colors": "^1.1.2",
"commander": "^2.9.0",
"debug": "^2.3.3",
"electron-forge-template-angular2": "^1.0.0",
"electron-forge-template-react": "^1.0.0",
"electron-forge-template-react-typescript": "^1.0.0",
"electron-forge-template-vue": "^1.0.0",
"electron-installer-dmg": "^0.1.2",
"electron-packager": "^8.5.0",
"electron-rebuild": "^1.5.5",
@@ -16,9 +16,15 @@ export default async (dir, template, lintStyle) => {
await asyncOra(`Locating custom template: "${template}"`, async () => {
try {
templateModulePath = await resolvePackage(`electron-forge-template-${template}`);
d('using global template');
} catch (err) {
// eslint-disable-next-line no-throw-literal
throw `Failed to locate custom template: "${template}"\n\nTry \`npm install -g electron-forge-template-${template}\``;
try {
templateModulePath = require(`electron-forge-template-${template}`);
d('using local template');
} catch (err2) {
// eslint-disable-next-line no-throw-literal
throw `Failed to locate custom template: "${template}"\n\nTry \`npm install -g electron-forge-template-${template}\``;
}
}
});

@@ -117,6 +117,31 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
});
});

describe('init (with built-in templater)', () => {
let dir;

before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}`);
dirID += 1;
await fs.remove(dir);
});

it('should succeed in initializing', async () => {
await forge.init({
dir,
template: 'react-typescript',
});
});

it('should add a dependency on react', async () => {
expect(Object.keys(require(path.resolve(dir, 'package.json')).dependencies)).to.contain('react');
});

after(async () => {
await fs.remove(dir);
});
});

describe('after init', () => {
let dir;

0 comments on commit bcba06a

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