* Update dependencies 2 * Lint fixes * Update graphql packages * Update changelog-entry.json * Update @octokit/rest * Update commander with help from @rachmari @rachmari * Upgrade helmet * Upgrade js-yaml * Update server.js * Update cheerio * Revert "Update cheerio" This reverts commit 8aa17c39fbf564ee554037d89e7a473027d16984.
40 lines
1.3 KiB
JavaScript
Executable File
40 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const flat = require('flat')
|
|
const { get } = require('lodash')
|
|
const walk = require('walk-sync').entries
|
|
const yaml = require('js-yaml')
|
|
const mkdirp = require('mkdirp').sync
|
|
const languages = require('../lib/languages')
|
|
|
|
// [start-readme]
|
|
//
|
|
// This script moves reusables out of YAML files into individual Markdown files.
|
|
//
|
|
// [end-readme]
|
|
|
|
// move reusables for each language
|
|
Object.values(languages).forEach(({ dir }) => move(dir))
|
|
|
|
function move (dir) {
|
|
const fullDir = path.join(__dirname, '..', dir, 'data/reusables')
|
|
console.log('removing', fullDir)
|
|
walk(fullDir)
|
|
.filter(entry => entry.relativePath.endsWith('yml'))
|
|
.forEach(file => {
|
|
const fullPath = path.join(file.basePath, file.relativePath)
|
|
const fileContent = fs.readFileSync(fullPath, 'utf8')
|
|
const data = flat(yaml.load(fileContent))
|
|
|
|
Object.keys(data).forEach(key => {
|
|
const value = get(data, key)
|
|
const markdownFilename = path.join(fullPath.replace('.yml', ''), `${key}.md`)
|
|
mkdirp(path.dirname(markdownFilename))
|
|
fs.writeFileSync(markdownFilename, value)
|
|
console.log('created new markdown file ', path.relative(file.basePath, markdownFilename))
|
|
})
|
|
})
|
|
}
|