Add Prettier Formatting ()

* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs

* Remove trailing-comma as we are using Node 6 on Circle

* Use latest Node 6 LTS version in Circle

* Remove unused test
This commit is contained in:
Héctor Ramos 2017-12-04 19:21:02 -08:00 committed by Joel Marcey
parent 0cead4b6f9
commit 65421db62e
50 changed files with 1376 additions and 1350 deletions

View file

@ -7,45 +7,45 @@
* LICENSE file in the root directory of this source tree.
*/
const chalk = require("chalk");
const commander = require("commander");
const fs = require("fs-extra");
const glob = require("glob");
const path = require("path");
const chalk = require('chalk');
const commander = require('commander');
const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
const CWD = process.cwd();
let feature;
commander
.arguments("[feature]")
.arguments('[feature]')
.action(feat => {
feature = feat;
})
.parse(process.argv);
// add scripts to package.json file
if (fs.existsSync(CWD + "/package.json")) {
if (fs.existsSync(CWD + '/package.json')) {
const packageContent = JSON.parse(
fs.readFileSync(CWD + "/package.json", "utf8")
fs.readFileSync(CWD + '/package.json', 'utf8')
);
if (!packageContent.scripts) {
packageContent.scripts = {};
}
packageContent.scripts["start"] = "docusaurus-start";
packageContent.scripts["build"] = "docusaurus-build";
packageContent.scripts["publish-gh-pages"] = "docusaurus-publish";
packageContent.scripts["examples"] = "docusaurus-examples";
packageContent.scripts["write-translations"] =
"docusaurus-write-translations";
packageContent.scripts["version"] = "docusaurus-version";
packageContent.scripts["rename-version"] = "docusaurus-rename-version";
packageContent.scripts['start'] = 'docusaurus-start';
packageContent.scripts['build'] = 'docusaurus-build';
packageContent.scripts['publish-gh-pages'] = 'docusaurus-publish';
packageContent.scripts['examples'] = 'docusaurus-examples';
packageContent.scripts['write-translations'] =
'docusaurus-write-translations';
packageContent.scripts['version'] = 'docusaurus-version';
packageContent.scripts['rename-version'] = 'docusaurus-rename-version';
fs.writeFileSync(
CWD + "/package.json",
CWD + '/package.json',
JSON.stringify(packageContent, null, 2)
);
console.log(
`${chalk.green("Wrote docusaurus scripts to package.json file.")}\n`
`${chalk.green('Wrote docusaurus scripts to package.json file.')}\n`
);
}
@ -56,48 +56,48 @@ let blogCreated = false;
let exampleSiteCreated = false;
// handles cases where feature is "translations", "versions" or neither/not present
if (feature === "translations") {
if (feature === 'translations') {
// copy files for translations
const folder = path.join(__dirname, "..", "examples", "translations");
if (fs.existsSync(CWD + "/../crowdin.yaml")) {
const folder = path.join(__dirname, '..', 'examples', 'translations');
if (fs.existsSync(CWD + '/../crowdin.yaml')) {
console.log(
`${chalk.yellow("crowdin.yaml already exists")} in ${chalk.yellow(
outerFolder + "/"
`${chalk.yellow('crowdin.yaml already exists')} in ${chalk.yellow(
outerFolder + '/'
)}. Rename or remove the file to regenerate an example version.\n`
);
} else {
fs.copySync(folder + "/crowdin.yaml", CWD + "/../crowdin.yaml");
fs.copySync(folder + '/crowdin.yaml', CWD + '/../crowdin.yaml');
exampleSiteCreated = true;
}
let files = glob.sync(folder + "/**/*");
let files = glob.sync(folder + '/**/*');
files.forEach(file => {
if (fs.lstatSync(file).isDirectory()) {
return;
}
if (path.basename(file) === "crowdin.yaml") {
if (path.basename(file) === 'crowdin.yaml') {
return;
}
const filePath = path.resolve(file).split(path.resolve(folder))[1];
try {
fs.copySync(file, CWD + filePath, {
overwrite: false,
errorOnExist: true
errorOnExist: true,
});
exampleSiteCreated = true;
} catch (e) {
console.log(
`${chalk.yellow(
path.basename(filePath) + " already exists"
path.basename(filePath) + ' already exists'
)} in ${chalk.yellow(
"website" + filePath.split(path.basename(filePath))[0]
'website' + filePath.split(path.basename(filePath))[0]
)}. Rename or remove the file to regenerate an example version.\n`
);
}
});
} else if (feature === "versions") {
} else if (feature === 'versions') {
// copy files for versions
const folder = path.join(__dirname, "..", "examples", "versions");
let files = glob.sync(folder + "/**/*");
const folder = path.join(__dirname, '..', 'examples', 'versions');
let files = glob.sync(folder + '/**/*');
files.forEach(file => {
if (fs.lstatSync(file).isDirectory()) {
return;
@ -106,76 +106,76 @@ if (feature === "translations") {
try {
fs.copySync(file, CWD + filePath, {
overwrite: false,
errorOnExist: true
errorOnExist: true,
});
exampleSiteCreated = true;
} catch (e) {
console.log(
`${chalk.yellow(
path.basename(filePath) + " already exists"
path.basename(filePath) + ' already exists'
)} in ${chalk.yellow(
"website" + filePath.split(path.basename(filePath))[0]
'website' + filePath.split(path.basename(filePath))[0]
)}. Rename or remove the file to regenerate an example version.\n`
);
}
});
} else {
const folder = path.join(__dirname, "..", "examples", "basics");
const folder = path.join(__dirname, '..', 'examples', 'basics');
// copy docs examples
if (fs.existsSync(CWD + "/../docs-examples-from-docusaurus")) {
if (fs.existsSync(CWD + '/../docs-examples-from-docusaurus')) {
console.log(
`${chalk.yellow(
"Example docs already exist!"
'Example docs already exist!'
)} Rename or remove ${chalk.yellow(
outerFolder + "/docs-examples-from-docusaurus"
outerFolder + '/docs-examples-from-docusaurus'
)} to regenerate example docs.\n`
);
} else {
fs.copySync(
folder + "/docs-examples-from-docusaurus",
CWD + "/../docs-examples-from-docusaurus"
folder + '/docs-examples-from-docusaurus',
CWD + '/../docs-examples-from-docusaurus'
);
exampleSiteCreated = true;
docsCreated = true;
}
// copy blog examples
if (fs.existsSync(CWD + "/blog-examples-from-docusaurus")) {
if (fs.existsSync(CWD + '/blog-examples-from-docusaurus')) {
console.log(
`${chalk.yellow(
"Example blog posts already exist!"
'Example blog posts already exist!'
)} Rename or remove ${chalk.yellow(
outerFolder + "/website/blog-examples-from-docusaurus"
outerFolder + '/website/blog-examples-from-docusaurus'
)} to regenerate example blog posts.\n`
);
} else {
fs.copySync(
path.join(folder, "blog-examples-from-docusaurus"),
path.join(CWD, "blog-examples-from-docusaurus")
path.join(folder, 'blog-examples-from-docusaurus'),
path.join(CWD, 'blog-examples-from-docusaurus')
);
exampleSiteCreated = true;
blogCreated = true;
}
// copy .gitignore file
if (fs.existsSync(CWD + "/.gitignore")) {
if (fs.existsSync(CWD + '/.gitignore')) {
console.log(
`${chalk.yellow(".gitignore already exists")} in ${chalk.yellow(
`${chalk.yellow('.gitignore already exists')} in ${chalk.yellow(
CWD
)}. Rename or remove the file to regenerate an example version.\n`
);
} else {
fs.copySync(path.join(folder, "gitignore"), path.join(CWD, ".gitignore"));
fs.copySync(path.join(folder, 'gitignore'), path.join(CWD, '.gitignore'));
}
// copy other files
let files = glob.sync(folder + "/**/*");
let files = glob.sync(folder + '/**/*');
files.forEach(file => {
if (fs.lstatSync(file).isDirectory()) {
return;
}
const containingFolder = path.basename(path.dirname(file));
if (
path.basename(file) === "gitignore" ||
containingFolder === "blog-examples-from-docusaurus" ||
containingFolder === "docs-examples-from-docusaurus"
path.basename(file) === 'gitignore' ||
containingFolder === 'blog-examples-from-docusaurus' ||
containingFolder === 'docs-examples-from-docusaurus'
) {
return;
}
@ -183,15 +183,15 @@ if (feature === "translations") {
try {
fs.copySync(file, CWD + filePath, {
overwrite: false,
errorOnExist: true
errorOnExist: true,
});
exampleSiteCreated = true;
} catch (e) {
console.log(
`${chalk.yellow(
path.basename(filePath) + " already exists"
path.basename(filePath) + ' already exists'
)} in ${chalk.yellow(
"website" + filePath.split(path.basename(filePath))[0]
'website' + filePath.split(path.basename(filePath))[0]
)}. Rename or remove the file to regenerate an example version.\n`
);
}
@ -200,8 +200,8 @@ if (feature === "translations") {
if (exampleSiteCreated) {
console.log(
`${chalk.green("Example website created")} in ${chalk.green(
CWD + "/website"
`${chalk.green('Example website created')} in ${chalk.green(
CWD + '/website'
)}\n`
);
}
@ -209,9 +209,9 @@ if (exampleSiteCreated) {
if (docsCreated) {
console.log(
`Rename ${chalk.yellow(
outerFolder + "/docs-examples-from-docusaurus"
outerFolder + '/docs-examples-from-docusaurus'
)} to ${chalk.yellow(
outerFolder + "/docs"
outerFolder + '/docs'
)} to see the example docs on your site.\n`
);
}
@ -219,9 +219,9 @@ if (docsCreated) {
if (blogCreated) {
console.log(
`Rename ${chalk.yellow(
outerFolder + "/website/blog-examples-from-docusaurus"
outerFolder + '/website/blog-examples-from-docusaurus'
)} to ${chalk.yellow(
outerFolder + "/website/blog"
outerFolder + '/website/blog'
)} to see the example blog posts on your site.\n`
);
}