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

Commit

Permalink
Add a simple starter generator
Browse files Browse the repository at this point in the history
Add the AddStarterRugProject generator that takes no parameters other
than the required project name.  Move common generator functionality
into a different file with exported functions.  TypeScript isn't half
bad.

Rename `group_id` to `owner` everywhere.
  • Loading branch information
David Dooling committed Feb 28, 2017
1 parent 52876e3 commit 27ac2e5
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 29 deletions.
32 changes: 32 additions & 0 deletions .atomist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,35 @@ editor:
- "generator_name": "NewRugProject"
- "description": "Generate new Rug archive project"

---
kind: "operation"
client: "rug-cli 0.24.0"
editor:
name: "AddTypeScriptGenerator"
group: "atomist-rugs"
artifact: "rug-editors"
version: "0.11.0"
origin:
repo: "https://github.com/atomist-rugs/rug-editors.git"
branch: "e9ca71094a8d4ba91783b9b00478e3d4741b0e33"
sha: "e9ca710"
parameters:
- "generator_name": "NewStandardRugProject"
- "description": "create new Rug archive project using standard setup and sensible defaults"

---
kind: "operation"
client: "rug-cli 0.24.0"
editor:
name: "AddTypeScriptGenerator"
group: "atomist-rugs"
artifact: "rug-editors"
version: "0.11.0"
origin:
repo: "https://github.com/atomist-rugs/rug-editors.git"
branch: "e9ca71094a8d4ba91783b9b00478e3d4741b0e33"
sha: "e9ca710"
parameters:
- "generator_name": "NewStarterRugProject"
- "description": "create new Rug archive project using standard setup and sensible defaults"

24 changes: 7 additions & 17 deletions .atomist/editors/NewRugProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/

import { PopulateProject } from '@atomist/rug/operations/ProjectGenerator'
import { Project } from '@atomist/rug/model/Core'
import { Project } from '@atomist/rug/model/Project'
import { Pattern } from '@atomist/rug/operations/RugOperation'
import { Generator, Parameter, Tags } from '@atomist/rug/operations/Decorators'
import { PathExpression, PathExpressionEngine } from '@atomist/rug/tree/PathExpression'
import { File } from '@atomist/rug/model/File'

import { removeUnnecessaryFiles, cleanReadMe } from './RugGeneratorFunctions'

@Generator("NewRugProject", "Generate new Rug archive project")
@Tags("rug", "atomist")
class NewRugProject implements PopulateProject {
Expand All @@ -44,7 +46,7 @@ class NewRugProject implements PopulateProject {
minLength: 1,
maxLength: 100
})
group_id: string;
owner: string;

