-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
159 lines (127 loc) · 3.05 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//Import dependencies
var keue = require('keue');
//Import project manager
var project = require('./index.js');
//Get the new keue object
var k = new keue();
//File and directory variables
var file = null, directory = null;
//Test the templating
k.then(function(next)
{
//Get the path
var path = '/hello/this/{var1}/a/{var2}';
//Replace elements
var elements = { var1: 'is', var2: 'test' };
//Build the template
var build = project.template(path, elements);
//Display in console
console.log('Expected: /hello/this/is/a/test ');
console.log('Generated: ' + build);
//Next test
return next();
});
//Test files
k.then(function(next)
{
//Get the new file
file = new project.file('./test.json', { json: true });
//Display in console
console.log('New file: ' + file.path);
//Check if file exists
file.exists(function(exists)
{
//Display if exists
console.log('File exists?: ' + exists);
//Continue
return next();
});
});
//Write the file
k.then(function(next)
{
//Write some content to the file
file.write({ value: 'This is a test' }, function(error)
{
//Check the error
if(error){ throw error; }
//Read the file content
file.read(function(error, data)
{
//Check the error
if(error){ throw error; }
//Display the content
console.log('File content: ' + JSON.stringify(data));
//Continue
return next();
});
});
});
//Test update the file content
k.then(function(next)
{
//Function to update the content
var fn = function(data){ data['value'] = 'Ups...'; return data; };
//Update the file content
file.map(fn, function(error)
{
//Check error
if(error){ throw error; }
//Read the file
file.read(function(error, data)
{
//Check the error
if(error){ throw error; }
//Display the file content
console.log('File content: ' + JSON.stringify(data));
//Continue
return next();
});
});
});
//Delete the file
k.then(function(next)
{
//Delete the file
file.delete(function(error)
{
//Check the error
if(error){ throw error; }
//Display in console
console.log('File deleted: ' + file.path);
//Continue
return next();
});
});
//Create the directory
k.then(function(next)
{
//Get the new directory
directory = new project.directory('./my-dir/');
//Display the directory path in console
console.log('Directory path: ' + directory.path);
//Check if directory exists
directory.exists(function(exists)
{
//Check if exists
console.log('Directory exists: ' + exists);
//Create the directory
directory.create(function(error)
{
//Check the error
if(error){ throw error; }
//Display in console
console.log('Directory ' + directory.path + ' created');
//Delete the directory
directory.delete(function(error)
{
//Check the error
if(error){ throw error; }
//Display in console
console.log('Directory ' + directory.path + ' deleted');
});
});
});
});
//Run the keue
k.run();