Skip to content

Chnaged Prettier command to format all code #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 30, 2019
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
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ignore node_modules
node_modules

#ignore build folder
dist

#ignore package-lock.json
package-lock.json
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"useTabs": true,
"trailingComma": "all",
"jsxBracketSameLine": true,
"jsxSingleQuote": true
}

67 changes: 38 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{
"name": "create-react-webpack",
"version": "0.1.2",
"description": "create-react-webpack ",
"main": "scripts/create.js",
"bin": {
"create-react-webpack": "./start.js"
},
"preferGlobal": true,
"scripts": {
"create-react-webpack": "node scripts/create.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AlokTakshak/create-react-webpack.git"
},
"keywords": [
"React",
"Webpack"
],
"author": "Alok Takshak",
"license": "ISC",
"bugs": {
"url": "https://github.com/AlokTakshak/create-react-webpack/issues"
},
"homepage": "https://github.com/AlokTakshak/create-react-webpack#readme",
"dependencies": {
"chalk": "^2.4.2",
"update-notifier": "^3.0.1"
}
"name": "create-react-webpack",
"version": "0.1.3",
"description": "create-react-webpack ",
"main": "scripts/create.js",
"bin": {
"create-react-webpack": "./start.js"
},
"preferGlobal": true,
"scripts": {
"create-react-webpack": "node scripts/create.js",
"format": "prettier --write \"./**/*.{js,jsx,json}\""
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/AlokTakshak/create-react-webpack.git"
},
"keywords": [
"React",
"Webpack"
],
"author": "Alok Takshak",
"license": "ISC",
"bugs": {
"url": "https://github.com/AlokTakshak/create-react-webpack/issues"
},
"homepage": "https://github.com/AlokTakshak/create-react-webpack#readme",
"dependencies": {
"chalk": "^2.4.2",
"husky": "^3.1.0",
"prettier": "^1.19.1",
"pretty-quick": "^2.0.1",
"update-notifier": "^3.0.1"
}
}
12 changes: 6 additions & 6 deletions scripts/constants.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const CLEAN_NPM_CACHE = "npm cache clean --force";
const SPECIALCHAR = RegExp("/[!@#$%^&*()-=_,.?~:;\\{}|<>]/g");
const UNNECESSORY_FOLDERS_FOR_DEV = RegExp(
"^node_modules|build|dist|server$",
"i"
"^node_modules|build|dist|server$",
"i",
);
const UNNECESSORY_FOLDERS_FOR_PROD = RegExp("^node_modules|build|dist$", "i");

module.exports = {
CLEAN_NPM_CACHE,
SPECIALCHAR,
UNNECESSORY_FOLDERS_FOR_DEV,
UNNECESSORY_FOLDERS_FOR_PROD
CLEAN_NPM_CACHE,
SPECIALCHAR,
UNNECESSORY_FOLDERS_FOR_DEV,
UNNECESSORY_FOLDERS_FOR_PROD,
};
54 changes: 27 additions & 27 deletions scripts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@ const path = require("path");
const { copyDirectory, ErrorMessage, SuccessMessage } = require("./helper");
const { CLEAN_NPM_CACHE, SPECIALCHAR } = require("./constants");
const {
installDependencies,
getDependencies,
getDevDependencies,
getProdDependencies
installDependencies,
getDependencies,
getDevDependencies,
getProdDependencies,
} = require("./dependencies");

var args = process.argv.slice(2);
var dirName = args[0];
var end_to_end = args[1];

