From bcba06a2045d65c5b68fc2272bfb182699b6970d Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 11 Jan 2017 18:42:58 +1100 Subject: [PATCH] feat(initializer): add userland templates to forge resolve local templates aswell as global templates, prioritizes global templates --- package.json | 4 ++++ src/init/init-custom.js | 10 ++++++++-- test/slow/api_spec_slow.js | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0fa668ebfb..bdb2d732d6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/init/init-custom.js b/src/init/init-custom.js index 20b836cdcc..a10c460992 100644 --- a/src/init/init-custom.js +++ b/src/init/init-custom.js @@ -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}\``; + } } }); diff --git a/test/slow/api_spec_slow.js b/test/slow/api_spec_slow.js index 7845e0f43f..914d170d49 100644 --- a/test/slow/api_spec_slow.js +++ b/test/slow/api_spec_slow.js @@ -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;