Skip to content
Permalink
Browse files

refactor(template-webpack): extract copy template file function

  • Loading branch information
malept committed Jul 15, 2019
1 parent d70ae5c commit cd63874442bc7d0d295c623213788c4266444b84
Showing with 22 additions and 5 deletions.
  1. +13 −1 packages/api/core/test/slow/api_spec_slow.ts
  2. +9 −4 packages/template/webpack/src/WebpackTemplate.ts
@@ -104,7 +104,7 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {
});
});

describe('init (with built-in templater)', () => {
describe.only('init (with built-in templater)', () => {
before(ensureTestDirIsNonexistent);

it('should succeed in initializing', async () => {
@@ -125,6 +125,18 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {
expect(Object.keys(require(path.resolve(dir, 'package.json')).devDependencies)).to.contain('@electron-forge/plugin-webpack');
});

it('should copy the appropriate template files', async () => {
const expectedFiles = [
'webpack.main.config.js',
'webpack.renderer.config.js',
'webpack.rules.js',
path.join('src', 'renderer.js'),
];
for (const filename of expectedFiles) {
await expectProjectPathExists(filename, 'file');
}
});

after(async () => {
await fs.remove(dir);
});
@@ -6,6 +6,11 @@ import path from 'path';

const currentVersion = require('../package').version;

const copyTemplateFile = async (destDir: string, basename: string) => {
const templateDir = path.resolve(__dirname, '..', 'tmpl');
await fs.copy(path.join(templateDir, basename), path.resolve(destDir, basename));
}

class WebpackTemplate implements ForgeTemplate {
public devDependencies = [
`@electron-forge/plugin-webpack@${currentVersion}`,
@@ -41,10 +46,10 @@ class WebpackTemplate implements ForgeTemplate {
});
});
await asyncOra('Setting up webpack configuration', async () => {
await fs.copy(path.resolve(__dirname, '..', 'tmpl', 'webpack.main.config.js'), path.resolve(directory, 'webpack.main.config.js'));
await fs.copy(path.resolve(__dirname, '..', 'tmpl', 'webpack.renderer.config.js'), path.resolve(directory, 'webpack.renderer.config.js'));
await fs.copy(path.resolve(__dirname, '..', 'tmpl', 'webpack.rules.js'), path.resolve(directory, 'webpack.rules.js'));
await fs.copy(path.resolve(__dirname, '..', 'tmpl', 'renderer.js'), path.resolve(directory, 'src', 'renderer.js'));
await copyTemplateFile(directory, 'webpack.main.config.js');
await copyTemplateFile(directory, 'webpack.renderer.config.js');
await copyTemplateFile(directory, 'webpack.rules.js');
await copyTemplateFile(path.join(directory, 'src'), 'renderer.js');
let indexContents = await fs.readFile(path.resolve(directory, 'src', 'index.js'), 'utf8');
indexContents = indexContents.split('\n').map((line) => {
if (line.includes('mainWindow.loadURL')) return ' mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);';

0 comments on commit cd63874

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