1 |
|
2 | (function() {
|
3 | var cson, fs, mkdirp, userHome;
|
4 |
|
5 | cson = require('season');
|
6 |
|
7 | fs = require('fs');
|
8 |
|
9 | mkdirp = require('mkdirp');
|
10 |
|
11 | userHome = require('user-home');
|
12 |
|
13 | module.exports = function(opts) {
|
14 | var crystal, crystal_file, crystal_path, key, method, value;
|
15 | key = opts._[1];
|
16 | method = opts._[2];
|
17 | value = opts._[3];
|
18 | crystal_path = userHome + "/.autocode/";
|
19 | crystal_file = crystal_path + "crystal.cson";
|
20 | crystal = fs.existsSync(crystal_file) ? cson.readFileSync(crystal_file) : {};
|
21 | if (!crystal["default"]) {
|
22 | crystal["default"] = {};
|
23 | }
|
24 | if (!crystal["default"][key]) {
|
25 | crystal["default"][key] = [];
|
26 | }
|
27 | switch (method) {
|
28 | case 'add':
|
29 | crystal["default"][key][value] = {
|
30 | path: '.',
|
31 | version: 'latest'
|
32 | };
|
33 | break;
|
34 | case 'remove':
|
35 | delete crystal["default"][key][value];
|
36 | break;
|
37 | default:
|
38 | return crystal["default"][key];
|
39 | }
|
40 | mkdirp.sync(crystal_path);
|
41 | fs.writeFileSync(crystal_file, cson.stringifySync(crystal));
|
42 | return crystal["default"][key];
|
43 | };
|
44 |
|
45 | }).call(this);
|