Skip to content

Commit

Permalink
feat(tools): enable package json cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Dec 13, 2023
1 parent bfedbf4 commit c286557
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions tools/utils/regenerate-pkg-json-cli.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
import { execSync } from 'child_process';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { execSync } from 'node:child_process';
import { unlink } from 'node:fs/promises';
import yargs from 'yargs';
import { getPackageJson, outputPackageJson } from '../nx/get-package-json';

async function regeneratePackageJson({ projectName, root }) {
async function regeneratePackageJson({
clean,
projectName,
root,
}: {
clean: boolean;
projectName: string;
root: string;
}) {
const packageJson = await getPackageJson({
projectName,
root,
skipDev: true,
});
if (clean) {
await unlink(`apps/${projectName}/package-lock.json`).catch(() => {});
await unlink(`apps/${projectName}/package.json`).catch(() => {});
}
outputPackageJson(
{ output: 'file', outputPath: `apps/${projectName}` },
packageJson
packageJson,
);
execSync(`npm i --prefix apps/${projectName} --package-lock-only --force`, {
stdio: 'inherit',
});
}

(async function () {
const argv = await yargs(hideBin(process.argv))
const argv = await yargs()
.usage('Usage: $0 -p [projects]')
.options({
projectName: {
description: 'Project name',
demandOption: true,
example: 'auth',
alias: 'p',
type: 'string',
},
root: {
description: 'Project root',
demandOption: false,
default: process.cwd(),
alias: 'r',
type: 'string',
},
clean: {
description: 'Clean package-lock.json',
demandOption: false,
default: false,
alias: 'c',
type: 'boolean',
},
})
.option('verbose', {
Expand Down

0 comments on commit c286557

Please sign in to comment.