Skip to content
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

Adds skills folder to repo and loads markdown for each skill #302 #336

Closed
wants to merge 11 commits into from
  •  
  •  
  •  
96 changes: 66 additions & 30 deletions bin/rename-skill
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const usage = () => {
console.log(
`Usage:
rename-skill CURRENT_SKILL_NAME NEW_SKILL_NAME [NEW_SKILL_NAME [NEW_SKILL_NAME […]]]

both CURRENT_SKILL_NAME and NEW_SKILL_NAME should be the skill as written in the markdown.
i.e. with spaces and backticks etc. - wrap entire skill name in quotes.
`
)
process.exit(1)
Expand All @@ -29,35 +32,68 @@ console.log(
chalk.magenta(util.inspect(newSkillNames))
)

const renameSkillsWithinModules = () =>
generateDigest().then(digest => {
const skillId = nameToId(currentSkillName)
const modules = Object.values(digest.modules).filter(module =>
module.skills.includes(skillId)
)

return Promise.all(
modules.map(renameSkillsWithinModule)
)
})

const skillNameToMarkdown = skillName =>
`- ${skillName}\n`

const renameSkillsWithinModule = (module) => {
const absolutePath = path.resolve(__dirname, `..${module.path}/README.md`)
console.log(
'%s %s',
chalk.green('updating module'),
module.path
)
return fs.readFile(absolutePath).then(markdown => {
markdown = markdown.toString().replace(
"\n"+skillNameToMarkdown(currentSkillName),
"\n"+newSkillNames.map(skillNameToMarkdown).join('')
)
return fs.writeFile(absolutePath, markdown)
})
const renameSkills = () => {
const skillId = nameToId(currentSkillName)
const getSkillName = () => {
return generateDigest()
.then(digest => {
const modules = Object.values(digest.modules).filter(module => {
return module.skills.includes(skillId)
})
const skills = Object.values(digest.skills).filter(skill => {
return Object.values(skill).includes(skillId)
})
return {modules, skills}
})
}

const skillNameToMarkdown = skillName =>
`- ${skillName}\n`

const writeSkillName = ({modules, skills}) => {
const arrayOfModulePromises = modules.map(module => {
const absolutePath = path.resolve(__dirname, `..${module.path}/README.md`)
console.log(
'%s %s',
chalk.green('updating module'),
module.path
)
return fs.readFile(absolutePath).then(markdown => {
markdown = markdown.toString().replace(
"\n"+skillNameToMarkdown(currentSkillName),
"\n"+newSkillNames.map(skillNameToMarkdown).join('')
)
return fs.writeFile(absolutePath, markdown)
})
})

const arrayOfSkillPromises = skills.map(skill => {
const oldMarkdownPath = path.join(__dirname, '..', skill.markdownFilePath)
const newMarkdownPath = path.join(
__dirname,
'..',
'skills'
) + '/' + nameToId(newSkillNames[0]) + '.md'
return fs.readFile(oldMarkdownPath)
.then(buffer => buffer.toString())
.then(skillContent => {
const newText = skillContent.replace(/\#.*\n/, `# ${newSkillNames[0]}\n`)
return fs.writeFile(newMarkdownPath, newText)
})
.then( (error) => {
if (error) {
console.log(`\nError in ${newMarkdownPath}\n`);
console.log(error)
}
return fs.unlink(oldMarkdownPath)
})
})

return Promise.all([...arrayOfModulePromises, ...arrayOfSkillPromises])
}

return getSkillName()
.then(writeSkillName)
}

const generateMigration = () => {
Expand Down Expand Up @@ -111,7 +147,7 @@ const yyyymmddhhmmss = () => {

Promise.all([
generateMigration(),
renameSkillsWithinModules(),
renameSkills(),
]).then(_ => {
process.exit(0)
})
Expand Down
99 changes: 99 additions & 0 deletions bin/skillsPopulate
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env node

const fs = require('fs')

const digest = require('../digest')

function fsPromise(funcName, params) {
return new Promise((resolve, reject) => {
fs[funcName](...params, (error, result) => {
if (error) {
reject(error)
return
}
resolve(result)
})
})
}

function makeDirectories() {
digest()
.then(digestInfo => Object.keys(digestInfo.skills))
.then(skillsArray => {
const arrOfDirs = []
skillsArray.forEach(skill => {
skill = skill.replace(/[\'\,\/]/g, '-')
arrOfDirs.push(fsPromise('mkdir', ['./skills/' + skill]))
})
})
}

function main(args) {
if (args.length <= 2 || args.length > 3) {
console.log(
`Not enough arguments.\n` +
`Usage: ./bin/${args[1].match(/[^\/]*$/g)[0]} <dirs | populate>\n\n` +
`dirs: Make empty directories based on module folder names\n` +
`populate: Create sample README.md files in each skill folder\n`
)
return
}

({
'dirs': makeDirectories,
'skills': createSkillsListTest,
'populate': createSkillsList,
})[args[2]]()
}

let skillsId = []
let skillsName = []

function createSkillsListTest() {
digest()
.then(digestInfo => {
const digestSkills = digestInfo.skills
for(let skill in digestSkills) {
skillsId.push(skill)
skillsName.push(digestSkills[skill].name)
}
})
.catch(error => {
console.error('Something went wrong', error)
})
}

function createSkillsList() {
digest()
.then(digestInfo => {
const digestSkills = digestInfo.skills
for(let skill in digestSkills) {
skillsId.push(skill)
skillsName.push(digestSkills[skill].name)
}
return createSampleFiles(skillsId, skillsName)
})
.catch(error => {
console.error('Something went wrong', error)
})
}

function createSampleFiles(skillsId, skillsName) {
console.log('skill Title length ---', skillsId.length)
for(let i = 0; i < skillsId.length; i++){
const sampleData =
`# ${skillsName[i]}\n\n` +
`_description tbd_\n\n` +
`## Resources\n\n` +
`### Reading\n\n` +
`_nothing here yet, please add something_\n\n` +
`### Watching\n\n` +
`_nothing here yet, please add something_\n`

fsPromise('writeFile', [`./skills/${skillsId[i]}.md`, sampleData])
}
return true
}


main(process.argv)
1 change: 1 addition & 0 deletions digest/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = digest => {
rawText,
modules: [],
path: `/skills/${encodeURIComponent(id)}`,
markdownFilePath: `/skills/${id}.md`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know i asked for this but i've changed my mind :)

}
const preExistingSkill = digest.skills[id]
if (preExistingSkill){
Expand Down
7 changes: 5 additions & 2 deletions modules/Grocery-Queries/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Grocery Queries Exercise

___Note:__ This module assumes you've already installed postgresql via homebrew. If you have not done that please do back and do the [Installfest](../Installfest) module._
___Note:__ This module assumes you've already installed postgresql via homebrew. If you
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes should not be in this PR. please remove

Copy link
Author

@lumodon lumodon Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very curious that our README somehow picked up those changes. Not even sure what or whose branch that is from. Will revert... just curiously commenting.

edit: git blame helped here. Somehow my "Fixes last minute mistakes" commit introduced this new mistake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very curious that our README somehow picked up those changes.
Well technically you committed these changes and worse you submitted them for reviews. This is the perfect time for you to focus on leveling up your git hygiene. Get into the habit of always using git add -p and before you open a PR always: rebase off upstream/master and consider squashing and polishing your commits. double or even triple check the diff.

have not done that please do back and do the [Installfest](../Installfest)
module._

## Skills

___Note:__ all of the skills below are applicable to any SQL server but were practicing them in postgresql_
___Note:__ all of the skills below are applicable to any SQL server but were
practicing them in postgresql_

- Can select everything from a single table in SQL
- Can select specific columns from a single table in SQL
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "nodemon web-server",
"start": "node web-server",
"db:migrate": "knex migrate:latest",
"test": "mocha -G -r ./mocha.config.js $(find digest web-server database backoffice | grep .test.js) ",
"test": "mocha -G -r ./mocha.config.js $(find digest web-server database backoffice skills | grep .test.js) ",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we'll put any tests in there. please remove this change

"test:watch": "npm test -- --watch",
"webpack": "webpack --config ./web-server/webpack.config.js",
"heroku-prebuild": "npm install && npm run webpack"
Expand Down
13 changes: 13 additions & 0 deletions skills/Can-add-.-node_modules-.bin-to-your-$PATH,-in-the-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add `./node_modules/.bin` to your `$PATH`, in the shell

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
13 changes: 13 additions & 0 deletions skills/Can-add-Git-metadata-to-your-shell-prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add Git metadata to your shell prompt

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add a custom bin directory to their Shell config, in the terminal

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add authorization to an HTTP API to restrict access to certain resources

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
13 changes: 13 additions & 0 deletions skills/Can-add-features-to-a-pre-existing-Node-codebase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add features to a pre-existing Node codebase

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can add properties to the prototype of a JavaScript Constructor

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
13 changes: 13 additions & 0 deletions skills/Can-affectively-manipulate-the-DOM-in-a-Browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can affectively manipulate the DOM in a Browser

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can assess what an appropriate salary is for my experience level at a hiring company

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
13 changes: 13 additions & 0 deletions skills/Can-author-a-JavaScript-RegExp-with-a-character-set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can author a JavaScript RegExp with a character set

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can author a Regular Expression by using the RegExp constructor

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Loading