forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.js
More file actions
67 lines (64 loc) · 1.42 KB
/
project.js
File metadata and controls
67 lines (64 loc) · 1.42 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var fs = require('fs'),
path = require('path');
module.exports = {
PROJECT_FILE: 'ionic.project',
PROJECT_DEFAULT: {
name: '',
app_id: ''
},
load: function() {
this.file = this.PROJECT_FILE;
if(fs.existsSync(this.file)) {
this.data = JSON.parse(fs.readFileSync(this.file));
} else {
if(fs.existsSync('www')) {
var parts = path.resolve('./').split(path.sep);
var dirname = parts[parts.length-1];
this.create(dirname);
this.save('./');
}
}
return this;
},
create: function(name) {
this.file = this.PROJECT_FILE;
this.data = this.PROJECT_DEFAULT;
if(name) {
this.set('name', name);
}
return this;
},
save: function(targetPath) {
if(!this.data) {
console.trace();
console.error('This should never happen!');
}
try {
fs.writeFileSync((targetPath?targetPath + '/':'') + this.PROJECT_FILE, JSON.stringify(this.data, null, 2));
} catch(e) {
console.error('Unable to save settings file:', e);
}
},
get: function(k) {
if(!this.data) {
return null;
}
if(k) {
return this.data[k];
} else {
return this.data;
}
},
set: function(k, v) {
if(!this.data) {
this.data = this.PROJECT_DEFAULT;
}
this.data[k] = v;
},
remove: function(k) {
if(!this.data) {
this.data = this.PROJECT_DEFAULT;
}
this.data[k] = '';
}
};