Skip to content

Commit

Permalink
Fix clc usage; Add prettierrc
Browse files Browse the repository at this point in the history
  • Loading branch information
harveysanders committed Jan 29, 2024
1 parent ab46cde commit 5b42af1
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
'func-names': 'off',
'consistent-return': 'off',
'prefer-arrow-callback': 'off',
'arrow-parens': 'as-needed',
'arrow-parens': 'off',
// Windows friendly -- does not show errors on every line of every file
'no-unused-vars': 1,
'linebreak-style': 0
Expand Down
24 changes: 24 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"singleAttributePerLine": false,
"bracketSameLine": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"embeddedLanguageFormatting": "auto",
"vueIndentScriptAndStyle": false,
"filepath": "/Users/opsparkowl/Documents/opspark/dev_shop/opspark/.eslintrc.js",
"parser": "babel"
}
6 changes: 2 additions & 4 deletions controller/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ const util = require('util');
const prompt = require('inquirer').prompt;
const mkdirp = require('mkdirp');
const fsJson = require('fs-json')();
const octonode = require('octonode');
const rp = require('request-promise');

const exec = require('child_process').exec;

const env = require('./env');
const config = require('../config.json');
const janitor = require('./janitor');
const {
createGithubToken,
deleteGithubToken,
Expand Down Expand Up @@ -300,7 +298,7 @@ function deauthorizeUser() {
console.log(clc.blue('Successfully logged out!'));
res(true);
})
.catch(err => rej(`${err}`.red));
.catch(err => rej(clc.red(`${err}`)));
});
}

