@atomist/atomist-sdm
Version:
Atomist SDM to deliver our own projects
95 lines (94 loc) • 3.82 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const automation_client_1 = require("@atomist/automation-client");
const sdm_1 = require("@atomist/sdm");
const sdm_pack_build_1 = require("@atomist/sdm-pack-build");
const appRoot = require("app-root-path");
const fs = require("fs-extra");
const path = require("path");
const identityPushTests_1 = require("../support/identityPushTests");
/**
* Update the TypeScript support files in a project. They are not
* added if they do not already exist.
*/
function updateSupportFilesInProject(p) {
return __awaiter(this, void 0, void 0, function* () {
const communityFiles = ["tslint.json"];
const baseDir = appRoot.path;
yield Promise.all(communityFiles.map((src) => __awaiter(this, void 0, void 0, function* () {
try {
const destFile = yield p.getFile(src);
if (!destFile) {
automation_client_1.logger.debug(`Project ${p.name} has no ${src} to update`);
return p;
}
const srcPath = path.join(baseDir, src);
const content = yield fs.readFile(srcPath, "utf8");
yield destFile.setContent(content);
}
catch (e) {
automation_client_1.logger.error(`Failed to update content of ${src} in ${p.name}: ${e.message}`);
}
return p;
})));
return p;
});
}
exports.updateSupportFilesInProject = updateSupportFilesInProject;
exports.UpdateSupportFilesAutofix = {
name: "Update support files",
pushTest: sdm_1.allSatisfied(sdm_1.ToDefaultBranch, sdm_1.not(identityPushTests_1.isNamed("web-app"))),
transform: updateSupportFilesInProject,
};
/**
* Create pull request with auto-merge labels.
*/
class AutoMergeBranchCommit {
get message() {
return `Update TypeScript support files
${sdm_pack_build_1.BuildAwareMarker}
`;
}
get branch() {
return `atomist-update-support-files-${Date.now()}`;
}
get autoMerge() {
return {
mode: automation_client_1.editModes.AutoMergeMode.SuccessfulCheck,
method: automation_client_1.editModes.AutoMergeMethod.Rebase,
};
}
}
exports.UpdateSupportFilesTransform = {
name: "UpdateSupportFilesAndFix",
description: "Update the TypeScript support files",
intent: "update support files",
transform: updateSupportFilesInProject,
transformPresentation: ci => {
return new AutoMergeBranchCommit();
},
};
//# sourceMappingURL=updateSupportFiles.js.map