Skip to content

Commit

Permalink
chore: add cli support
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Dec 25, 2023
1 parent 72ce753 commit d66593e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions schematics/ng-update/upgrade-rules/v17/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,19 @@ export class AppComponent implements OnInit {
expect(content).toContain(`private donePreloader = stepPreloader();`);
expect(content).toContain(`this.donePreloader();`);
});

it('add ng-less-javascript-enabled-patch', async () => {
const packageJsonPath = '/package.json';
tryAddFile(
tree,
packageJsonPath,
`{
"scripts": {},
"devDependencies": {}
}`
);
await runMigration();
const content = tree.readContent(packageJsonPath);
expect(content).toContain(`"ng-less-javascript-enabled-patch": "^17.0.0"`);
});
});
2 changes: 2 additions & 0 deletions schematics/ng-update/upgrade-rules/v17/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';

import { fixAngularJson } from './angularJson';
import { autoRegisterFormWidgets } from './autoRegisterFormWidgets';
import { addNljep } from './nljep';
import { updatePreloader } from './preloader';
import { removeForRoot } from './removeForRoot';
import { replaceProvideConfig } from './replaceProvideConfig';
Expand Down Expand Up @@ -34,6 +35,7 @@ export function v17Rule(): Rule {
autoRegisterFormWidgets(),
replaceProvideConfig(),
updatePreloader(),
addNljep(),
finished()
]);
};
Expand Down
21 changes: 21 additions & 0 deletions schematics/ng-update/upgrade-rules/v17/nljep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';

import { logInfo, readPackage, writePackage } from '../../../utils';

const PACKAGE_NAME = 'ng-less-javascript-enabled-patch';
export function addNljep(): Rule {
return (tree: Tree, context: SchematicContext) => {
const json = readPackage(tree);
if (json == null) return;
if (json.devDependencies[PACKAGE_NAME]) return;

if (typeof json.scripts.postinstall !== 'string') json.scripts.postinstall = '';
if (json.scripts.postinstall.length > 0) json.scripts.postinstall += ' && ';
json.scripts.postinstall += PACKAGE_NAME;

json.devDependencies[PACKAGE_NAME] = '^17.0.0';
writePackage(tree, json);

logInfo(context, `Add [https://github.com/cipchk/${PACKAGE_NAME}] for devDependencies`);
};
}

0 comments on commit d66593e

Please sign in to comment.