Expand Down
2 changes: 1 addition & 1 deletion controller/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function () {
.catch(janitor.error(clc.red('Failure installing project')))
.then(projects.initializeProject)
.catch(janitor.error(clc.red('Failure initializing')))
.then(res => console.log(`Successfully installed ${res.name}!`.blue))
.then(res => console.log(clc.blue(`Successfully installed ${res.name}!`)))
.catch(err => {
console.error(err);
});
Expand Down
8 changes: 4 additions & 4 deletions controller/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function selectProject({ session, projectAction }) {
],
function (response) {
if (response.project === cancelOption) {
console.log(`${action} cancelled, bye bye!`.green);
console.log(clc.green(`${action} cancelled, bye bye!`));
process.exitCode = 0;
process.exit();
}
Expand Down Expand Up @@ -126,7 +126,7 @@ function installProject(project) {
const projectName = changeCase.paramCase(project.name);
const projectDirectory = `${projectsDirectory}/${projectName}`;
if (ensureProjectDirectory(projectDirectory)) {
rej(`${project.name} already installed!`.red);
rej(clc.red(`${project.name} already installed!`));
}
console.log(
clc.yellow('Installing project %s, please wait...'),
Expand All @@ -152,9 +152,9 @@ function uninstallProject(project) {
{
type: 'confirm',
name: 'delete',
message:
message: clc.bgRed(
`Are you sure you want to delete ${project.name}? This cannot be undone.`
.bgRed
)
},
function (confirm) {
if (confirm.delete) {
Expand Down
3 changes: 1 addition & 2 deletions controller/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const clc = require('cli-color');
const _ = require('lodash');
const inquirer = require('inquirer');
const { waterfall } = require('async');
const changeCase = require('change-case');

const projects = require('./projects');

Expand Down Expand Up @@ -34,7 +33,7 @@ function selectSession(sessions) {
],
function (response) {
if (response.class === cancelOption) {
console.log(`${projects.action} cancelled, bye bye!`.green);
console.log(clc.green(`${projects.action} cancelled, bye bye!`));
process.exitCode = 0;
process.exit();
}
Expand Down
2 changes: 1 addition & 1 deletion controller/shelve.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function () {
.then(projects.shelveProject)
.catch(janitor.error(clc.red('Failure shelving project')))
.then(path =>
console.log(clc.blue('Project now available at'), `${path}!`.yellow)
console.log(clc.blue('Project now available at'), clc.yellow(`${path}!`))
)
.catch(err => {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion controller/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports.createGist = createGist;
function ensureGistExists({ project, gist, tries }) {
return new Promise(function (res, rej) {
if (tries < 4) {
console.log(`Ensuring gist exists. . . Attempt ${tries}`.yellow);
console.log(clc.yellow(`Ensuring gist exists. . . Attempt ${tries}`));
const cmd = readGistHelper(gist.files['grade.txt'].raw_url);
exec(cmd, function (err, stdout, stderr) {
if (err) {
Expand Down
25 changes: 14 additions & 11 deletions controller/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const changeCase = require('change-case');
const exec = require('child_process').exec;

const { codenvyUser, home, cloud9User } = require('./env');
const { home } = require('./env');
const janitor = require('./janitor');
const github = require('./github');
const greenlight = require('./greenlight');
Expand All @@ -18,8 +18,7 @@ const {
execAsync
} = require('./helpers');

let rootDirectory = `${home()}/environment`;
let githubDir;
const rootDirectory = `${home()}/environment`;

// if (cloud9User) {
// githubDir = fs
Expand Down Expand Up @@ -70,7 +69,7 @@ module.exports.test = test;
function grabTests(project) {
return new Promise(function (res, rej) {
const name = changeCase.paramCase(project.name);
console.log(`Downloading tests for ${name}. . .`.yellow);
console.log(clc.yellow(`Downloading tests for ${name}. . .`));
const directory = `${projectsDirectory}/${name}`;
const cmd = downloadProjectTests(
project.url,
Expand Down Expand Up @@ -137,15 +136,17 @@ function runTests(project) {

console.log(clc.bgBlue.white(` Passing tests: ${getFillStr(passes)}`));
console.log(clc.bgRed.white(` Failing tests: ${getFillStr(failures)}`));
console.log(clc.bgYellow.black(` Pending tests: ${getFillStr(pending)}`));
console.log(
clc.bgYellow.black(` Pending tests: ${getFillStr(pending)}`)
);
console.log(clc.bgBlack.white(` Total tests: ${getFillStr(tests)}`));

return { project, testResults };
})
.then(
testResults => removeProjectTests().then(() => testResults),
error => removeProjectTests().then(() => Promise.reject(error))
)
);
}

module.exports.runTests = runTests;
Expand All @@ -161,15 +162,17 @@ function displayResults({ testResults }) {
const stackLineOne = stack[0];
const stackLineTwo = stack[1];
const errorInfo = stackLineOne.slice(stackLineOne.indexOf(':'));
console.log(`${i + 1}) ${whichTest}`.red.bold.underline);
console.log(`> > > ${message}`.red);
console.log(`> > > ${errorInfo}`.grey);
console.log(`> > > ${stackLineTwo}`.grey);
console.log(clc.red.bold.underline(`${i + 1}) ${whichTest}`));
console.log(clc.red(`> > > ${message}`));
console.log(clc.xterm(252)(`> > > ${errorInfo}`));
console.log(clc.xterm(252)(`> > > ${stackLineTwo}`));
});

//part divided by the whole 3/4 = 75%
//use math.round to round to the nearest whole percent
let grade = Math.round(100 * (testResults.stats.passes / testResults.stats.tests))
let grade = Math.round(
100 * (testResults.stats.passes / testResults.stats.tests)
);
const clcMethod = grade > 75 ? clc.yellow : clc.red;
console.log(clcMethod(`You have passed ${grade}% of the test.`));

Expand Down
40 changes: 27 additions & 13 deletions test/test-projects.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/* global describe it expect before beforeEach afterEach */
require('mocha');
require('should');
const clc = require('cli-color');

const fs = require('fs');
const _ = require('lodash');
const util = require('util');
const sinon = require('sinon');
const prompt = require('prompt');
const rimraf = require('rimraf');
const process = require('process');
const fsJson = require('fs-json')();

const expect = require('chai').expect;
const bddStdin = require('bdd-stdin');
const proxyquire = require('proxyquire');
Expand All @@ -26,7 +21,8 @@ const projects = proxyquire('../controller/projects', {
}
});

const readAndParse = path => JSON.parse(fs.readFileSync(path));
const readAndParse = path =>
JSON.parse(fs.readFileSync(path).toString('utf-8'));
const projectsDirectory = './test/files/environment/projects';
const projectEntriesPath = './test/files/environment/projects/projects.json';

Expand Down Expand Up @@ -112,7 +108,7 @@ describe('projects', function () {
.selectProject({ session: dummySession, projectAction: 'install' })
.then(function (project) {
expect(project).to.be.an.object;
expect(project.name).to.equal('Matchy');
expect(project.name).to.equal('Function Master');
expect(project._id).to.exist;
expect(project._session).to.exist;
expect(project.desc).to.exist;
Expand All @@ -123,6 +119,14 @@ describe('projects', function () {
});

describe('#installProject()', function () {
before(function (done) {
if (fs.existsSync(projectsDirectory)) {
rimraf(projectsDirectory, () => done());
} else {
done();
}
});

it('should install project', function (done) {
projects.installProject(dummySession.PROJECT[2]).then(function (project) {
expect(project).to.be.an.object;
Expand Down Expand Up @@ -235,12 +239,22 @@ describe('projects', function () {
it('should shelve project', function (done) {
const path = `${projectsDirectory}/underpants`;
const newPath = `${projectsDirectory}/_underpants`;
expect(fs.existsSync(path)).to.be.true;
expect(fs.existsSync(newPath)).to.be.false;
expect(fs.existsSync(path), `path: "${path}" should initially exist`).to
.be.true;
expect(
fs.existsSync(newPath),
`path: "${newPath}" should not initially exist`
).to.be.false;
bddStdin('y\n');
projects.shelveProject(dummySession.PROJECT[0]).then(function (resPath) {
expect(fs.existsSync(path)).to.be.false;
expect(fs.existsSync(newPath)).to.be.true;
expect(
fs.existsSync(path),
`path: "${path}" should not exist`
).to.be.false;
expect(
fs.existsSync(newPath),
`path: "${newPath}" should exist`
).to.be.true;
expect(resPath).to.equal(newPath);
done();
});
Expand Down

0 comments on commit 5b42af1

Please sign in to comment.