@atomist/atomist-sdm
Version:
Atomist SDM to deliver our own projects
74 lines • 3.57 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 slack_messages_1 = require("@atomist/slack-messages");
const _ = require("lodash");
const identityPushTests_1 = require("../support/identityPushTests");
const DescriptionRegexp = new RegExp(/\* @description (.*)/, "g");
const TagsRegexp = new RegExp(/\* @tag (.*)/, "g");
/**
* Autofix to update the sample listing in the samples repository
*/
exports.ReadmeSampleListingAutofix = {
name: "README.md sample listing",
pushTest: sdm_1.allSatisfied(identityPushTests_1.isOrgNamed("atomist"), identityPushTests_1.isNamed("samples")),
transform: (p) => __awaiter(this, void 0, void 0, function* () {
const samples = _.sortBy((yield automation_client_1.projectUtils.gatherFromFiles(p, ["**/*.ts"], (f) => __awaiter(this, void 0, void 0, function* () {
if (!f.path.includes("lib/")) {
return undefined;
}
const content = yield f.getContent();
DescriptionRegexp.lastIndex = 0;
TagsRegexp.lastIndex = 0;
const descriptionMatch = DescriptionRegexp.exec(content);
const tagsMatch = TagsRegexp.exec(content);
const tags = [];
if (!!tagsMatch) {
tags.push(...tagsMatch[1].split(","));
}
if (!!descriptionMatch) {
return {
name: f.path,
description: descriptionMatch[1],
tags: tags.sort(),
};
}
return undefined;
}))).filter(s => !!s), "name");
const sampleTable = `<!---atomist:sample=start--->
|Name|Description|Tags|
|----|-----------|----|
${samples.map(s => `|[${slack_messages_1.codeLine(s.name)}](${s.name})|${s.description}|${s.tags.join(", ")}|`).join("\n")}
<!---atomist:sample=end--->`;
const readme = yield p.getFile("README.md");
const readmeContent = yield readme.getContent();
const newReadmeContent = readmeContent.replace(/<!---atomist:sample=start--->[\s\S]*<!---atomist:sample=end--->/gm, sampleTable);
yield readme.setContent(newReadmeContent);
return p;
}),
};
//# sourceMappingURL=ReadmeSampleListingAutofix.js.map