Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ bundle.js.map
bundle.js
index.html
build
build/bundle.js.gz
build/bundle.js.gz
standard
git
yarn
skip
npm
travis
yarn-skip
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ script:
- npm run webpack;
- npm run coveralls;
- npm run bundlesize;
- node build-index.js my-app -f;
- cd my-app;
- npm test;
- npm run webpack;
- cd ..;
- ./scripts/travis-install.sh
- create-react-matt hello-world -f;
- cd hello-world;
Expand Down
5 changes: 5 additions & 0 deletions build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ program.arguments("<folder>").option("-y, --yarn", "Use yarn").option("-t, --tra
_context3.prev = 16;
_context3.t0 = _context3["catch"](8);

// eslint-disable-next-line no-console
console.log(_context3.t0);
throw _context3.t0;

Expand Down Expand Up @@ -355,13 +356,15 @@ program.arguments("<folder>").option("-y, --yarn", "Use yarn").option("-t, --tra
}
fs.writeFile(filename, content, function (error) {
if (error) {
// eslint-disable-next-line no-console
console.log(error);
reject(error);
} else {
resolve();
}
});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
reject(error);
}
Expand Down Expand Up @@ -466,8 +469,10 @@ program.arguments("<folder>").option("-y, --yarn", "Use yarn").option("-t, --tra
_context5.t0 = _context5["catch"](7);

if (!_context5.t0.message.indexOf("File exists")) {
// eslint-disable-next-line no-console
console.error("Something went wrong, sorry");
} else if (_context5.t0.message.indexOf("File exists") !== -1) {
// eslint-disable-next-line no-console
console.error("You need to delete " + folder + ", or run again with -f");
}

Expand Down
8 changes: 8 additions & 0 deletions index-tests/git.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { executeBashFunction, doesFileExist } from "./utils";

test("When passing -g, .gitignore should be created", async () => {
const folder = "git";
await executeBashFunction(`node index.js ${folder} -s -g`);
const result = await doesFileExist(`${folder}/.gitignore`);
expect(result).toBeTruthy();
});
11 changes: 11 additions & 0 deletions index-tests/npm.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { executeBashFunction, executeBuild, doesFileExist } from "./utils";

test("using npm", async () => {
const folder = "npm";
await executeBashFunction(`node index.js ${folder}`);
await executeBuild(folder);
const doesPackageLockExist = await doesFileExist(`${folder}/package-lock.json`);
expect(doesPackageLockExist).toBeTruthy();
});


8 changes: 8 additions & 0 deletions index-tests/skip.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { executeBashFunction, doesFileExist } from "./utils";

test("When passing -s, node_modules shouldn't be installed", async () => {
const folder = "skip";
await executeBashFunction(`node index.js ${folder} -s`);
const result = await doesFileExist(`${folder}/node_modules`);
expect(result).not.toBeTruthy();
});
8 changes: 8 additions & 0 deletions index-tests/travis.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { executeBashFunction, doesFileExist } from "./utils";

test("When passing -t, .travis.yml should be created", async () => {
const folder = "travis";
await executeBashFunction(`node index.js ${folder} -s -t`);
const result = await doesFileExist(`${folder}/.travis.yml`);
expect(result).toBeTruthy();
});
33 changes: 33 additions & 0 deletions index-tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { exec } = require("child_process");
const fs = require("fs-extra");

const executeFunction = func => {
return new Promise((resolve, reject) => {
try {
func((error, output) => {
if (error) {
reject(error);
} else {
resolve(output);
}
});
} catch (error) {
reject(error);
}
});
};
export const executeBashFunction = command => {
return executeFunction(callback => exec(command, callback));
};
export const executeBuild = folder => {
return executeBashFunction(`cd ${folder} && npm test && npm run webpack && npm run bundlesize`);
};

export const doesFileExist = async path => {
try {
return await executeFunction(callback => fs.stat(path, callback));
} catch (error) {
return false;
}

};
18 changes: 18 additions & 0 deletions index-tests/yarn.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { executeBashFunction, executeBuild, doesFileExist } from "./utils";

test.skip("when passing -y, yarn should be used.", async () => {
const folder = "yarn";
await executeBashFunction(`node index.js ${folder} -y`);
await executeBuild(folder);
const doesYarnLockExist = await doesFileExist(`${folder}/yarn.lock`);
expect(doesYarnLockExist).toBeTruthy();
});

test.skip("When skipping installation, node_modules should not be there", async () => {
const folder = "yarn-skip";
await executeBashFunction(`node index.js ${folder} -y -s`);
const doesNodeModulesExist = await doesFileExist(`${folder}/node_modules`);
expect(doesNodeModulesExist).toBeTruthy();
});


5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ program
await fixPackageJson();
} catch (error) {
if (!error.message.indexOf("File exists")) {
// eslint-disable-next-line no-console
console.error("Something went wrong, sorry");
} else if (error.message.indexOf("File exists") !== -1) {
// eslint-disable-next-line no-console
console.error(`You need to delete ${folder}, or run again with -f`);
}
}
Expand Down Expand Up @@ -236,6 +238,7 @@ npm-debug.log`;
const file = await readFile(`./${f}`);
await writeFile(`${folder}/${f}`, file);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
throw e;
}
Expand Down Expand Up @@ -301,13 +304,15 @@ script:
}
fs.writeFile(filename, content, error => {
if (error) {
// eslint-disable-next-line no-console
console.log(error);
reject(error);
} else {
resolve();
}
});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
reject(error);
}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"scripts": {
"analyze-bundle": "export ANALYZE_BUNDLE=true && npm run webpack",
"start": "export NODE_ENV=development && webpack-dev-server",
"linter": "eslint index.js && eslint src --ext .js,.jsx && eslint test --ext .js,.jsx",
"linter": "eslint index.js && eslint index-tests --ext .js && eslint src --ext .js,.jsx && eslint test --ext .js,.jsx",
"webpack": "export NODE_ENV=production && webpack -p --progress",
"build": "babel index.js --out-file build-index.js",
"test": "npm run linter && jest --coverage",
"test": "npm run linter && npm run jest",
"pre-jest": "rm -rf yarn-skip && rm -rf yarn && rm -rf npm && rm -rf travis && rm -rf skip && rm -rf git",
"jest": "npm run pre-jest && jest --coverage && npm run pre-jest",
"bundlesize": "bundlesize",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"prepublishOnly": "npm run build"
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ app.get("*.js", (req, res, next) => {
next();
});
app.use(express.static(path.resolve(__dirname, "../..", "build")));

// eslint-disable-next-line no-console
app.listen(3000, () => console.log(`server started on port 3000`));
1 change: 1 addition & 0 deletions test/client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ const EnzymeAdapter = require("enzyme-adapter-react-16");

// Setup enzyme's react adapter
Enzyme.configure({ adapter: new EnzymeAdapter() });
jest.setTimeout(900000);