MCPcopy Index your code
hub / github.com/github/docs / DataDirectory

Class DataDirectory

tests/helpers/data-directory.js:43–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41// will create a single <tempdir>/data/ui.yml file.
42//
43export class DataDirectory {
44 constructor(data, root) {
45 this.root = root || this.createTempRoot('data-directory')
46 this.create(data)
47 }
48
49 createTempRoot(prefix) {
50 const fullPath = path.join(os.tmpdir(), prefix)
51 return fs.mkdtempSync(fullPath)
52 }
53
54 create(data, root = null, isVariables = false, isReusables = false) {
55 const here = root || this.root
56
57 for (const [key, value] of Object.entries(data)) {
58 if (isReusables) {
59 if (typeof value === 'string') {
60 fs.writeFileSync(path.join(here, `${key}.md`), value, 'utf-8')
61 } else {
62 fs.mkdirSync(path.join(here, key))
63 this.create(value, path.join(here, key), false, true)
64 }
65 } else if (isVariables) {
66 fs.writeFileSync(path.join(here, `${key}.yml`), yaml.dump(value), 'utf-8')
67 } else {
68 if (key === 'ui') {
69 fs.writeFileSync(path.join(here, `${key}.yml`), yaml.dump(value), 'utf-8')
70 } else {
71 const there = path.join(here, key)
72 fs.mkdirSync(there)
73 if (key === 'reusables') {
74 this.create(value, there, false, true)
75 } else if (key === 'variables') {
76 this.create(value, there, true, false)
77 } else {
78 this.create(value, there)
79 }
80 }
81 }
82 }
83 }
84
85 destroy() {
86 fs.rmSync(this.root, { recursive: true })
87 }
88}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected