2 exists : function(path) {
3 return system.exists(path);
6 getFullPath: function(path) {
7 var currentPath = system.setcwd(path);
8 return system.setcwd(currentPath);
11 getPath: function(path){
12 return path.replace(/\//g, Fs.sep);
15 mkdir: function(path) {
16 if (Platform.isWindows) {
20 Cmd.execute('mkdir -p ' + path);
22 return this.getFullPath(path);
25 readFile : function(file) {
26 if (!Fs.exists(file)) {
27 Logger.log("[ERROR] File '" + file + "' does not exist or is not readable!");
31 file = new Stream(file);
32 var contents = file.readFile();
38 writeFile: function(file, contents) {
39 file = new Stream(file, 'w');
40 file.writeln(contents);
46 copy: function(src, dest) {
47 src = Fs.getPath(src);
48 dest = Fs.getPath(dest);
50 if (Platform.isWindows) {
51 if (Fs.endsWith(src, Fs.sep)) {
52 src = src.slice(0, -1); // cut off any trailing \
56 * Check if we're copying a single file. This isn't bulletproof, however xcopy
57 * will prompt regarding if the item is a directory or file, with no way to
58 * suppress the prompt. As such, this will catch a majority of scenarios
59 * and actually make the build work!
61 var isFile = /\.[0-9a-z]{2,4}$/i;
62 if (isFile.test(src)) {
63 system.copy(src, dest);
65 Cmd.execute('xcopy ' + src + ' ' + dest + ' /E /Y /I');
72 // u: only update if newer
73 // p: keep permissions
74 // L: copy the contents of symlinks
75 Cmd.execute('rsync -qrupL ' + src + ' ' + dest);
78 Cmd.execute('cp -Rpf ' + src + ' ' + dest);
83 endsWith: function(str, last){
84 return str.lastIndexOf(last) == str.length - 1;
87 split: function(file) {
89 if (!Fs.exists(file)) {
92 file = new Stream(file);
94 split.push(file.readln().trim());
99 remove: function(file) {
100 if (Platform.isWindows) {
103 Cmd.execute('rm -Rf "' + file + '"');
108 // Create short alias
111 Fs.sep = (Fs.getFullPath('.')[0] == '/') ? '/': '\\';
112 Fs.fileWorkingDir = Fs.getFullPath('.');