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

Impements skills markdown into skills page #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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, '..', `/skills/${skill.id}.md`)
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`,
}
const preExistingSkill = digest.skills[id]
if (preExistingSkill){
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_
13 changes: 13 additions & 0 deletions skills/Can-author-a-Regular-Expression-literal-in-JavaScript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Can author a Regular Expression literal in JavaScript

_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 avoid defining global variables in Browser JavaScript

_description tbd_

## Resources

### Reading

_nothing here yet, please add something_

### Watching

_nothing here yet, please add something_
Loading