Skip to content

Commit

Permalink
Install npm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpogi5 committed May 13, 2020
1 parent c8a604c commit 8ffa2eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', '/tests/__helpers'],
testPathIgnorePatterns: [
'/node_modules/',
'/tests/__helpers',
'/hello-world/',
],
collectCoverage: true,
coverageReporters: ['lcov'],
collectCoverageFrom: ['src/**/*.js'],
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import execa from 'execa';

import pkg from './pkg';
import CONFIG_FILES from './configs';
import NPM_PACKAGES from './packages';

const PKG_DIR = __dirname;

Expand All @@ -19,7 +20,9 @@ const run = async ({ packageName }) => {

// npm commands
await execa('npm', ['init', '-y']);
// await execa('npm', ['i', '-D', ...NPM_PACKAGES]);
const npmProc = execa('npm', ['i', '-D', ...NPM_PACKAGES]);
const { stdout: npmInstall } = await npmProc;
console.log('npm install output:', npmInstall);

// copy config
CONFIG_FILES.forEach((c) => {
Expand Down
21 changes: 21 additions & 0 deletions src/packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const NPM_PACKAGES = [
'@babel/core',
'@babel/cli',
'@babel/preset-env',
'eslint',
'prettier',
'babel-eslint',
'eslint-plugin-import',
'eslint-plugin-prettier',
'eslint-config-airbnb-base',
'eslint-config-prettier',
'husky',
'lint-staged',
'pretty-quick',
'jest',
'babel-jest',
'@babel/plugin-transform-runtime',
'@types/jest',
];

export default NPM_PACKAGES;
8 changes: 7 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import fse from 'fs-extra';
import run from '../src';
import CONFIG_FILES from '../src/configs';
import NPM_PACKAGES from '../src/packages';

const PKG_NAME = 'hello-world';
const ROOT_DIR = process.cwd();
Expand All @@ -17,7 +18,8 @@ describe('Create NodeJs', () => {
});

it('should run', async () => {
expect.assertions(7 + CONFIG_FILES.length);
jest.setTimeout(60000);
expect.assertions(7 + CONFIG_FILES.length + NPM_PACKAGES.length);
try {
await run({ packageName: 'hello-world' });
expect(fs.existsSync(PKG_DIR)).toBe(true);
Expand All @@ -34,6 +36,10 @@ describe('Create NodeJs', () => {
expect(pkg.license).toBe('MIT');
expect(pkg.author.name).toBe('Ian Dela Cruz');
expect(pkg.author.email).toBe('[email protected]');

NPM_PACKAGES.forEach((c) => {
expect(pkg.devDependencies).toHaveProperty(c);
});
} catch (error) {
// console.log(error);
expect(error).toBe(null);
Expand Down

0 comments on commit 8ffa2eb

Please sign in to comment.