This repository has been archived by the owner on Feb 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
281 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.