|
| 1 | +Class.Define('BaseBuild', { |
| 2 | + Static: { |
| 3 | + BUILD_SCRIPTS_DIR: Wsh.Fso.GetAbsolutePathName('.').replace(/\\/g, '/'), |
| 4 | + GLOBAL_VERSION_NUMBER_FILENAME: 'GLOBAL_VERSION_NUMBER' |
| 5 | + }, |
| 6 | + mainModuleDirName: '', |
| 7 | + subModuleDirsNameBegin: '', |
| 8 | + versions: [], |
| 9 | + modulesInfo: [], |
| 10 | + Constructor: function () { |
| 11 | + // |
| 12 | + }, |
| 13 | + loadGlobalVersionNumber: function () { |
| 14 | + var fullPath = this.self.BUILD_SCRIPTS_DIR + '/' + this.self.GLOBAL_VERSION_NUMBER_FILENAME; |
| 15 | + var textStream = Wsh.Fso.OpenTextFile(fullPath, 1, 0); // for reading, as ASCII |
| 16 | + var versionNumStr = textStream.ReadLine().trim(); |
| 17 | + textStream.Close(); |
| 18 | + var versionNumStrParts = versionNumStr.split("."); |
| 19 | + for (var i = 0, l = versionNumStrParts.length; i < l; i += 1) { |
| 20 | + this.versions.push( |
| 21 | + parseInt(versionNumStrParts[i], 10) |
| 22 | + ); |
| 23 | + } |
| 24 | + }, |
| 25 | + completeModuleDirectoriesInfo: function () { |
| 26 | + var folder = Wsh.Fso.GetFolder("./.."), |
| 27 | + foldersEnum = new Enumerator(folder.subFolders), |
| 28 | + subFolder = {}, |
| 29 | + lang = '', |
| 30 | + asmInfo = '', |
| 31 | + nugetCfgPath = ''; |
| 32 | + for (; !foldersEnum.atEnd(); foldersEnum.moveNext()) { |
| 33 | + subFolder = Wsh.Fso.GetFolder(String(foldersEnum.item())); |
| 34 | + lang = ''; |
| 35 | + asmInfo = ''; |
| 36 | + if (subFolder.name.indexOf(this.subModuleDirsNameBegin) == 0 || subFolder.name == this.mainModuleDirName) { |
| 37 | + if (Wsh.Fso.FileExists(subFolder.path + '/My Project/AssemblyInfo.vb')) { |
| 38 | + lang = 'vb'; |
| 39 | + asmInfo = subFolder.path + '/My Project/AssemblyInfo.vb'; |
| 40 | + } else if (Wsh.Fso.FileExists(subFolder.path + '/Properties/AssemblyInfo.cs')) { |
| 41 | + lang = 'cs'; |
| 42 | + asmInfo = subFolder.path + '/Properties/AssemblyInfo.cs'; |
| 43 | + } |
| 44 | + if (!lang) continue; |
| 45 | + this.modulesInfo.push({ |
| 46 | + lang: lang, |
| 47 | + dirFullPath: subFolder.path, |
| 48 | + dirName: subFolder.name, |
| 49 | + asmInfo: asmInfo, |
| 50 | + nugetCfg: this._tryToFindNugetConfigFile(subFolder.path) |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | + this.modulesInfo.sort().reverse(); |
| 55 | + }, |
| 56 | + _tryToFindNugetConfigFile: function (dirFullPath) { |
| 57 | + var folder = Wsh.Fso.GetFolder(dirFullPath), |
| 58 | + filesEnum = new Enumerator(folder.files), |
| 59 | + fileExt = '', |
| 60 | + result = ''; |
| 61 | + for (; !filesEnum.atEnd() ; filesEnum.moveNext()) { |
| 62 | + file = Wsh.Fso.GetFile(String(filesEnum.item())); |
| 63 | + fileExt = String(Wsh.Fso.GetExtensionName(file.Path)).toLowerCase(); |
| 64 | + if (fileExt == 'nuspec') { |
| 65 | + result = file.Path; |
| 66 | + break; |
| 67 | + } |
| 68 | + } |
| 69 | + return result; |
| 70 | + }, |
| 71 | + cleanAllBinDirectoriesForNupkgs: function () { |
| 72 | + var dirFullPath = ''; |
| 73 | + for (var i = 0, l = this.modulesInfo.length; i < l; i += 1) { |
| 74 | + dirFullPath = this.modulesInfo[i].dirFullPath; |
| 75 | + this.cleanDirectory(dirFullPath + '/bin/Debug'); |
| 76 | + this.cleanDirectory(dirFullPath + '/bin/Release'); |
| 77 | + } |
| 78 | + }, |
| 79 | + setUpVersionToAssemblyInfos: function () { |
| 80 | + var readStream = null, |
| 81 | + writeStream = null, |
| 82 | + asmInfoFullPath = '', |
| 83 | + asmInfoContent = ''; |
| 84 | + for (var i = 0, l = this.modulesInfo.length; i < l; i += 1) { |
| 85 | + asmInfoFullPath = this.modulesInfo[i].asmInfo; |
| 86 | + // open for reading, if file doesn't exists, do not create new |
| 87 | + readStream = Wsh.Fso.OpenTextFile(asmInfoFullPath, 1, false); |
| 88 | + asmInfoContent = readStream.ReadAll(); |
| 89 | + readStream.Close(); |
| 90 | + asmInfoContent = this._setUpVersionToAssemblyInfoContent(asmInfoContent, 'AssemblyVersion'); |
| 91 | + asmInfoContent = this._setUpVersionToAssemblyInfoContent(asmInfoContent, 'AssemblyFileVersion'); |
| 92 | + // for overwriting, not as Unicode |
| 93 | + writeStream = Wsh.Fso.CreateTextFile(asmInfoFullPath, true, false); |
| 94 | + writeStream.Write(asmInfoContent); |
| 95 | + writeStream.Close(); |
| 96 | + } |
| 97 | + }, |
| 98 | + _setUpVersionToAssemblyInfoContent: function (asmInfoContent, attrName) { |
| 99 | + var index = 0, |
| 100 | + attrBegin = 0, |
| 101 | + attrEnd = 0, |
| 102 | + version = ''; |
| 103 | + while (true) { |
| 104 | + attrBegin = asmInfoContent.indexOf(attrName + '(', index); |
| 105 | + if (attrBegin == -1) break; |
| 106 | + attrBegin += attrName.length + 1; |
| 107 | + attrEnd = asmInfoContent.indexOf(')', attrBegin); |
| 108 | + if (attrEnd == -1) break; |
| 109 | + version = asmInfoContent.substring(attrBegin, attrEnd) |
| 110 | + .trim('"\' \t\n\r'); |
| 111 | + if (!/^([0-9\.]*)$/gi.test(version)) { |
| 112 | + index = attrEnd; |
| 113 | + continue; |
| 114 | + } |
| 115 | + asmInfoContent = asmInfoContent.substr(0, attrBegin) |
| 116 | + + '"' + this.versions.join('.') + '"' |
| 117 | + + asmInfoContent.substr(attrEnd); |
| 118 | + break; |
| 119 | + } |
| 120 | + return asmInfoContent; |
| 121 | + }, |
| 122 | + setUpVersionToNuspecCfgs: function () { |
| 123 | + var readStream = null, |
| 124 | + writeStream = null, |
| 125 | + nugetCfgFullPath = '', |
| 126 | + nugetCfgContent = ''; |
| 127 | + for (var i = 0, l = this.modulesInfo.length; i < l; i += 1) { |
| 128 | + nugetCfgFullPath = this.modulesInfo[i].nugetCfg; |
| 129 | + if (!nugetCfgFullPath) continue; |
| 130 | + // open for reading, if file doesn't exists, do not create new |
| 131 | + readStream = Wsh.Fso.OpenTextFile(nugetCfgFullPath, 1, false); |
| 132 | + nugetCfgContent = readStream.ReadAll(); |
| 133 | + readStream.Close(); |
| 134 | + nugetCfgContent = this._setUpVersionToNugspecCfgContent(nugetCfgContent); |
| 135 | + // for overwriting, not as Unicode |
| 136 | + writeStream = Wsh.Fso.CreateTextFile(nugetCfgFullPath, true, false); |
| 137 | + writeStream.Write(nugetCfgContent); |
| 138 | + writeStream.Close(); |
| 139 | + } |
| 140 | + }, |
| 141 | + _setUpVersionToNugspecCfgContent: function (nugetCfgContent) { |
| 142 | + var index = 0, |
| 143 | + openingNode = '<version>', |
| 144 | + closingNode = '</version>', |
| 145 | + valueBegin = 0, |
| 146 | + valueEnd = 0, |
| 147 | + versionStr = ''; |
| 148 | + while (true) { |
| 149 | + valueBegin = nugetCfgContent.indexOf(openingNode, index); |
| 150 | + if (valueBegin == -1) break; |
| 151 | + valueBegin += openingNode.length; |
| 152 | + valueEnd = nugetCfgContent.indexOf(closingNode, valueBegin); |
| 153 | + if (valueEnd == -1) break; |
| 154 | + versionStr = nugetCfgContent.substring(valueBegin, valueEnd) |
| 155 | + .trim('"\' \t\n\r'); |
| 156 | + if (!/^([0-9\.]*)$/gi.test(versionStr)) { |
| 157 | + index = valueEnd; |
| 158 | + continue; |
| 159 | + } |
| 160 | + nugetCfgContent = nugetCfgContent.substr(0, valueBegin) |
| 161 | + + this.versions.join('.') |
| 162 | + + nugetCfgContent.substr(valueEnd); |
| 163 | + break; |
| 164 | + } |
| 165 | + return nugetCfgContent; |
| 166 | + }, |
| 167 | + cleanDirectory: function (relativeOrAbsolutePath, allFiles) { |
| 168 | + var folder = Wsh.Fso.GetFolder(relativeOrAbsolutePath), |
| 169 | + filesEnum = new Enumerator(folder.files), |
| 170 | + allFiles = !!allFiles, |
| 171 | + fileExt = ''; |
| 172 | + for (; !filesEnum.atEnd() ; filesEnum.moveNext()) { |
| 173 | + file = Wsh.Fso.GetFile(String(filesEnum.item())); |
| 174 | + fileExt = String(Wsh.Fso.GetExtensionName(file.Path)).toLowerCase(); |
| 175 | + if (allFiles || (!allFiles && fileExt == 'nupkg')) { |
| 176 | + try { |
| 177 | + Wsh.Fso.DeleteFile(file.Path); |
| 178 | + } catch (e) { } |
| 179 | + } |
| 180 | + } |
| 181 | + }, |
| 182 | + incrementGlobalVersionNumberRevision: function () { |
| 183 | + this.versions[3] += 1; |
| 184 | + }, |
| 185 | + storeGlobalVersionNumber: function () { |
| 186 | + var fullPath = this.self.BUILD_SCRIPTS_DIR + '/' + this.self.GLOBAL_VERSION_NUMBER_FILENAME; |
| 187 | + var textStream = Wsh.Fso.CreateTextFile(fullPath, true, false); // for overwriting, not as Unicode |
| 188 | + textStream.Write(this.versions.join('.')); |
| 189 | + textStream.Close(); |
| 190 | + } |
| 191 | +}); |
0 commit comments