Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Linting and minor refactoring #127

Merged
merged 1 commit into from
May 2, 2016
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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN npm install -g gluestick@$GLUESTICK_VERSION
RUN mkdir /app
WORKDIR /app

ADD ./new/package.json /app
ADD ./templates/new/package.json /app

RUN npm install

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ var dockerfile = [
""
];

fs.writeFile("./new/src/config/.Dockerfile", dockerfile.join("\n"));
fs.writeFile("./templates/new/src/config/.Dockerfile", dockerfile.join("\n"));
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"bugs": "https://github.com/TrueCar/gluestick/issues",
"license": "MIT",
"scripts": {
"lint": "eslint src test templates",
"test": "mocha --compilers js:babel-core/register --require babel-polyfill --recursive",
"test-coverage": "./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover --include-all-sources --report html --dir coverage/html ./node_modules/.bin/_mocha -- --recursive",
"prepublish": "./docker/generate_dockerfile",
"postpublish": "./docker/create_base_image"
"prepublish": "./docker/generate-dockerfile.js",
"postpublish": "./docker/create-base-image.js"
},
"keywords": [
"react",
Expand Down Expand Up @@ -97,6 +98,9 @@
},
"peerDependencies": {},
"devDependencies": {
"babel-eslint": "6.0.4",
"eslint": "2.9.0",
"eslint-plugin-react": "5.0.1",
"temp": "0.8.3"
}
}
4 changes: 2 additions & 2 deletions src/auto-upgrade/index.js → src/autoUpgrade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = async function () {
}
catch (e) {
const fileName = path.parse(filePath).base;
const newFile = fs.readFileSync(path.join(__dirname, "..", "..", "new", filePath), "utf8");
const newFile = fs.readFileSync(path.join(__dirname, "..", "..", "templates", "new", filePath), "utf8");
replaceFile(fileName, newFile);
}
});
Expand All @@ -65,7 +65,7 @@ module.exports = async function () {
const currentFile = fs.readFileSync(getCurrentFilePath(fileName));
const currentSha = sha1(currentFile);

const newFile = fs.readFileSync(path.join(__dirname, "..", "..", "new", "src", "config", fileName), "utf8");
const newFile = fs.readFileSync(path.join(__dirname, "..", "..", "templates", "new", "src", "config", fileName), "utf8");
const newSha = sha1(newFile);

if (currentSha !== newSha) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export default function updateBabelConfig() {
return new Promise(resolve => {

const projectConfigPath = path.join(process.cwd(), ".babelrc");
const latestConfigPath = path.join(__dirname, "../..", "new", ".babelrc");
const latestConfigPath = path.join(__dirname, "../..", "templates", "new", ".babelrc");
const projectSha = sha1(readFileSyncStrip(projectConfigPath));
const previousSha = sha1(readFileSyncStrip(path.join(__dirname, "previous", ".babelrc")));
const latestSha = sha1(readFileSyncStrip(latestConfigPath));

if (projectSha === latestSha) {
resolve();
}
}
else if (projectSha === previousSha) {
doUpdate(latestConfigPath, projectConfigPath);
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function updateConfig () {
const appConfigPath = path.join(CWD, "src", "config", "application.js");
const appConfig = readFileSyncStrip(appConfigPath);
const lastAppConfigLine = appConfig.split("\n").pop();
const expectedLastLine = 'export default (config[process.env.NODE_ENV] || config["development"]);';
const expectedLastLine = "export default (config[process.env.NODE_ENV] || config[\"development\"]);";

const hasExportUpgrade = lastAppConfigLine === expectedLastLine;
const hasHeadUpgrade = appConfig.indexOf("const headContent = {") !== -1;
Expand All @@ -28,7 +28,7 @@ export default function updateConfig () {
return;
}

const exampleContents = fs.readFileSync(path.join(__dirname, "..", "..", "new", "src", "config", "application.js"), "utf8");
const exampleContents = fs.readFileSync(path.join(__dirname, "..", "..", "templates", "new", "src", "config", "application.js"), "utf8");
logger.warn("The format of src/config/application.js is out of date.");
if (hasExportUpgrade) {
logger.warn("You should *manually* update it to include the new document head content as seen in the example below.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ export default function fixVersionMismatch () {

// Compare the new project dependencies, mark any module that is missing in
// the generated project's dependencies
for(let key in newProjectDependencies) {
for(const key in newProjectDependencies) {
if (newProjectDependencies[key] !== projectDependencies[key]) {
mismatchedModules[key] = { required: newProjectDependencies[key], project: projectDependencies[key] || "missing", type: "dependencies" };
}
}

// Compare the new project development dependencies, mark any module that
// is missing in the generated project's development dependencies
for(let key in newProjectDevDependencies) {
for(const key in newProjectDevDependencies) {
if (newProjectDevDependencies[key] !== projectDevDependencies[key]) {
mismatchedModules[key] = { required: newProjectDevDependencies[key], project: projectDevDependencies[key] || "missing", type: "devDependencies" };
}
}

// Compare the CLI dependencies, only mark a module as mismatched if it is
// included in both and the version do not match
for(let key in cliDependencies) {
for(const key in cliDependencies) {
if (projectDependencies[key] && cliDependencies[key] !== projectDependencies[key]) {
mismatchedModules[key] = { required: cliDependencies[key], project: projectDependencies[key], type: "dependencies" };
}
Expand Down Expand Up @@ -111,7 +111,7 @@ function loadCLIPackage () {
* @return {Object}
*/
function loadNewProjectPackage () {
return loadPackage(path.join(__dirname, "../../new/package.json"));
return loadPackage(path.join(__dirname, "../../templates/new/package.json"));
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ ${chalk.yellow(mismatchedModuleOutput)}
Would you like to automatically update your project's dependencies to match the CLI?`
};
inquirer.prompt([question]).then(function (answers) {
if (!answers.confirm) return done();
if (!answers.confirm) { return done(); }
performModulesUpdate(mismatchedModules, done);
});
}
Expand All @@ -164,9 +164,9 @@ Would you like to automatically update your project's dependencies to match the
* update completes
*/
function performModulesUpdate (mismatchedModules, done) {
let projectPackageData = loadProjectPackage();
const projectPackageData = loadProjectPackage();
let module;
for (let moduleName in mismatchedModules) {
for (const moduleName in mismatchedModules) {
module = mismatchedModules[moduleName];
projectPackageData[module.type][moduleName] = module.required;
}
Expand All @@ -184,7 +184,7 @@ function performModulesUpdate (mismatchedModules, done) {
const npmInstall = spawn("npm" + postFix, ["install"], {stdio: "inherit"});

npmInstall.on("close", () => {
logger.success(`node_modules have been updated.`);
logger.success("node_modules have been updated.");
done();
});
}
5 changes: 2 additions & 3 deletions src/cli-harmony.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
'use strict';

require("./run-through-babel");
"use strict";

require("./lib/runThroughBabel");
require("./cli");

14 changes: 8 additions & 6 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { highlight } = logsColorScheme;
const utils = require("./lib/utils");
const { quitUnlessGluestickProject } = utils;

const autoUpgrade = require("./auto-upgrade");
const autoUpgrade = require("./autoUpgrade");

const isProduction = process.env.NODE_ENV === "production";

Expand Down Expand Up @@ -167,7 +167,7 @@ Upgrade Notice: Newer versions of Index.js now include react-helmet
for allowing dynamic changes to document header data. You will need to
manually update your Index.js file to receive this change.
For a simple example see:
https://github.com/TrueCar/gluestick/blob/develop/new/Index.js
https://github.com/TrueCar/gluestick/blob/develop/templates/new/Index.js
##########################################################################
`);
}
Expand All @@ -186,8 +186,10 @@ function spawnProcess (type, args=[]) {
case "test":
childProcess = spawn("gluestick" + postFix, ["start-test", ...args], {stdio: "inherit", env: Object.assign({}, process.env, {NODE_ENV: isProduction ? "production": "development-test"})});
break;
default:
break;
}
childProcess.on("error", function (data) { logger.error(JSON.stringify(arguments)); });
childProcess.on("error", function () { logger.error(JSON.stringify(arguments)); });
return childProcess;
}

Expand All @@ -200,12 +202,12 @@ async function startAll(withoutTests=false, debug=false) {
process.exit();
}

const client = spawnProcess("client");
const server = spawnProcess("server", (debug ? ["--debug"] : []));
spawnProcess("client");
spawnProcess("server", (debug ? ["--debug"] : []));

// Start tests unless they asked us not to or we are in production mode
if (!isProduction && !withoutTests) {
const testProcess = spawnProcess("test");
spawnProcess("test");
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/commands/destroy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var fs = require("fs");
var path = require("path");
var inquirer = require("inquirer");
const fs = require("fs");
const path = require("path");
const inquirer = require("inquirer");
const logger = require("../lib/logger");
const logsColorScheme = require("../lib/logsColorScheme");
const { highlight, filename } = logsColorScheme;

var availableCommands = {
const availableCommands = {
"container": "containers",
"component": "components",
"reducer": "reducers"
Expand All @@ -22,7 +22,7 @@ module.exports = async function (command, name) {

// Validate the name by stripping out unwanted characters
if (!name || name.length === 0) {
logger.error(`invalid arguments. You must specify a name.`);
logger.error("invalid arguments. You must specify a name.");
return;
}

Expand All @@ -32,7 +32,7 @@ module.exports = async function (command, name) {
}

// Possibly mutate the name by converting it to Pascal Case (only for container and component for now)
var originalName = name; // store original name for later
const originalName = name; // store original name for later
if (["container", "component"].indexOf(command) !== -1) {
name = name.substr(0, 1).toUpperCase() + name.substr(1);
}
Expand All @@ -41,8 +41,8 @@ module.exports = async function (command, name) {
}

// Remove the file
var destinationPath = path.join(process.cwd(), "/src/", availableCommands[command] + "/" + name + ".js");
var fileExists = true;
const destinationPath = path.join(process.cwd(), "/src/", availableCommands[command] + "/" + name + ".js");
let fileExists = true;
try {
fs.statSync(destinationPath);
}
Expand All @@ -54,7 +54,7 @@ module.exports = async function (command, name) {
// If they typed a name that would normally be mutated, check with the user first before deleting the files
if (originalName !== name) {
// @NOTE: We are using await so that we can wait for the result of the promise before moving on
const continueDestroying = await new Promise((resolve, reject) => {
const continueDestroying = await new Promise((resolve) => {
const question = {
type: "confirm",
name: "confirm",
Expand All @@ -66,7 +66,7 @@ module.exports = async function (command, name) {
});

// Since we used await, this code will not be executed until the promise above resolves
if (!continueDestroying) process.exit();
if (!continueDestroying) { process.exit(); }
}

fs.unlinkSync(destinationPath);
Expand All @@ -79,7 +79,7 @@ module.exports = async function (command, name) {

// If we destroyed a reducer, remove it from the reducers index
if (command === "reducer") {
var reducerIndexPath = path.resolve(process.cwd(), "src/reducers/index.js");
const reducerIndexPath = path.resolve(process.cwd(), "src/reducers/index.js");
try {
const indexLines = fs.readFileSync(reducerIndexPath, {encoding: "utf8"}).split("\n");
const reducerLine = `export { default as ${name} } from "./${name}"`;
Expand All @@ -92,13 +92,13 @@ module.exports = async function (command, name) {
logger.success(`${highlight(name)} removed from reducer index ${filename(reducerIndexPath)}`);
}
catch (e) {
logger.error(`Unable to modify reducers index. Reducer not removed from index`);
logger.error("Unable to modify reducers index. Reducer not removed from index");
}
}

// Remove the test file
var testPath = path.join(process.cwd(), "/test/", availableCommands[command], `/${name}.test.js`);
var testFileExists = true;
const testPath = path.join(process.cwd(), "/test/", availableCommands[command], `/${name}.test.js`);
let testFileExists = true;
try {
fs.statSync(testPath);
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/dockerize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { spawn } from "cross-spawn";
import path from "path";
import process from "process";
import fs from "fs";

module.exports = function (name) {
const { version: gluestickVersion } = JSON.parse(fs.readFileSync(path.join(__dirname, "../../package.json"), "utf-8"));
// @TODO: check if docker is installed first (https://github.com/TrueCar/gluestick/issues/128)
spawn("docker", ["build", "-t", name, "-f", path.join(process.cwd(), "src", "config", ".Dockerfile"), process.cwd()], {stdio: "inherit"});
};

Loading