Skip to content

Commit

Permalink
redo eslintrc files (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Jan 3, 2018
1 parent bbd8c37 commit ca43757
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 76 deletions.
61 changes: 23 additions & 38 deletions packages/generator-electrode/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ module.exports = class extends Generator {
: this.fs.exists(this.destinationPath("src/server/koa-server.js")) ? KoaJS : HapiJS;
this.props.pwa = this.fs.exists(this.destinationPath("client/sw-registration.js"));
this.props.autoSsr = this.fs.exists(this.destinationPath("server/plugins/autossr.js"));
this.props.quoteType = this.fs.exists(this.destinationPath(".eslintrc")) ? "'" : '"';
this.props.quoteType =
_.get(pkg, "eslintConfig.rules.quotes", []).indexOf("single") >= 0 ? "'" : '"';
} else if (_.isString(this.pkg.author)) {
var info = parseAuthor(this.pkg.author);
this.props.authorName = info.name;
Expand Down Expand Up @@ -274,7 +275,8 @@ module.exports = class extends Generator {
isHapi,
isExpress,
isPWA,
isAutoSSR
isAutoSSR,
isSingleQuote
});

var defaultPkg = this.fs.readJSON(this.destinationPath(_pkg));
Expand Down Expand Up @@ -327,23 +329,21 @@ module.exports = class extends Generator {
this.fs.writeJSON(this.destinationPath("package.json"), pkg);

const rootConfigsToCopy = ["xclap.js", "config", "test"];
if (isSingleQuote) rootConfigsToCopy.push(".eslintrc");
rootConfigsToCopy.push(".eslintrc.js");
rootConfigsToCopy.forEach(f => {
this.fs.copyTpl(this.templatePath(f), this.destinationPath(f), { isSingleQuote });
this.fs.copyTpl(
this.templatePath(f),
this.destinationPath(f),
{ isSingleQuote },
{},
{ globOptions: { dot: true } }
);
});

if (this.isExtended) {
this.fs.delete(this.destinationPath("config/default.js"));
}

//copy .eslintc into the client directory
if (isSingleQuote) {
this.fs.copy(
this.templatePath("src/client/.eslintrc"),
this.destinationPath("src/client/.eslintrc")
);
}

//special handling for the server file
this.fs.copyTpl(
this.templatePath("src/server"),
Expand All @@ -352,6 +352,7 @@ module.exports = class extends Generator {
{},
{
globOptions: {
dot: true,
ignore: ignoreArray
}
}
Expand All @@ -365,26 +366,21 @@ module.exports = class extends Generator {
{
// copy options
globOptions: {
dot: true,
// Images are damaged by the template compiler
ignore: [
"**/client/images/**",
(!isPWA && "**/client/sw-registration.js") || "",
(this.isDemoApp && "**/client/components/**") || "",
(this.isDemoApp && "**/client/actions/**") || "",
(this.isDemoApp && "**/client/reducers/**") || ""
]
ignore: ["**/client/images/**", !isPWA && "**/client/sw-registration.js"]
.concat(
this.isDemoApp && [
"**/client/components/**",
"**/client/actions/**",
"**/client/reducers/**"
]
)
.filter(x => x)
}
}
);

["src/client", "src/server", "test/client", "test/server"].forEach(d => {
this.fs.move(this.destinationPath(d + "/babelrc"), this.destinationPath(d + "/.babelrc"));
});

["test/client", "test/server"].forEach(d => {
this.fs.move(this.destinationPath(d + "/eslintrc"), this.destinationPath(d + "/.eslintrc"));
});

this.fs.copy(this.templatePath("src/client/images"), this.destinationPath("src/client/images"));
}

Expand Down Expand Up @@ -453,17 +449,6 @@ module.exports = class extends Generator {
}

end() {
if (this.props.quoteType === "'") {
this.spawnCommandSync("node_modules/.bin/eslint", [
"--fix",
"src",
"test",
"config",
"--ext",
".js,.jsx"
]);
}

if (!this.isDemoApp) {
var chdir = this.props.createDirectory
? "'cd " + _.kebabCase(_.deburr(this.props.name)) + "' then "
Expand Down

This file was deleted.

11 changes: 11 additions & 0 deletions packages/generator-electrode/generators/app/templates/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");
var archetype = require("electrode-archetype-react-app/config/archetype");
var archetypeEslint = path.join(archetype.config.eslint, ".eslintrc-react");

function dotify(p) {
return path.isAbsolute(p) ? p : "." + path.sep + p;
}

module.exports = {
extends: dotify(path.relative(__dirname, archetypeEslint))
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"test": "clap check",
"coverage": "clap check",
"prod": "echo 'Starting standalone server in PROD mode'; NODE_ENV=production node ./lib/server/",
"heroku-postbuild": "clap build"
"heroku-postbuild": "clap build"<% if (isSingleQuote) { %>,
"install": "clap fix-generator-eslint"<% } %>
},
"dependencies": {
"bluebird": "^3.4.6",
Expand All @@ -47,5 +48,10 @@
},
"devDependencies": {
"electrode-archetype-react-app-dev": "^4.0.0"
}
}<% if (isSingleQuote) { %>,
"eslintConfig": {
"rules": {
"quotes": [2, "single"]
}
}<% } %>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");
var archetype = require("electrode-archetype-react-app/config/archetype");
var archetypeEslint = path.join(archetype.config.eslint, ".eslintrc-react");

function dotify(p) {
return path.isAbsolute(p) ? p : "." + path.sep + p;
}

module.exports = {
extends: dotify(path.relative(__dirname, archetypeEslint))
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");
var archetype = require("electrode-archetype-react-app/config/archetype");
var archetypeEslint = path.join(archetype.config.eslint, ".eslintrc-node");

function dotify(p) {
return path.isAbsolute(p) ? p : "." + path.sep + p;
}

module.exports = {
extends: dotify(path.relative(__dirname, archetypeEslint))
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");
var archetype = require("electrode-archetype-react-app/config/archetype");
var archetypeEslint = path.join(archetype.config.eslint, ".eslintrc-react-test");

function dotify(p) {
return path.isAbsolute(p) ? p : "." + path.sep + p;
}

module.exports = {
extends: dotify(path.relative(__dirname, archetypeEslint))
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");
var archetype = require("electrode-archetype-react-app/config/archetype");
var archetypeEslint = path.join(archetype.config.eslint, ".eslintrc-mocha-test-es6");

function dotify(p) {
return path.isAbsolute(p) ? p : "." + path.sep + p;
}

module.exports = {
extends: dotify(path.relative(__dirname, archetypeEslint))
};

This file was deleted.

23 changes: 23 additions & 0 deletions packages/generator-electrode/generators/app/templates/xclap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,26 @@ process.env.SERVER_ES6 = true;
// process.env.WEBPACK_DEV_HTTPS = true;

require("electrode-archetype-react-app")();

//
// When single quote option is selected, this will use eslint to fix
// generated files from double to single quote after npm install.
// This is more reliable in case you stop npm install after the generator
// generated the app.
// You may remove this if you want.
//
const xclap = require("xclap");
const Fs = require("fs");
const Path = require("path");
xclap.load("user", {
"fix-generator-eslint": {
task: () => {
const pkg = require("./package.json");
if (pkg.scripts.install === "clap fix-generator-eslint") {
pkg.scripts.install = "echo OK";
Fs.writeFileSync(Path.resolve("package.json"), JSON.stringify(pkg, null, 2));
return "~$eslint --fix config src test --ext .js,.jsx";
}
}
}
});

0 comments on commit ca43757

Please sign in to comment.