-
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.
* refactor: add new functions to modify package.json * feat: add new schematic to generate nvmrc and include node version in package.json
- Loading branch information
Showing
8 changed files
with
5,903 additions
and
6,145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
1 change: 1 addition & 0 deletions
1
packages/@guidesmiths/cuckoojs-schematics/src/nvmrc/files/.nvmrc
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 @@ | ||
<%=nodeVersion%> |
47 changes: 47 additions & 0 deletions
47
packages/@guidesmiths/cuckoojs-schematics/src/nvmrc/nvmrc.factory.ts
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,47 @@ | ||
import type { | ||
Rule, | ||
SchematicContext, | ||
Tree} from '@angular-devkit/schematics'; | ||
import { | ||
apply, | ||
MergeStrategy, | ||
mergeWith, move, | ||
template, | ||
url, | ||
chain, | ||
} from '@angular-devkit/schematics'; | ||
import {normalize} from '@angular-devkit/core'; | ||
import {join} from 'path'; | ||
import {PackageJsonUtils} from '../utils/package-json.utils'; | ||
|
||
type Options = { | ||
directory: string; | ||
nodeVersion: number; | ||
}; | ||
|
||
export function main(options: Options): Rule { | ||
return (_tree: Tree, context: SchematicContext): Rule => { | ||
context.logger.info('Creating .nvmrc file and updating package.json...'); | ||
|
||
const templateSource = apply(url('./files'), [ | ||
template({...options}), | ||
move(normalize(options.directory)), | ||
]); | ||
|
||
return chain([ | ||
mergeWith(templateSource, MergeStrategy.Overwrite), | ||
updatePackageJson(options), | ||
]); | ||
}; | ||
} | ||
|
||
function updatePackageJson(options: Options): Rule { | ||
return (tree: Tree) => { | ||
const path = join(options.directory, 'package.json'); | ||
|
||
const packageJsonUtils = new PackageJsonUtils(tree, path); | ||
packageJsonUtils.addWithPath(['engines', 'node'], `>=${options.nodeVersion}`); | ||
|
||
return tree; | ||
}; | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/@guidesmiths/cuckoojs-schematics/src/nvmrc/schema.json
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,21 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "SchematicsNvmrc", | ||
"title": "Nvmrc schematic schema", | ||
"type": "object", | ||
"properties": { | ||
"directory": { | ||
"type": "string", | ||
"description": "nvmrc file destination directory.", | ||
"default": ".", | ||
"x-prompt": "Where is the root folder of your project?" | ||
}, | ||
"nodeVersion": { | ||
"type": "number", | ||
"description": "node version to use in nvmrc file", | ||
"x-prompt": "What node version would you like for your project?", | ||
"default": 18 | ||
} | ||
}, | ||
"required": ["directory", "nodeVersion"] | ||
} |
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