forked from appcelerator-archive/titanium_mobile_tizen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·179 lines (152 loc) · 5.56 KB
/
build.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env node
// simple hack to enable debugger output
process.env.DEBUG = process.env.DEBUG || 'BUILD:info';
require('shelljs/global');
var fs = require('fs'),
path = require('path'),
async = require('async'),
debug = require('debug'),
args = process.argv.slice(2),
branchName, repoPath, titaniumTizenSdk;
// silence shelljs output
config.silent = true;
// create info logger
var info = debug('BUILD:info');
info('Starting');
// command-line arguments:
// args[0]: path to a titanium_mobile repo
// args[1]: target branch, master by default
repoPath = args[0];
titaniumTizenSdk = path.join(repoPath, 'tizen');
branchName = args[1] || 'master';
// Validating path to repo
if (!fs.existsSync(repoPath)) {
info('Error: param 1 should point to an existng zip archive. Current value: ' + args[0]);
process.exit(1);
}
async.series(
[
function(next) {
// check out and switch branch
gitCheckout(repoPath, branchName, function(){
next(null, 'ok');
});
}, function(next) {
// Some mobileweb modules/files are excluded from Tizen:
// - MobileWeb-specific Facebook support implemetation cannot work on Tizen
// - iOS specific startup images are unneeded on Tizen
var exclude = [
path.join(titaniumTizenSdk, 'titanium/Ti/Facebook'),
path.join(titaniumTizenSdk, 'titanium/Ti/Facebook.js'),
path.join(titaniumTizenSdk, 'resources/apple_startup_images'),
path.join(titaniumTizenSdk, 'templates/app/default/Resources/mobileweb/apple_startup_images')
],
createDirs = [ // Lists directories that will be created
'utils'
],
supportFiles = [ // Additional directories that will be copied to the result
'support/mobileweb/closureCompiler',
'support/mobileweb/imageResizer',
'support/mobileweb/minify',
'support/mobileweb/resources'
],
// Files that override original MobileWeb files on Tizen.
// (signapp.jar is unique for Tizen and implements wgt signing.)
overrideFiles = [
{src : 'titanium/Ti/*', dst : 'titanium/Ti/'},
{src : 'cli/commands/*', dst : 'cli/commands/'},
{src : 'titanium/Ti.js', dst : 'titanium/'},
{src : 'templates/*', dst : 'templates/'},
{src : 'src/*', dst : 'src/'},
{src : 'dependencyAnalyzer/*', dst : 'dependencyAnalyzer/'},
{src : 'themes/*', dst : 'themes/'},
{src : 'package.json', dst : 'package.json'},
{src : 'utils/signApp.jar', dst : 'utils/'},
{src : 'utils/7zip/7za.exe', dst : 'utils/'},
{src : 'utils/7zip/license.txt', dst : 'utils/'}
];
info('Clean up, deleting ' + titaniumTizenSdk);
rm('-rf', titaniumTizenSdk);
// MobileWeb is base for Tizen.
cp('-fR', path.join(repoPath, 'mobileweb', '*'), titaniumTizenSdk);
// This script works before Titanium SDK build process creates a ready-to-use mobileweb directory.
// So we have to copy supporting files on our own.
supportFiles.forEach( function (pth) {
info('copy ' + path.join(repoPath, pth) + ' into ' + titaniumTizenSdk);
cp('-fR', path.join(repoPath, pth), titaniumTizenSdk);
});
createDirs.forEach( function (dirpath) {
mkdir(path.join(titaniumTizenSdk, dirpath));
});
// Remove directories marked for exclusion
rm('-rf', exclude);
// Override MobileWeb files
overrideFiles.forEach( function (patch) {
info('copy ' + path.join(__dirname, patch.src) + ' into ' + path.join(titaniumTizenSdk, patch.dst));
cp('-fR', path.join(__dirname, patch.src), path.join(titaniumTizenSdk, patch.dst));
});
next(null, 'ok');
}, function(next) {
try{
// Generating with dependencyAnalyzer tool
info('Loading dependencyAnalyzer.js');
var depCheck = require('./dependencyAnalyzer/dependencyAnalyzer');
depCheck(repoPath + '/');
} catch(e) {
info('dependencyAnalyzer failed: ' + e);
}
next(null, 'ok');
}, function(next) {
// Package the Tizen wrapper module and place it into titanium_mobile/support/module/packaged
var packer = require('child_process'),
packagesModules = path.join(repoPath, 'support','module','packaged'),
random = Math.random ().toString ().substring (2),
workingDir = path.join(tempdir(), random),
cmdzip = 'zip -q -r "' + path.join(packagesModules,'tizen-tizen-3.0.0.zip') + '" *';
// remove tizen-tizen-3.0.0.zip if it exists
rm('-rf', path.join(packagesModules,'tizen-tizen-3.0.0.zip'));
//create temporary dir and its structire
fs.mkdirSync(workingDir);
fs.mkdirSync(path.join(workingDir, 'modules'));
fs.mkdirSync(path.join(workingDir, 'modules', 'tizen'));
fs.mkdirSync(path.join(workingDir, 'modules', 'tizen','tizen'));
fs.mkdirSync(path.join(workingDir, 'modules', 'tizen','tizen','3.0.0'));
cp('-R', path.join(__dirname, 'modules', 'tizen') + '/*', path.join(workingDir, 'modules', 'tizen', 'tizen','3.0.0'));
// Create archive with the Tizen wrapper module
info('zip cmd: ' + cmdzip);
packer.exec(
cmdzip, {
cwd: workingDir
}, function(err, stdout, stderr) {
info(stdout);
// remove the temporary directory
rm('-rf', workingDir);
next(null, 'ok');
});
}
], function(err) {
if (err) {
info(err);
}
info('Preparing Tizen for Titanium SDK finished.');
});
function gitCheckout(workingDir, branch, finish) {
var executor = require('child_process'),
cmd = 'git checkout -f ' + branch;
info('git cmd: ' + cmd);
executor.exec(
cmd, {
cwd: workingDir
}, function(err, stdout, stderr) {
info(stdout);
if (stdout) {
info(stdout);
}
if (err) {
info(stderr);
} else {
info('git ok');
}
finish(null);
});
}