Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove package installation from schematics #96

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Check their correspondent README files for more info.
| Option | Description | Requiered | Type | Default |
|---------------|---------------------------------------------------------------------|---|---|---------|
| `directory` | Root folder of your NestJS project | false | string | `.` |
| `skipInstall` | Root folder of your NestJS project | false | string | `false` |

## How to use it within a project

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
chain,
noop,
type Rule,
type SchematicContext,
type Tree,
Expand All @@ -9,11 +8,9 @@ import {schematic} from '@angular-devkit/schematics';
import {normalize} from '@angular-devkit/core';
import {execSync} from 'child_process';
import {resolve} from 'path';
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks'

interface Options {
directory: string;
skipInstall: boolean;
}

export function main(options: Options): Rule {
Expand All @@ -32,14 +29,6 @@ export function main(options: Options): Rule {
schematic('commitlint', options),
schematic('gitignore', options),
schematic('nvmrc', options),
options.skipInstall ? noop() : installDependencies(),
]);
};
}

function installDependencies(): Rule {
return (tree: Tree, context: SchematicContext) => {
context.addTask(new NodePackageInstallTask());
return tree;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
"type": "string",
"description": "destination directory.",
"default": "."
},
"skillInstall": {
"type": "boolean",
"description": "skip npm install.",
"default": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env var defined via the `envVar` option.
|---------------|-----------------------------------------------------------------------------|---|---------|------------|
| `directory` | Root folder of your NestJS project | false | string | `.` |
| `envVar` | Name of the env var that determines your environment during runtime | false | string | `NODE_ENV` |
| `skipInstall` | Skips the installation process of the packages included with this schematic | false | boolean | `false` |


## How to use it within a project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import {
template,
chain,
url,
noop
} from '@angular-devkit/schematics';
import {normalize} from '@angular-devkit/core';
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks';
import {addConfigToModuleRule} from './utils/add-config-to-module-rule';
import {PackageJsonUtils} from '../utils/package-json.utils';

interface Options {
directory: string;
skipInstall: boolean;
}

export function main(options: Options): Rule {
Expand All @@ -42,7 +39,6 @@ export function main(options: Options): Rule {
mergeWith(templateSource, MergeStrategy.Overwrite),
addConfigToModuleRule(appFile),
updatePackageJson(),
options.skipInstall ? noop() : installDependencies(),
]);
};
}
Expand All @@ -55,16 +51,8 @@ function updatePackageJson(): Rule {
packageJsonUtils.addPackage('class-transformer', '^0.5.1', false);
packageJsonUtils.addPackage('class-validator', '^0.14.0', false);
packageJsonUtils.addPackage('lodash.merge', '^4.6.2', false);

return tree;
};
}

function installDependencies(): Rule {
return (tree: Tree, context: SchematicContext) => {
context.addTask(new NodePackageInstallTask());

return tree;
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
"description": "Name of the env var that determines the environment",
"default": "NODE_ENV",
"x-prompt": "What is the name of the env var that determines the environment where the app will be running?"
},
"skillInstall": {
"type": "boolean",
"description": "skip npm install.",
"default": false
}
},
"required": ["directory", "envVar"]
Expand Down