-
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.
feat(changelog): added changelog schematics
- Loading branch information
1 parent
f516028
commit 4d017a1
Showing
1 changed file
with
33 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { Rule, SchematicContext, SchematicsException, Tree } from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
|
||
// You don't have to export the function as default. You can also have more than one rule factory | ||
// per file. | ||
export function changelog(_options: any): Rule { | ||
return (tree: Tree, _context: SchematicContext) => { | ||
|
||
const packageJsonBuffer = tree.read("package.json"); | ||
if (!packageJsonBuffer) { | ||
throw new SchematicsException("Not an npm project. Couldn't find package.json"); | ||
} | ||
|
||
const packageJson = JSON.parse(packageJsonBuffer.toString()); | ||
|
||
const scripts = "scripts"; | ||
const changelogScript = "changelog"; | ||
const changelogScriptCmd = "./node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s -r 0"; | ||
if (!packageJson[scripts]) { | ||
packageJson[scripts] = {}; | ||
} | ||
packageJson[scripts][changelogScript] = changelogScriptCmd; | ||
|
||
const devDeps = "devDependencies"; | ||
const changelog = "conventional-changelog-cli"; | ||
const version = "latest"; | ||
if (!packageJson[devDeps]) { | ||
packageJson[devDeps] = {}; | ||
} | ||
if (!packageJson[devDeps][changelog]) { | ||
packageJson[devDeps][changelog] = version; | ||
} | ||
|
||
tree.overwrite('package.json', JSON.stringify(packageJson, null, 2)); | ||
_context.logger.log('info', `Added "${changelogScript}" to "${scripts}" in package.json`); | ||
_context.logger.log('info', `Added "${changelog}@${version}" to ${devDeps}`); | ||
_context.addTask(new NodePackageInstallTask()); | ||
|
||
return tree; | ||
}; | ||
} |