1 |
|
2 | (function() {
|
3 | var cache, fs, mkdirp, userHome, yaml;
|
4 |
|
5 | fs = require('fs');
|
6 |
|
7 | mkdirp = require('mkdirp');
|
8 |
|
9 | userHome = require('user-home');
|
10 |
|
11 | yaml = require('js-yaml');
|
12 |
|
13 | cache = function(key, val, debug) {
|
14 | var crystal, crystal_file, crystal_path;
|
15 | crystal_path = userHome + "/.autocode/";
|
16 | crystal_file = crystal_path + "crystal.yml";
|
17 | crystal = fs.existsSync(crystal_file) ? yaml.safeLoad(fs.readFileSync(crystal_file)) : {};
|
18 | if (!crystal.cache) {
|
19 | crystal.cache = {};
|
20 | }
|
21 | if (val !== void 0) {
|
22 | crystal.cache[key] = val;
|
23 | fs.writeFileSync(crystal_file, yaml.safeDump(crystal));
|
24 | }
|
25 | if (debug) {
|
26 | console.log("File: " + crystal_file);
|
27 | console.log("Method: crystal.cache(key, val)");
|
28 | console.log("Key: " + key);
|
29 | console.log("Value: " + crystal.cache[key] + "\n");
|
30 | }
|
31 | return crystal.cache[key];
|
32 | };
|
33 |
|
34 | module.exports = cache;
|
35 |
|
36 | }).call(this);
|