Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / build / build-bootstrap-data.js
1 var startTime = Date.now();
2
3 load('../../jsbuilder/src/Filesystem.js');
4 load('../../jsbuilder/src/Logger.js');
5 load('../../jsbuilder/src/Platform.js');
6 load('../../jsbuilder/src/Cmd.js');
7
8 function pathToNamespace(path) {
9     var escapedSep = Ext.String.escapeRegex(Fs.sep);
10
11     return path.replace(new RegExp('^' + escapedSep), '')
12                .replace(new RegExp(escapedSep, 'g'), '.')
13                .replace(/\.js$/, '');
14 }
15
16
17 var PATH = {
18     BUILD: Fs.getFullPath('./'),
19     ROOT: Fs.getFullPath('../'),
20     JSBUILDER: Fs.getFullPath('../../jsbuilder/src'),
21     PLATFORM: Fs.getFullPath('../../platform/src'),
22     EXTJS: Fs.getFullPath('../src')
23 };
24
25 var sdkManifest = JSON.parse(Fs.readFile('sdk.jsb3')),
26     foundationFiles = [],
27     coreFiles = [];
28
29 sdkManifest.packages.forEach(function(pkg) {
30     if (pkg.id === 'foundation') {
31         foundationFiles = pkg.files;
32     }
33
34     if (['foundation', 'extras', 'dom'].indexOf(pkg.id) !== -1) {
35         pkg.files.forEach(function(file) {
36             coreFiles.push((file.path + file.name).replace(/^\.\.\//, ''));
37         });
38     }
39 });
40
41 foundationFiles.forEach(function(file) {
42     load(file.path + file.name);
43 });
44
45 var platformOnlyFolders = [],
46     excludes = JSON.parse(Fs.readFile('ignore.json')),
47     excludeRegex = new RegExp(excludes.map(Ext.String.escapeRegex).join('|'));
48
49 function getPlatformOnlyFolders(path) {
50     system.setcwd(PATH.PLATFORM + Fs.sep + path);
51
52     var folders = system.folders(),
53         currentPath;
54
55     folders.forEach(function(folder) {
56         currentPath = (path) ? (path + Fs.sep + folder) : folder;
57
58         system.setcwd(PATH.EXTJS + Fs.sep + path);
59
60         if (system.folders().indexOf(folder) !== -1) {
61             getPlatformOnlyFolders(currentPath);
62         }
63         else {
64             platformOnlyFolders.push(currentPath);
65         }
66     });
67 }
68
69 getPlatformOnlyFolders('');
70 Logger.log("Folders:\n---------------------------------");
71 Logger.log(platformOnlyFolders.join("\n"));
72
73 var platformOnlyFiles = [];
74
75 function getPlatformOnlyFiles(path) {
76     system.setcwd(PATH.PLATFORM + Fs.sep + path);
77
78     var files = system.files('*.js'),
79         folders = system.folders(),
80         currentPath;
81
82     files.forEach(function(file) {
83         platformOnlyFiles.push(path + Fs.sep + file);
84     });
85
86     folders.forEach(function(folder) {
87         currentPath = (path) ? (path + Fs.sep + folder) : folder;
88
89         if (platformOnlyFolders.indexOf(currentPath) === -1) {
90             getPlatformOnlyFiles(currentPath);
91         }
92     });
93 }
94
95 getPlatformOnlyFiles('');
96 Logger.log("\nFiles:\n---------------------------------");
97 Logger.log(platformOnlyFiles.join("\n"));
98
99 var sourcePaths = [
100         PATH.PLATFORM,
101         PATH.EXTJS
102     ],
103     sourceManifestPath = PATH.BUILD + Fs.sep + "Ext4-manifest.json",
104     classes,
105     alias,
106     parentClassName,
107     allClasses = [],
108     classMap = {},
109     classInheritanceMap = {},
110     nameToAliasesMap = {},
111     alternateToNameMap = {};
112
113 function getAllClasses(root, path) {
114     system.setcwd(root + Fs.sep + path);
115
116     var files = system.files('*.js'),
117         folders = system.folders(),
118         filePath,
119         currentPath;
120
121     files.forEach(function(file) {
122         filePath = path + Fs.sep + file;
123
124         if (filePath.search(excludeRegex) === -1) {
125             allClasses.push('Ext.' + pathToNamespace(filePath));
126         }
127     });
128
129     folders.forEach(function(folder) {
130         currentPath = (path) ? (path + Fs.sep + folder) : folder;
131
132         getAllClasses(root, currentPath);
133     });
134 }
135
136 getAllClasses(PATH.PLATFORM, '');
137 getAllClasses(PATH.EXTJS, '');
138
139 var hammerjsPath = PATH.BUILD + Fs.sep + "bin" + Fs.sep + (system.arguments[1] || "mac") + Fs.sep + "hammerjs";
140
141 Cmd.execute(hammerjsPath + " " + PATH.BUILD + Fs.sep + "build-manifest.js " + sourcePaths.join(',') +
142             " " + sourceManifestPath);
143
144 classes = JSON.parse(Fs.readFile(sourceManifestPath));
145 classes.forEach(function(cls) {
146     classMap[cls.className] = cls;
147 });
148
149 //classes.forEach(function(cls) {
150 //    if (cls.extend) {
151 //        classInheritanceMap[cls.className] = cls.extend;
152 //    }
153 //});
154
155 function getAliasOf(cls) {
156     if (!cls.alias) {
157 //        parentClassName = classInheritanceMap[cls.className];
158 //
159 //        if (parentClassName && classMap[parentClassName]) {
160 //            return getAliasOf(classMap[parentClassName]);
161 //        }
162 //        else {
163             return '';
164 //        }
165     }
166
167     return cls.alias;
168 }
169
170 var aliases, i, ln, alternates;
171
172 allClasses.forEach(function(name) {
173     aliases = classMap[name] ? Ext.Array.from(getAliasOf(classMap[name])) : [];
174     alternates = classMap[name] ? Ext.Array.from(classMap[name].alternateClassName) : [];
175
176     nameToAliasesMap[name] = aliases;
177
178     for (i = 0, ln = alternates.length; i < ln; i++) {
179         alternateToNameMap[alternates[i]] = name;
180     }
181 });
182
183 system.setcwd(PATH.BUILD);
184 var generatedFilePath = system.arguments[0] + Fs.sep + 'data.js';
185 Fs.writeFile(generatedFilePath, 'this.ExtBootstrap.data = ' + JSON.stringify({
186     coreFiles: coreFiles,
187     platformFolders: platformOnlyFolders.map(pathToNamespace),
188     platformFiles: platformOnlyFiles.map(pathToNamespace),
189     nameToAliasesMap: nameToAliasesMap,
190     alternateToNameMap: alternateToNameMap
191 }, null, 4));
192
193 var releaseData = Fs.readFile(PATH.ROOT + Fs.sep + 'bootstrap' + Fs.sep + 'data-release-base.js');
194
195 Fs.writeFile(PATH.ROOT + Fs.sep + 'bootstrap' + Fs.sep + 'data-release.js', '(function(){ var data = ' + JSON.stringify({
196     nameToAliasesMap: nameToAliasesMap,
197     alternateToNameMap: alternateToNameMap
198 }, null, 4) + ';' + releaseData + '})();');
199
200 //Fs.remove(sourceManifestPath);
201
202 Logger.log("\nSuccessfully re-generated: " + generatedFilePath + " in " + ((Date.now() - startTime) / 1000) + 's');