Skip to content
Permalink
Browse files

feat(initializer): only copy CI files if specified

  • Loading branch information
malept committed Aug 21, 2017
1 parent 296bdde commit fd6f2f9b48ef3bf58dc09a6b05b3cd0f864ebf3b
Showing with 53 additions and 48 deletions.
  1. +3 −0 README.md
  2. +3 −2 src/api/init.js
  3. +2 −0 src/electron-forge-init.js
  4. +3 −2 src/init/init-starter-files.js
  5. +42 −44 test/slow/api_spec_slow.js
@@ -79,6 +79,9 @@ You can also start a project with your
[favorite framework](https://electronforge.io/templates) with the `--template`
argument. E.g. `--template=react`.

If you'd like to have pre-made configuration files for Travis CI and AppVeyor CI to automatically
build and deploy distributables to GitHub, use the `--copy-ci-files` argument.

## Importing an existing Project

```bash
@@ -27,10 +27,11 @@ const d = debug('electron-forge:init');
*/
export default async (providedOptions = {}) => {
// eslint-disable-next-line prefer-const, no-unused-vars
let { dir, interactive, lintstyle, template } = Object.assign({
let { dir, interactive, lintstyle, copycifiles, template } = Object.assign({
dir: process.cwd(),
interactive: false,
lintstyle: 'airbnb',
copycifiles: false,
template: null,
}, providedOptions);
asyncOra.interactive = interactive;
@@ -47,7 +48,7 @@ export default async (providedOptions = {}) => {

await initDirectory(dir, interactive);
await initGit(dir);
await initStarter(dir, template ? undefined : lintstyle);
await initStarter(dir, { lintStyle: template ? undefined : lintstyle, copyCIFiles: copycifiles });
await initNPM(dir, template ? undefined : lintstyle);
if (!template) {
if (lintstyle === 'standard') {
@@ -11,6 +11,7 @@ import { init } from './api';
.arguments('[name]')
.option('-t, --template [name]', 'Name of the forge template to use')
.option('-l, --lintstyle [style]', 'Linting standard to follow. For the default template it can be "airbnb" or "standard"', 'airbnb')
.option('-c, --copy-ci-files', 'Whether to copy the templated CI files (defaults to false)', false)
.action((name) => {
if (!name) return;
if (path.isAbsolute(name)) {
@@ -25,6 +26,7 @@ import { init } from './api';
dir,
interactive: true,
lintstyle: program.lintstyle,
copycifiles: !!program.copyCiFiles,
};
if (program.template) initOpts.template = program.template;

@@ -11,13 +11,14 @@ export const copy = async (source, target) => {
await fs.copy(source, target);
};

export default async (dir, lintStyle) => {
export default async (dir, { lintStyle, copyCIFiles }) => {
await asyncOra('Copying Starter Files', async () => {
const tmplPath = path.resolve(__dirname, '../../tmpl');

d('creating directory:', path.resolve(dir, 'src'));
await fs.mkdirs(path.resolve(dir, 'src'));
const rootFiles = ['_gitignore', '_compilerc', '_travis.yml', '_appveyor.yml'];
const rootFiles = ['_gitignore', '_compilerc'];
if (copyCIFiles) rootFiles.push(...['_travis.yml', '_appveyor.yml']);
if (lintStyle === 'airbnb') rootFiles.push('_eslintrc');
const srcFiles = ['index.js', 'index.html'];

@@ -17,40 +17,51 @@ const forge = proxyquire.noCallThru().load('../../src/api', {
});

describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
let dir;
let dirID = Date.now();

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

const beforeInitTest = (params, beforeInit) => {
before(async () => {
await ensureTestDirIsNonexistent();
if (beforeInit) {
beforeInit();
}
await forge.init(Object.assign({}, params, { dir }));
});
};

const expectProjectPathExists = async (subPath, pathType) => {
expect(await fs.pathExists(path.resolve(dir, subPath)), `the ${subPath} ${pathType} should exist`).to.equal(true);
};

const forLintingMethod = (lintStyle) => {
describe(`init (with lintStyle=${lintStyle})`, () => {
let dir;

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

it('should create a new folder with a npm module inside', async () => {
expect(await fs.pathExists(dir), 'the target dir should have been created').to.equal(true);
for (const filename of ['package.json', '.travis.yml', '.appveyor.yml']) {
expect(await fs.pathExists(path.resolve(dir, filename)), `the ${filename} file should exist`).to.equal(true);
}
expectProjectPathExists('package.json', 'file');
});

it('should have initialized a git repository', async () => {
expect(await fs.pathExists(path.resolve(dir, '.git')), 'the .git folder should exist').to.equal(true);
expectProjectPathExists('.git', 'folder');
});

it('should have installed the initial node_modules', async () => {
expect(await fs.pathExists(path.resolve(dir, 'node_modules')), 'node_modules folder should exist').to.equal(true);
expectProjectPathExists('node_modules', 'folder');
expect(await fs.pathExists(path.resolve(dir, 'node_modules/electron-prebuilt-compile')), 'electron-prebuilt-compile should exist').to.equal(true);
expect(await fs.pathExists(path.resolve(dir, 'node_modules/babel-core')), 'babel-core should exist').to.equal(true);
expect(await fs.pathExists(path.resolve(dir, 'node_modules/electron-forge')), 'electron-forge should exist').to.equal(true);
});

it('should have set the .compilerc electron version to be a float', async () => {
expectProjectPathExists('.compilerc', 'file');
const compilerc = JSON.parse(await fs.readFile(path.resolve(dir, '.compilerc')));
expect(compilerc.env.development['application/javascript'].presets[0][1].targets.electron).to.be.a('number');
});
@@ -65,29 +76,30 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
forLintingMethod('airbnb');
forLintingMethod('standard');

describe('init (with custom templater)', () => {
let dir;
describe('init with CI files enabled', () => {
beforeInitTest({ copycifiles: true });

before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}`);
dirID += 1;
await fs.remove(dir);
it('should copy over the CI config files correctly', async () => {
expect(await fs.pathExists(dir), 'the target dir should have been created').to.equal(true);
expectProjectPathExists('.appveyor.yml', 'file');
expectProjectPathExists('.travis.yml', 'file');
});
});

describe('init (with custom templater)', () => {
beforeInitTest({ template: 'dummy' }, () => {
execSync('npm link', {
cwd: path.resolve(__dirname, '../fixture/custom_init'),
});
await forge.init({
dir,
template: 'dummy',
});
});

it('should create dot files correctly', async () => {
expect(await fs.pathExists(dir), 'the target dir should have been created').to.equal(true);
expect(await fs.pathExists(path.resolve(dir, '.bar')), 'the .bar file should exist').to.equal(true);
expectProjectPathExists('.bar', 'file');
});

it('should create deep files correctly', async () => {
expect(await fs.pathExists(path.resolve(dir, 'src/foo.js')), 'the src/foo.js file should exist').to.equal(true);
expectProjectPathExists('src/foo.js', 'file');
});

describe('lint', () => {
@@ -103,13 +115,7 @@ describe(`electron-forge API (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);
});
before(ensureTestDirIsNonexistent);

it('should succeed in initializing', async () => {
await forge.init({
@@ -135,13 +141,7 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
});

describe('init (with a nonexistent templater)', () => {
let dir;

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

it('should fail in initializing', async () => {
await expect(forge.init({
@@ -156,8 +156,6 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
});

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

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

0 comments on commit fd6f2f9

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