Skip to content

Commit

Permalink
refactor: remove package installation from schematics
Browse files Browse the repository at this point in the history
  • Loading branch information
neodmy committed Nov 24, 2023
1 parent 98ad199 commit cc46925
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 35 deletions.
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

0 comments on commit cc46925

Please sign in to comment.