forked from tidev/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_test.js
executable file
·82 lines (71 loc) · 1.89 KB
/
create_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
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
os = require('os');
var EOL = os.EOL;
// ensure we're targeting the right folder
var TESTING_FOLDER = path.join(__dirname,'..','test','apps','testing');
if (!fs.existsSync(TESTING_FOLDER)) {
die('"testing" folder does not exist at ' + rel(TESTING_FOLDER));
}
// get the name of the test app to be created
var args = process.argv.slice(2);
var appName = args[0];
if (!appName) {
die('You must specify a name for the test app you want to create');
}
// make sure this doesn't already exist, then create it
var pathToTest = path.join(TESTING_FOLDER,appName);
if (fs.existsSync(pathToTest)) {
die('Test app "' + appName + '" already exists at "' + rel(pathToTest) + '"');
}
fs.mkdirSync(pathToTest, 0755);
console.log('* Created folder ' + YELLOW(rel(pathToTest)));
var files = [
{
folder: path.join(pathToTest,'views'),
file: 'index.xml',
data:
'<Alloy>' + EOL +
'\t<Window>' + EOL +
'\t</Window>' + EOL +
'</Alloy>'
},
{
folder: path.join(pathToTest,'controllers'),
file: 'index.js',
data: '$.index.open();'
},
{
folder: path.join(pathToTest,'styles'),
file: 'index.tss',
data:
"'#index': {" + EOL +
"\tbackgroundColor: '#fff'," + EOL +
"\tfullscreen: false," + EOL +
"\texitOnClose: true" + EOL +
"}"
}
];
for (var i = 0; i < files.length; i++) {
var o = files[i];
var fullpath = path.join(o.folder,o.file);
fs.mkdirSync(o.folder, 0755);
fs.writeFileSync(fullpath, o.data);
console.log('* Created file ' + YELLOW(rel(fullpath)));
}
console.log(GREEN('test app ' + appName + ' successfully created.'));
// helper functions
function rel(p) {
return path.relative(process.cwd(), p);
}
function GREEN(s) {
return '\u001b[32m' + s + '\u001b[0m';
}
function YELLOW(s) {
return '\u001b[33m' + s + '\u001b[0m';
}
function die(msg) {
console.error('\u001b[31m' + 'ERROR: ' + msg + '\u001b[0m');
process.exit(1);
}