Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Jakefile
blob: 6c358ba2d7db363537486c6f408c8adfaaa88372 (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env narwhal
 
var FILE = require("file"),
    ENV = require("system").env,
    OS = require("os"),
    JAKE = require("jake");

var buildDir = './build',
    bundleDir = FILE.join(buildDir, 'bundle'),
    lessonsDir = FILE.join(buildDir, 'lessons'),
    htmlDir = bundleDir;
		     

var LESSONS = [ ['~/tmp/karma_lesson1', 'karma_lesson1'],
		['~/tmp/karma_lesson2', 'karma_lesson2'],
		['~/tmp/karma_lesson3', 'karma_lesson3'],
	     // [" git://git.sugarlabs.org/karma_adding_up_to_10_svg/mainline.git", 
             // "karma_adding_up_to_10_svg"], 
	     // ["gitorious@git.sugarlabs.org:karma_conozco-uruguay/mainline.git", 
	     //  'karma_Conozco-Uruguay'],
	     // ["~/karma/lessons/English_Alphabet_Puzzle_Solving", 
	     //  'karma_English_Alphabet_Puzzle_Solving'] 
	    ];
var includedLessons = [];
var bundleType = '';

//Specify which files should be removed by the 'jake clean' and 'jake clobber' tasks
var CLEAN_LIB = require('jake/clean');
var CLEAN = CLEAN_LIB.CLEAN; 
CLEAN.include('**/#*#', '\.#*' , '**/\.tmp*',"**/\.*\.*\.swp");
CLEAN.exclude('\.git');

var CLOBBER = CLEAN_LIB.CLOBBER; 
CLOBBER.include('**/build');
CLOBBER.exclude('\.git');


//docs, documentation
JAKE.task('docs', function(){
	var path = './tools/jsdoc-toolkit';
	 if(FILE.exists(path)){
	     var cmd = 'java -jar ' + path + '/jsrun.jar ' + 
		 path + '/app/run.js ' + './js/ui.kHeader.js ./js/karma.js ./js/ui.kFooter.js ./js/ui.feedback.js -d=docs/ ' +
		 '-t=tools/jsdoc-toolkit/templates/jsdoc/';
	     OS.system(cmd);
	 } else {
	     print("The folder ./tools/jsdoc-toolkit isn't present " +
		   "you need it to generate documentation");
	 }

});

JAKE.task('checkout', function(){
    OS.system('git checkout master;');
});


JAKE.filedir('lessons-dir', function(){
	FILE.mkdirs(lessonsDir);
}); 


JAKE.task('lessons-bundle-dir', function(){
    var lessonsTargetDir = FILE.join(bundleDir, 'lessons');
    if(FILE.exists(lessonsTargetDir)){
	FILE.rmtree(lessonsTargetDir);
    }
    FILE.mkdirs(FILE.join(bundleDir, 'lessons'));
}); 

var prepareEachLessonDir = function(repo, tag){
    var exitCode = '';
    var lessonRepo = repo[0];
    var lessonName = repo[1];
    var cmd = '';
    var lessonDir = FILE.join(lessonsDir, lessonName);

    if(!FILE.exists(FILE.join(lessonDir, '.git'))){
	if(FILE.exists(lessonDir)){
	    FILE.rmdir(lessonDir);
	    FILE.mkdir(lessonDir);
	}

	cmd = "git clone " + lessonRepo + " " + lessonDir;
	OS.system(cmd);
    }

    print(tag);
    cmd = "cd " + lessonDir + ";git pull -t origin master; git checkout " + tag ;
    exitCode = OS.system(cmd);
    
    if(exitCode === 0){
	includedLessons.push(lessonName);
    }
};

var copyLessons = function(){
    includedLessons.forEach(function(lessonName){
	    var lessonDir = FILE.join(bundleDir, 'lessons');
	    var cmdCopyLessons = "cp -r " + lessonsDir + "/" + 
				    lessonName + " " + lessonDir;
	    var cmdRmGitFiles = "find " + bundleDir + " -type d -name '.git' " +
		"-exec rm -rf {} \\; ";
	    OS.system(cmdCopyLessons);
	    OS.system(cmdRmGitFiles);
	});
};


JAKE.task('build-stable', ['checkout', 'lessons-dir', 'lessons-bundle-dir'], function()
{
    LESSONS.forEach(function(lessonRepo) { 
			prepareEachLessonDir(lessonRepo, "stable"); 
		    });
    copyLessons();
});

JAKE.task('build', ['build-latest']);

JAKE.task('build-latest',['checkout', 'lessons-dir', 'lessons-bundle-dir'],  function()
{
    LESSONS.forEach(function(lessonRepo) { 
			prepareEachLessonDir(lessonRepo, "master"); 
		    });
    copyLessons();

});

var copyWebFiles = function(){
     var webSrcFiles = [ './assets', './css', 'index*', './js'];      
   
    webSrcFiles.forEach(function(filename){
	    var cmd = 'cp -rf ' + filename + ' ' + htmlDir;
	    OS.system(cmd);    
    });
};

var existsLessonsBundleDir = function(){
    if(!FILE.exists(FILE.join(bundleDir, 'lessons'))){
	print('you need to run "jake build-stable" or "jake build-latest" ' +
	      ' before you run this command');
	quit();
    }
};

//move js files
var moveJsFiles = function(){
    var cmd = "find " + htmlDir + "/lessons -name '*.js' \\!" +
	    " -name 'lesson.js' -exec mv -n {} " + htmlDir + "/js" + " \\;;" +
	    "find " + htmlDir + "/lessons" + " -name '*.js'" + " \\! " +  
	    "-name 'lesson.js' -exec rm {} \\;";
    OS.system(cmd);
};

//change references
var changeHtmlJsPaths = function(){
    var cmdFindIndexFiles = 
	"find " + htmlDir + "/lessons -name '*.html' -exec ";
    var cmdChangePaths = 
	"sed -i 's/src=\"\\.*\\/*\\(js\\/.*.js\\)\"/src=\"..\\/..\\/\\1\"/g' {} \\;";
    var cmdFixLessonJs = 
	"sed -i 's/src=\"\\.*\\/*\\.*\\/*\\(js\\/lesson.js\\)\"/src=\"\\.\\/\\1\"/g'" +
	" {} \\;";
    var cmd = cmdFindIndexFiles + cmdChangePaths + ';' +
	cmdFindIndexFiles + cmdFixLessonJs;
    OS.system(cmd);
};

JAKE.task('xo-bundle', function(){
    existsLessonsBundleDir();

    var bundleSrc = './tools/xo_bundle/';

    bundleType = "xo";
    OS.system('cp -rf ' + bundleSrc + "/* " + bundleDir );
    htmlDir = FILE.join(htmlDir, 'karma');
    FILE.mkdirs(htmlDir);
    copyWebFiles(htmlDir);

    if(FILE.exists(FILE.join(htmlDir, 'lessons'))){
	FILE.rmtree(FILE.join(htmlDir, 'lessons'));
    }

    FILE.move(FILE.join(bundleDir, 'lessons'), FILE.join(htmlDir, 'lessons'));
    moveJsFiles();
    changeHtmlJsPaths();
});

JAKE.task('web-bundle', function(){
    existsLessonsBundleDir();

    bundleType = 'web';
    copyWebFiles(htmlDir);
    moveJsFiles();
    changeHtmlJsPaths();
});





//clobber

//checkout bundle

//checkout lessons


//delete backup files and commit their removal