if (dirName === "undefined") {
throw new Error(ErrorMessage("directory name can't be empty"));
throw new Error(ErrorMessage("directory name can't be empty"));
} else if (dirName[0].match("^[A-Z0-9]")) {
throw new Error(
ErrorMessage("directory name can't start from capital letters ")
);
throw new Error(
ErrorMessage("directory name can't start from capital letters "),
);
} else if (dirName.match(SPECIALCHAR)) {
throw new Error(
ErrorMessage(
"directory name can't start from capital letters or contain special characters in it"
)
);
throw new Error(
ErrorMessage(
"directory name can't start from capital letters or contain special characters in it",
),
);
} else {
//using process.cwd for getting current path
const TEMPLATE_PATH = path.join(__dirname, "../template");
let destination = path.join(process.cwd() + "/" + args[0]);
const prod = end_to_end == "-e";
//using process.cwd for getting current path
const TEMPLATE_PATH = path.join(__dirname, "../template");
let destination = path.join(process.cwd() + "/" + args[0]);
const prod = end_to_end == "-e";

copyDirectory(TEMPLATE_PATH, destination, prod);
copyDirectory(TEMPLATE_PATH, destination, prod);

let commands = [],
options;
let commands = [],
options;

commands.push(CLEAN_NPM_CACHE);
commands.push(getDependencies());
prod && commands.push(getProdDependencies());
commands.push(getDevDependencies());
commands.push(CLEAN_NPM_CACHE);
commands.push(getDependencies());
prod && commands.push(getProdDependencies());
commands.push(getDevDependencies());

options = { cwd: destination, stdio: "inherit" };
options = { cwd: destination, stdio: "inherit" };

installDependencies(commands, options);
console.log(SuccessMessage("Successfully created the directory"));
installDependencies(commands, options);
console.log(SuccessMessage("Successfully created the directory"));
}
104 changes: 52 additions & 52 deletions scripts/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,63 @@ const child_process = require("child_process");

const DEPENDENCIES = ["prop-types", "react", "react-dom", "react-hot-loader"];
const DEV_DEPENDENCIES = [
"@babel/cli",
"@babel/core",
"@babel/plugin-proposal-class-properties",
"@babel/preset-env",
"@babel/preset-react",
"babel-loader",
"brotli-webpack-plugin",
"compression-webpack-plugin",
"css-loader",
"eslint",
"eslint-plugin-react",
"file-loader",
"html-webpack-plugin",
"husky",
"jest",
"prettier",
"pretty-quick",
"style-loader",
"webpack",
"webpack-cli",
"webpack-dev-server",
"webpack-manifest-plugin",
"webpack-merge"
"@babel/cli",
"@babel/core",
"@babel/plugin-proposal-class-properties",
"@babel/preset-env",
"@babel/preset-react",
"babel-loader",
"brotli-webpack-plugin",
"compression-webpack-plugin",
"css-loader",
"eslint",
"eslint-plugin-react",
"file-loader",
"html-webpack-plugin",
"husky",
"jest",
"prettier",
"pretty-quick",
"style-loader",
"webpack",
"webpack-cli",
"webpack-dev-server",
"webpack-manifest-plugin",
"webpack-merge",
];
const PROD_DEPENDENCIES = ["express", "express-static-gzip"];

/**
* Returns npm command for installing dependencies
*/
function getDependencies() {
var installCommand = "npm install --save";
DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
var installCommand = "npm install --save";
DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
}

/**
* Returns npm command for installing dev-dependencies
*/
function getDevDependencies() {
var installCommand = "npm install --save-dev";
DEV_DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
var installCommand = "npm install --save-dev";
DEV_DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
}

/**
* Returns npm command for installing prod dependencies
*/
function getProdDependencies() {
var installCommand = "npm install --save";
PROD_DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
var installCommand = "npm install --save";
PROD_DEPENDENCIES.forEach(dependency => {
installCommand += ` ${dependency} `;
});
return installCommand;
}

/**
Expand All @@ -69,22 +69,22 @@ function getProdDependencies() {
* @param {String} options.stdio process's stdio config
*/
function installDependencies(commands, options) {
options.stdio = options.stdio || "inherit";
options.stdio = options.stdio || "inherit";

if (commands) {
try {
commands.forEach(command => {
child_process.execSync(command, options);
});
} catch (error) {
throw error;
}
}
if (commands) {
try {
commands.forEach(command => {
child_process.execSync(command, options);
});
} catch (error) {
throw error;
}
}
}

module.exports = {
installDependencies,
getDependencies,
getDevDependencies,
getProdDependencies
installDependencies,
getDependencies,
getDevDependencies,
getProdDependencies,
};
Loading