MCPcopy Create free account
hub / github.com/acode/cli / Config

Class Config

cli/config.js:9–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7const CONFIG_VAR_TIMESTAMP = 'CREATED_AT';
8
9class Config {
10
11 constructor (pathname, filename) {
12 this.pathname = pathname || DEFAULT_PATHNAME;
13 this.filename = filename || DEFAULT_FILENAME;
14 this.data = this.load();
15 }
16
17 fullpath () {
18 return path.join(this.pathname, this.filename);
19 }
20
21 location (depth) {
22 depth = depth || 0;
23 let loc = process.cwd();
24 let pathnames = loc.split(path.sep);
25 // If Window directory drive, don't add starting "/"
26 let fullpath = pathnames[0].indexOf(':') > -1 ?
27 path.join.apply(path, pathnames.slice(0, pathnames.length - depth)) :
28 path.join.apply(path, ['/'].concat(pathnames.slice(0, pathnames.length - depth)));
29 return this.workspace() &&
30 depth <= pathnames.length &&
31 fullpath.toLowerCase() === this.workspace().toLowerCase();
32 }
33
34 workspace () {
35 return this.get(CONFIG_VAR_WORKSPACE);
36 }
37
38 legacypath () {
39 let cwd = process.cwd();
40 let directories = cwd.split(path.sep);
41 let pathname;
42 for (let i = directories.length; i > 0; i--) {
43 let relpath = path.join(directories.slice(0, i).join(path.sep), LEGACY_FILENAME);
44 if (fs.existsSync(relpath)) {
45 pathname = relpath;
46 break;
47 }
48 }
49 return pathname;
50 }
51
52 load () {
53 if (!fs.existsSync(this.fullpath())) {
54 let legacypath = this.legacypath();
55 if (legacypath) {
56 let legacydirs = legacypath.split(path.sep);
57 legacydirs.pop();
58 let legacydir = legacydirs.join(path.sep);
59 this.initialize(
60 legacydir,
61 this.read(legacypath)
62 )
63 } else {
64 this.write({});
65 }
66 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected