Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Get everything working without manifest.yml
Browse files Browse the repository at this point in the history
The new standard is just to have a package.json and no manifest.yml.
Since pretty much every Rug in this project touches manifest.yml
somehow, a lot of things had to be updated.  There is an explicit
ConvertManifestToPackageJson editor, but many editors will
automatically call that if they find a manifest.yml.

Removed AddManifestYml, AddTypeScript editors since they were no
longer relevant.

Update build for package.json-based projects.

While I was touching all the files, I did some clean up too,
especially in tests.

Do not overwrite some values from package.json when merging contents
of manifest.yml in.

No longer add package.json in UpdateSupportFiles, since if it didn't
exist in the first place, the editor would throw an Error.
  • Loading branch information
David Dooling committed Jun 6, 2017
1 parent f4d0d31 commit 43e2fdf
Show file tree
Hide file tree
Showing 56 changed files with 1,702 additions and 2,605 deletions.
47 changes: 19 additions & 28 deletions .atomist/build/travis-build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -o pipefail

declare Pkg=travis-build
declare Version=0.7.0
declare Version=0.8.0

function msg() {
echo "$Pkg: $*"
Expand Down Expand Up @@ -59,27 +59,23 @@ function main () {
rug="$rug --timer --quiet --update --resolver-report --error --settings=$PWD/.atomist/build/cli.yml"
export TEAM_ID=T1L0VDKJP

if [[ -f .atomist/package.json ]]; then
msg "running yarn"
# this should use --frozen-lockfile but
# https://github.com/yarnpkg/yarn/issues/3313
if ! ( cd .atomist && yarn --pure-lockfile ); then
err "yarn failed"
return 1
fi
msg "running npm install"
if ! ( cd .atomist && npm install ); then
err "npm install failed"
return 1
fi

msg "running lint"
if ! ( cd .atomist && yarn run lint ); then
err "tslint failed"
return 1
fi
msg "running lint"
if ! ( cd .atomist && npm run lint ); then
err "tslint failed"
return 1
fi

if [[ -d .atomist/mocha ]]; then
msg "running mocha tests"
if ! ( cd .atomist && yarn run mocha ); then
err "mocha tests failed"
return 1
fi
if [[ -d .atomist/mocha ]]; then
msg "running mocha tests"
if ! ( cd .atomist && npm run mocha ); then
err "mocha tests failed"
return 1
fi
fi

Expand All @@ -98,15 +94,10 @@ function main () {
[[ $TRAVIS_PULL_REQUEST == false ]] || return 0

local archive_version
local manifest=.atomist/manifest.yml
if [[ -f $manifest ]]; then
archive_version=$(awk -F: '$1 == "version" { print $2 }' "$manifest" | sed 's/[^.0-9]//g')
else
err "no manifest.yml in archive"
return 1
fi
local pkg_json=.atomist/package.json
archive_version=$(jq -er .version "$pkg_json")
if [[ $? -ne 0 || ! $archive_version ]]; then
err "failed to extract archive version: $archive_version"
err "failed to extract archive version from $pkg_json: $archive_version"
return 1
fi
local project_version
Expand Down
2 changes: 1 addition & 1 deletion .atomist/editors/AddFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PathExpressionEngine } from "@atomist/rug/tree/PathExpression";
*/
export function addInstructionsToReadMe(project: Project, instructions: string): void {
const readme = project.findFile("README.md");
if (readme === null || !readme.containsMatch("\n## Rugs[\\S\\s]*\n## Support")) {
if (readme == null || !readme.containsMatch("\n## Rugs[\\S\\s]*\n## Support")) {
return;
}
readme.regexpReplace("\n## Support", instructions + "\n## Support");
Expand Down
23 changes: 12 additions & 11 deletions .atomist/editors/AddLocalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ import { Editor, Parameter, Tags } from "@atomist/rug/operations/Decorators";
import { EditProject } from "@atomist/rug/operations/ProjectEditor";
import { Pattern } from "@atomist/rug/operations/RugOperation";

import { isRugArchive } from "./RugEditorsPredicates";
import { RugParameters } from "./RugParameters";

/**
* Add an editor for modifying the local project. Useful when you
* editors are specific to a project and you want to store them with
* the project.
*/
@Editor("AddLocalEditor", "adds an editor for modifying the local project, initiating a Rug archive if needed")
@Tags("rug", "atomist", "typescript")
export class AddLocalEditor implements EditProject {
Expand All @@ -44,18 +50,13 @@ export class AddLocalEditor implements EditProject {
public groupId: string = "local";

public edit(project: Project) {
project.editWith("ConvertExistingProjectToRugArchive", {
description: this.description,
archiveName: project.name,
groupId: this.groupId,
});
project.editWith("AddTypeScript", {});
if (!project.directoryExists(".atomist/node_modules")) {
// The following line works with the CLI but when used through the
// bot, it often triggers GitHub rate limiting.
// project.copyEditorBackingFilesPreservingPath(".atomist/node_modules");
if (!isRugArchive(project)) {
project.editWith("ConvertExistingProjectToRugArchive", {
description: this.description,
archiveName: project.name,
groupId: this.groupId,
});
}

project.editWith("AddTypeScriptEditor", this);
}
}
Expand Down
80 changes: 0 additions & 80 deletions .atomist/editors/AddManifestYml.ts

This file was deleted.

44 changes: 0 additions & 44 deletions .atomist/editors/AddTypeScript.ts

This file was deleted.

6 changes: 4 additions & 2 deletions .atomist/editors/AddTypeScriptCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { EditProject } from "@atomist/rug/operations/ProjectEditor";
import { isRugArchive, NotRugArchiveError } from "./RugEditorsPredicates";
import { RugParameters } from "./RugParameters";

/**
* Add a command handler to a Rug project. If the project is not a Rug project
* an Error is thrown.
*/
@Editor("AddTypeScriptCommandHandler", "adds a TypeScript Rug command handler to a Rug project")
@Tags("rug", "atomist", "typescript")
export class AddTypeScriptCommandHandler implements EditProject {
Expand Down Expand Up @@ -55,8 +59,6 @@ export class AddTypeScriptCommandHandler implements EditProject {
throw new NotRugArchiveError();
}

project.editWith("AddTypeScript", {});

const srcHandlerName = "TypeScriptCommandHandler";
const srcHandlerPath = `.atomist/handlers/command/${srcHandlerName}.ts`;
const srcTestPath = `.atomist/tests/handlers/command/${srcHandlerName}Steps.ts`;
Expand Down
6 changes: 4 additions & 2 deletions .atomist/editors/AddTypeScriptEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import { addInstructionsToReadMe, readMeInstructions } from "./AddFunctions";
import { isRugArchive, NotRugArchiveError } from "./RugEditorsPredicates";
import { RugParameters } from "./RugParameters";

/**
* Add a editor to a Rug project. If the project is not a Rug project
* an Error is thrown.
*/
@Editor("AddTypeScriptEditor", "adds a TypeScript Rug editor to a Rug project")
@Tags("rug", "atomist", "typescript")
export class AddTypeScriptEditor implements EditProject {
Expand All @@ -47,8 +51,6 @@ export class AddTypeScriptEditor implements EditProject {
throw new NotRugArchiveError();
}

project.editWith("AddTypeScript", {});

const srcEditorName = "TypeScriptEditor";
const srcEditorPath = `.atomist/editors/${srcEditorName}.ts`;
const srcTestPath = `.atomist/tests/project/${srcEditorName}Steps.ts`;
Expand Down
6 changes: 4 additions & 2 deletions .atomist/editors/AddTypeScriptEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { EditProject } from "@atomist/rug/operations/ProjectEditor";
import { isRugArchive, NotRugArchiveError } from "./RugEditorsPredicates";
import { RugParameters } from "./RugParameters";

/**
* Add an event handler to a Rug project. If the project is not a Rug project
* an Error is thrown.
*/
@Editor("AddTypeScriptEventHandler", "adds a TypeScript Rug event handler to a Rug project")
@Tags("rug", "atomist", "typescript")
export class AddTypeScriptEventHandler implements EditProject {
Expand Down Expand Up @@ -56,8 +60,6 @@ export class AddTypeScriptEventHandler implements EditProject {
throw new NotRugArchiveError();
}

project.editWith("AddTypeScript", {});

const srcHandlerName = "TypeScriptEventHandler";
const srcHandlerPath = `.atomist/handlers/event/${srcHandlerName}.ts`;
const srcTestPath = `.atomist/tests/handlers/event/${srcHandlerName}Steps.ts`;
Expand Down
6 changes: 4 additions & 2 deletions .atomist/editors/AddTypeScriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import { addInstructionsToReadMe, readMeInstructions } from "./AddFunctions";
import { isRugArchive, NotRugArchiveError } from "./RugEditorsPredicates";
import { RugParameters } from "./RugParameters";

/**
* Add a generator to a Rug project. If the project is not a Rug project
* an Error is thrown.
*/
@Editor("AddTypeScriptGenerator", "adds a TypeScript generator to a Rug project")
@Tags("rug", "atomist", "typescript")
export class AddTypeScriptGenerator implements EditProject {
Expand All @@ -46,8 +50,6 @@ export class AddTypeScriptGenerator implements EditProject {
throw new NotRugArchiveError();
}

project.editWith("AddTypeScript", {});

const srcGeneratorName = "TypeScriptGenerator";
const srcGeneratorPath = `.atomist/generators/${srcGeneratorName}.ts`;
const srcTestPath = ".atomist/tests/project/TypeScriptGeneratorSteps.ts";
Expand Down
26 changes: 16 additions & 10 deletions .atomist/editors/BumpVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { Project } from "@atomist/rug/model/Project";
import { Editor, Parameter, Tags } from "@atomist/rug/operations/Decorators";
import { EditProject } from "@atomist/rug/operations/ProjectEditor";

import { isRugArchive, NotRugArchiveError } from "./RugEditorsPredicates";

/**
* Increment the Rug archive version in manifest.yml
* Increment the Rug archive version in .atomist/package.json.
*/
@Editor("BumpVersion", "bump the version of this Rug archive project")
@Tags("rug", "version")
Expand All @@ -37,25 +39,29 @@ export class BumpVersion implements EditProject {
public component: string = "minor";

public edit(project: Project) {
const manifest = project.findFile(".atomist/manifest.yml");
if (manifest == null) {
const err = "project does not appear to be a Rug project";
if (!isRugArchive(project)) {
throw new NotRugArchiveError();
}
const pkgJsonPath = ".atomist/package.json";
const pkgJson = project.findFile(pkgJsonPath);
if (pkgJson == null) {
const err = `failed to open file: ${pkgJsonPath}`;
console.log(err);
throw new Error(err);
}

const extractVersionRegex = /^version\s*:\s*(?:"(.*?)"|(.*))\s*$/m;
const versionMatch = extractVersionRegex.exec(manifest.content);
const extractVersionRegex = /"version"\s*:\s*"(.*?)"/;
const versionMatch = extractVersionRegex.exec(pkgJson.content);
if (!versionMatch) {
const err = `unable to extract version from manifest.yml: ${manifest.content}`;
const err = `unable to extract version from ${pkgJsonPath}: ${pkgJson.content}`;
console.log(err);
throw new Error(err);
}

const comp = this.component as "major" | "minor" | "patch";
const newVersion = incrementVersion(versionMatch[1] || versionMatch[2], comp);
const newVersion = incrementVersion(versionMatch[1], comp);

manifest.regexpReplace("version:.*", `version: "${newVersion}"`);
pkgJson.regexpReplace(`"version"\\s*:\\s*".*?"`, `"version": "${newVersion}"`);
}
}

Expand All @@ -71,7 +77,7 @@ export function incrementVersion(version: string, component: "major" | "minor" |
let major = parseInt(versionMatch[1], 10);
let minor = parseInt(versionMatch[2], 10);
let patch = parseInt(versionMatch[3], 10);
const rest = (versionMatch[4] !== null && versionMatch[4] !== undefined) ? versionMatch[4] : "";
const rest = (versionMatch[4] != null) ? versionMatch[4] : "";

if (component === "major") {
major = major + 1;
Expand Down
Loading

0 comments on commit 43e2fdf

Please sign in to comment.