@Parameter({
displayName: "Project Description",
Expand All @@ -69,29 +71,17 @@ class NewRugProject implements PopulateProject {

populate(project: Project) {
let toRemove: string[] = [
".atomist.yml",
".travis.yml",
"CHANGELOG.md",
"CODE_OF_CONDUCT.md",
"LICENSE"
];
for (let f of toRemove) {
project.deleteFile(f);
}

let eng: PathExpressionEngine = project.context().pathExpressionEngine();
removeUnnecessaryFiles(project, toRemove);

let readmePE = new PathExpression<Project, File>("/*[@name='README.md']");
let readme: File = eng.scalar(project, readmePE);
readme.replace("# Atomist 'rug-project'", "# " + this.project_name);
readme.regexpReplace("a Rug archive project generator.[\\s\\S]*?\n## Rugs\n", this.description + "\n\n## Rugs\n");
readme.regexpReplace("\n### NewRugProject[\\s\\S]*\n## Support\n", "\n## Support\n");
readme.replace("rug-project", this.project_name);
readme.replace("atomist-rugs", this.group_id);
cleanReadMe(project, this.project_name, this.description, this.owner);

let params = {
archive_name: this.project_name,
group_id: this.group_id,
group_id: this.owner,
version: this.version
}
project.editWith("AddManifestYml", params);
Expand Down
64 changes: 64 additions & 0 deletions .atomist/editors/NewStarterRugProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright © 2017 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.
*/

import { PopulateProject } from '@atomist/rug/operations/ProjectGenerator'
import { Project } from '@atomist/rug/model/Core'
import { Pattern } from '@atomist/rug/operations/RugOperation'
import { Generator, Parameter, Tags } from '@atomist/rug/operations/Decorators'

import { removeUnnecessaryFiles, cleanReadMe, cleanChangeLog } from './RugGeneratorFunctions'

@Generator("NewStarterRugProject", "create new Rug archive project using standard setup and sensible defaults")
@Tags("atomist", "rug", "documentation", "starter")
class NewStarterRugProject implements PopulateProject {

// this is only necessary to avoid https://github.com/atomist/rug-resolver/issues/17
@Parameter({
displayName: "Project Name",
description: "name of project to be created",
pattern: Pattern.project_name,
validInput: "a valid GitHub project name consisting of alphanumeric, ., -, and _ characters",
minLength: 1,
maxLength: 100
})
project_name: string;

populate(project: Project) {
removeUnnecessaryFiles(project);

const description: string = "Atomist Rug archive project.";
const owner: string = "atomist-rugs";

cleanReadMe(project, this.project_name, description, owner);
cleanChangeLog(project, this.project_name, owner);

const version: string = "0.1.0";
const manifestParams = {
archive_name: this.project_name,
group_id: owner,
version: version
}
project.editWith("AddManifestYml", manifestParams);
project.editWith("AddTypeScript", {});
const editorParams = {
editor_name: "MyFirstEditor",
description: "A sample Rug TypeScript editor to start playing with."
}
project.editWith("AddTypeScriptEditor", editorParams);
}
}

export const newStarterRugProject = new NewStarterRugProject();
55 changes: 55 additions & 0 deletions .atomist/editors/RugGeneratorFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright © 2017 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.
*/

import { Project } from '@atomist/rug/model/Project'
import { PathExpression, PathExpressionEngine } from '@atomist/rug/tree/PathExpression'
import { File } from '@atomist/rug/model/File'

export function removeUnnecessaryFiles(project: Project, extra?: string[]): void {
let toRemove: string[] = [
".atomist.yml",
".travis.yml"
];
if (extra != null) {
toRemove = toRemove.concat(extra);
}
for (let f of toRemove) {
project.deleteFile(f);
}
}

export function cleanReadMe(project: Project, projectName: string, description: string, owner: string): void {
let eng: PathExpressionEngine = project.context().pathExpressionEngine();

let readMePE = new PathExpression<Project, File>("/*[@name='README.md']");
let readMe: File = eng.scalar(project, readMePE);
readMe.replace("# Atomist 'rug-project'", "# " + projectName);
readMe.regexpReplace("a Rug archive project generator.[\\s\\S]*?\n## Rugs\n", description + "\n\n## Rugs\n");
readMe.regexpReplace("\n### NewRugProject[\\s\\S]*\n## Support\n", "\n## Support\n");
readMe.replace("rug-project", projectName);
readMe.replace("atomist-rugs", owner);
}

export function cleanChangeLog(project: Project, projectName: string, owner: string): void {
let eng: PathExpressionEngine = project.context().pathExpressionEngine();

let changeLogPE = new PathExpression<Project, File>("/*[@name='CHANGELOG.md']");
let changeLog: File = eng.scalar(project, changeLogPE);
changeLog.regexpReplace("\\d+\\.\\d+\\.\\d+\\.\\.\\.HEAD\n\n[\\S\\s]*## \\[0\\.1\\.0\\]", "0.1.0...HEAD\n\n## [0.1.0]");
changeLog.regexpReplace("\n### Added[\\S\\s]*", "\nAdded\n\n- Everything\n");
changeLog.replace("rug-project", projectName);
changeLog.replace("atomist-rugs", owner);
}
12 changes: 6 additions & 6 deletions .atomist/tests/NewRugProject.rt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
scenario NewRugProject should create a ready-made .atomist directory

let project_name = "rugs-n-rugs"
let group_id = "my.org"
let owner = "my.rugs"
let version = "0.0.1"
let description = "this is a test of the emergency broadcast system"

Expand All @@ -31,7 +31,7 @@ then
fileExists ".atomist/manifest.yml"
and fileContains ".atomist/manifest.yml" version
and fileContains ".atomist/manifest.yml" project_name
and fileContains ".atomist/manifest.yml" group_id
and fileContains ".atomist/manifest.yml" owner
and { !result.fileExists("CHANGELOG.md") }
and { !result.fileExists("CODE_OF_CONDUCT.md") }
and { !result.fileExists(".travis.yml") }
Expand All @@ -41,7 +41,7 @@ then
and fileContains "README.md" description
and { !result.fileContains("README.md", "Rug archive project generator.") }
and { !result.fileContains("README.md", "After you create a project with this generator") }
and fileContains "README.md" { "https://travis-ci.org/" + group_id + "/" + project_name + ".svg?branch=master" }
and fileContains "README.md" { "https://travis-ci.org/" + owner + "/" + project_name + ".svg?branch=master" }
and fileContains "README.md" "[![Slack Status](https://join.atomist.com/badge.svg)](https://join.atomist.com)"
and { !result.fileContains("README.md", "### NewRugProject") }
and { !result.fileContains("README.md", "ruggery") }
Expand All @@ -54,7 +54,7 @@ then
scenario NewRugProject should create a ready-made .atomist directory using defaults

let project_name = "rug-rug-rug"
let group_id = "my-rugs"
let owner = "my-rugs"
let description = "this is not a test of the emergency broadcast system"

given
Expand All @@ -67,7 +67,7 @@ then
fileExists ".atomist/manifest.yml"
and fileContains ".atomist/manifest.yml" "0.1.0"
and fileContains ".atomist/manifest.yml" project_name
and fileContains ".atomist/manifest.yml" group_id
and fileContains ".atomist/manifest.yml" owner
and { !result.fileExists("CHANGELOG.md") }
and { !result.fileExists("CODE_OF_CONDUCT.md") }
and { !result.fileExists(".travis.yml") }
Expand All @@ -77,7 +77,7 @@ then
and fileContains "README.md" description
and { !result.fileContains("README.md", "Rug archive project generator.") }
and { !result.fileContains("README.md", "After you create a project with this generator") }
and fileContains "README.md" { "https://travis-ci.org/" + group_id + "/" + project_name + ".svg?branch=master" }
and fileContains "README.md" { "https://travis-ci.org/" + owner + "/" + project_name + ".svg?branch=master" }
and fileContains "README.md" "[![Slack Status](https://join.atomist.com/badge.svg)](https://join.atomist.com)"
and { !result.fileContains("README.md", "### NewRugProject") }
and { !result.fileContains("README.md", "ruggery") }
Expand Down
66 changes: 66 additions & 0 deletions .atomist/tests/NewStarterRugProject.rt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright © 2017 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.
*/

scenario NewStarterRugProject should create a new project based on this archive

let pName = "my-project-name"

given
Empty

when
NewStarterRugProject project_name = pName

then
fileExists ".atomist/manifest.yml"
and fileContains ".atomist/manifest.yml" "0.1.0"
and fileContains ".atomist/manifest.yml" pName
and fileContains ".atomist/manifest.yml" "atomist-rugs"
and fileExists "CHANGELOG.md"
and fileContains "CHANGELOG.md" "[0.1.0]"
and fileContains "CHANGELOG.md" "All notable changes to this project will be documented in this file."
and fileContains "CHANGELOG.md" { "https://github.com/atomist-rugs/" + pName + "/compare/0.1.0...HEAD" }
and { !result.fileContains("CHANGELOG.md", "rug-project") }
and { !result.fileContains("CHANGELOG.md", "0.2.0") }
and { !result.fileContains("CHANGELOG.md", "NewRugProject") }
and fileExists "CODE_OF_CONDUCT.md"
and fileContains "CODE_OF_CONDUCT.md" "This Code of Conduct applies both within project spaces and in public spaces"
and { !result.fileExists(".travis.yml") }
and fileExists "LICENSE"
and fileContains "LICENSE" "APPENDIX: How to apply the Apache License to your work."
and fileExists "README.md"
and fileContains "README.md" { "# " + pName }
and { !result.fileContains("README.md", "Atomist 'rug-project'") }
and fileContains "README.md" "Atomist Rug archive project."
and { !result.fileContains("README.md", "Rug archive project generator.") }
and { !result.fileContains("README.md", "After you create a project with this generator") }
and fileContains "README.md" { "https://travis-ci.org/atomist-rugs/" + pName + ".svg?branch=master" }
and fileContains "README.md" "[![Slack Status](https://join.atomist.com/badge.svg)](https://join.atomist.com)"
and { !result.fileContains("README.md", "### NewRugProject") }
and { !result.fileContains("README.md", "ruggery") }
and fileContains "README.md" "## Support"
and fileContains "README.md" "## Development"
and fileContains "README.md" { "---\nCreated by [Atomist][atomist]." }
and fileContains "README.md" "Need Help? [Join our Slack team][slack]."
and fileExists ".atomist/tsconfig.json"
and fileContains ".atomist/tsconfig.json" '"experimentalDecorators": true'
and fileExists ".atomist/package.json"
and fileContains ".atomist/package.json" '"@atomist/rug":'
and directoryExists ".atomist/node_modules/@atomist/rug"
and fileExists ".atomist/editors/MyFirstEditor.ts"
and fileContains ".atomist/editors/MyFirstEditor.ts" '"A sample Rug TypeScript editor to start playing with."'
and fileExists ".atomist/tests/MyFirstEditor.rt"
and fileContains ".atomist/tests/MyFirstEditor.rt" "MyFirstEditor"
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

[Unreleased]: https://github.com/atomist-rugs/rug-project/compare/0.1.0...HEAD
[Unreleased]: https://github.com/atomist-rugs/rug-project/compare/0.2.0...HEAD

## [0.2.0] - 2017-02-28

[0.2.0]: https://github.com/atomist-rugs/rug-project/compare/0.1.0...0.2.0

Sensible release

### Added

- NewStarterRugProject generator

## [0.1.0] - 2017-02-27

Expand Down
Loading

0 comments on commit 27ac2e5

Please sign in to comment.