-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (56 loc) · 1.74 KB
/
index.js
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
68
69
70
71
72
// native
var path = require('path');
var fs = require('fs');
var q = require('q');
// internal
var DomFile = require('./lib/dom-file');
/**
* Object that represents the filesystem
* @param {[type]} root [description]
* @param {[type]} options [description]
*/
var DomFs = function (root, options) {
// root of the filesystem
this.root = root;
// TODO: DomFs is not keeping references to open (and possibly edited)
// DomFiles. With this, all further calls to getFile of a modified and
// unsaved file will return file objects with unmodified content
// object to hold the file
this.files = {};
};
/**
* Creates a file object
* @param {[type]} fileRelativePath [description]
* @return {[type]} [description]
*/
DomFs.prototype.getFile = function (fileRelativePath) {
var fullPath = path.join(this.root, fileRelativePath);
return new DomFile(fullPath);
};
/**
* Creates a new page in the templates folder
*/
DomFs.prototype.createNewPage = function(pageData) {
var deferred = q.defer();
var dir = path.join(this.root, 'www', 'templates');
/*
* First we need to make sure that there is a template folder inside
* the project's root folder.
*/
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
/*
* Then, we'll create a new file with a default content.
*/
var content = '<ion-view view-title=\"' + pageData.label + '\"><ion-content></ion-content></ion-view>';
fs.writeFile(path.join(this.root, 'www', 'templates', pageData.name + '.html'), content, function(err) {
if (err) {
deferred.reject(err);
}
deferred.resolve();
});
return deferred.promise;
}
// Export the class
module.exports = DomFs;