Skip to content

Instantly share code, notes, and snippets.

@dbritto-dev
Last active July 4, 2024 19:29
Show Gist options
  • Select an option

  • Save dbritto-dev/36699fae284bdc90066e37517105141c to your computer and use it in GitHub Desktop.

Select an option

Save dbritto-dev/36699fae284bdc90066e37517105141c to your computer and use it in GitHub Desktop.

Revisions

  1. dbritto-dev revised this gist Jul 4, 2024. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions npm-ri.js
    Original file line number Diff line number Diff line change
    @@ -6,20 +6,18 @@ const dependencies = Object.keys(pkg.dependencies || {});
    const devDependencies = Object.keys(pkg.devDependencies || {});
    const pkgRegex = new RegExp(process.argv.slice(2)[0]);

    const filteredDependencies = dependencies
    const latestDependencies = dependencies
    .concat(devDependencies)
    .filter((dependency) => pkgRegex.test(dependency));
    const latestDependencies = filteredDependencies.map(
    (dependency) => `${dependency}@latest`
    );
    .filter((dependency) => pkgRegex.test(dependency))
    .map((dependency) => `${dependency}@latest`);

    if (filteredDependencies.length > 0) {
    const npmInstall = spawn("npm", ["install", ...latestDependencies]);
    if (latestDependencies.length > 0) {
    const npmInstall = spawn("npm", ["install"].concat(latestDependencies));

    npmInstall.on("close", (code) => {
    if (code === 0) {
    console.info(
    `The next packages were updated to their latest version:\n${filteredDependencies.join(
    `The next packages were updated to their latest version:\n${latestDependencies.join(
    "\n"
    )}`
    );
    @@ -28,6 +26,8 @@ if (filteredDependencies.length > 0) {
    }
    });
    } else {
    console.log(`No matches found with the next regular expression: ${pkgRegex}`);
    console.log(
    `No packages found with the next regular expression: ${pkgRegex}`
    );
    process.exit(1);
    }
  2. dbritto-dev renamed this gist Jul 4, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. dbritto-dev created this gist Jul 4, 2024.
    33 changes: 33 additions & 0 deletions npm-i-regex.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    /* eslint-disable unicorn/no-process-exit */
    const { spawn } = require("child_process");
    const pkg = require("./package.json");

    const dependencies = Object.keys(pkg.dependencies || {});
    const devDependencies = Object.keys(pkg.devDependencies || {});
    const pkgRegex = new RegExp(process.argv.slice(2)[0]);

    const filteredDependencies = dependencies
    .concat(devDependencies)
    .filter((dependency) => pkgRegex.test(dependency));
    const latestDependencies = filteredDependencies.map(
    (dependency) => `${dependency}@latest`
    );

    if (filteredDependencies.length > 0) {
    const npmInstall = spawn("npm", ["install", ...latestDependencies]);

    npmInstall.on("close", (code) => {
    if (code === 0) {
    console.info(
    `The next packages were updated to their latest version:\n${filteredDependencies.join(
    "\n"
    )}`
    );
    } else {
    console.error(`Something went wrong`);
    }
    });
    } else {
    console.log(`No matches found with the next regular expression: ${pkgRegex}`);
    process.exit(1);
    }