Skip to content

Commit

Permalink
feat(initializer): add userland templates to forge
Browse files Browse the repository at this point in the history
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 bcba06a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/init/init-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}\``;
}
}
});

Expand Down
25 changes: 25 additions & 0 deletions test/slow/api_spec_slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bcba06a

Please sign in to comment.