@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
70 lines (68 loc) • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanFile = exports.updateShellReferences = void 0;
const tslib_1 = require("tslib");
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const logger_1 = require("./logger");
function updateShellReferences(primaryDisplayName, internal) {
logger_1.Logger.log('Updating shell references...');
logger_1.Logger.log('Detected internal: ' + internal);
const internalShellReference = '@msft-sme';
const externalShellReference = '@microsoft/windows-admin-center-sdk';
const find = internal ? externalShellReference : internalShellReference;
const replace = internal ? internalShellReference : externalShellReference;
// For performance reasons, all applicable files are listed here, rather than scanning all files
const extensionDirectory = ('./' + primaryDisplayName + '/').replace('//', '/');
const extensionSrcDirectory = extensionDirectory + 'src/';
const extensionAppDirectory = extensionSrcDirectory + 'app/';
const gulpFileDirectory = extensionDirectory + 'gulpfile.ts/';
const gulpFileCommonDirectory = gulpFileDirectory + 'common/';
const filesWithShellReferences = [
extensionDirectory + 'angular.json',
gulpFileDirectory + 'config-data.ts',
gulpFileDirectory + 'index.ts',
gulpFileCommonDirectory + 'pack.ts',
gulpFileCommonDirectory + 'powershell.ts',
gulpFileCommonDirectory + 'resjson.ts',
gulpFileCommonDirectory + 'test.ts',
gulpFileCommonDirectory + 'validate.ts',
extensionSrcDirectory + 'main.ts',
extensionSrcDirectory + 'manifest.json',
extensionSrcDirectory + 'polyfills.ts',
extensionSrcDirectory + 'test.ts',
extensionAppDirectory + 'app-routing.module.ts',
extensionAppDirectory + 'app.component.ts',
extensionAppDirectory + 'app.module.ts',
extensionDirectory + '.eslintrc.json'
];
const cleanFiles = {};
filesWithShellReferences.forEach((file) => {
cleanFiles[file] = {
[find]: replace
};
});
for (const key in cleanFiles) {
if (Object.prototype.hasOwnProperty.call(cleanFiles, key)) {
cleanFile(key, cleanFiles[key]);
}
}
}
exports.updateShellReferences = updateShellReferences;
function cleanFile(key, values) {
logger_1.Logger.log('Updating: ' + key + ' ' + JSON.stringify(values));
for (const valuesKey in values) {
let a = 0;
if (Object.prototype.hasOwnProperty.call(values, valuesKey)) {
let fileData = fs_extra_1.default.readFileSync(key, 'utf8');
let displayNameIndex = fileData.indexOf(valuesKey);
while (displayNameIndex > 0) {
logger_1.Logger.log('Found key: ' + valuesKey + ' at index: ' + displayNameIndex);
fileData = fileData.replace(valuesKey, values[valuesKey]);
displayNameIndex = fileData.indexOf(valuesKey);
}
fs_extra_1.default.outputFileSync(key, fileData);
}
}
}
exports.cleanFile = cleanFile;
//# sourceMappingURL=update-shell-references.js.map