-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·46 lines (27 loc) · 945 Bytes
/
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
#!/usr/bin/env node
var fs = require("fs");
var _ = require("underscore-node");
//set dir
var dir = process.argv[2] || "./";
var newFileDir = dir+"converted/";
//create 'converted' directory
try{ fs.mkdirSync(newFileDir); } catch(e){}
//get js files
var jsFiles = _.reject(fs.readdirSync(dir),function(file){
return !file.match(".js");
});
var moduleWrap = function(str){
var file = "/*\n* Author: [email protected]\n*/\ndefine(['libs/movieclip'],function(createjs){\nvar spritesheet; //container for spritesheet\n";
file += str.replace(" = "," = spritesheet = ");
file += "\nreturn spritesheet;\n});";
return file;
};
var processFile = function(name){
var filePath = dir+name,
file = fs.readFileSync( filePath, "utf8" ),
wrappedFile = moduleWrap(file),
newFilePath = newFileDir+name.replace(/\s/g,"-");
fs.writeFileSync( newFilePath, wrappedFile);
};
//process all JS files
_(jsFiles).each(processFile);