Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

move-reusables-to-markdown.js 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const flat = require('flat')
  5. const { get } = require('lodash')
  6. const walk = require('walk-sync').entries
  7. const yaml = require('js-yaml')
  8. const mkdirp = require('mkdirp').sync
  9. const languages = require('../lib/languages')
  10. // [start-readme]
  11. //
  12. // This script moves reusables out of YAML files into individual Markdown files.
  13. //
  14. // [end-readme]
  15. // move reusables for each language
  16. Object.values(languages).forEach(({ dir }) => move(dir))
  17. function move (dir) {
  18. const fullDir = path.join(__dirname, '..', dir, 'data/reusables')
  19. console.log('removing', fullDir)
  20. walk(fullDir)
  21. .filter(entry => entry.relativePath.endsWith('yml'))
  22. .forEach(file => {
  23. const fullPath = path.join(file.basePath, file.relativePath)
  24. const fileContent = fs.readFileSync(fullPath, 'utf8')
  25. const data = flat(yaml.load(fileContent))
  26. Object.keys(data).forEach(key => {
  27. const value = get(data, key)
  28. const markdownFilename = path.join(fullPath.replace('.yml', ''), `${key}.md`)
  29. mkdirp(path.dirname(markdownFilename))
  30. fs.writeFileSync(markdownFilename, value)
  31. console.log('created new markdown file ', path.relative(file.basePath, markdownFilename))
  32. })
  33. })
  34. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...