Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #98 from nachoaldamav/development
Browse files Browse the repository at this point in the history
Merge `development`
  • Loading branch information
nachoaldamav authored Oct 15, 2022
2 parents 93858c7 + 1fe6144 commit b5654e2
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 120 deletions.
8 changes: 5 additions & 3 deletions packages/cli/src/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env node
import { commands } from "../commands/index.js";
import { args } from "../utils/arguments.js";
import chalk from "chalk";
import path from "node:path";
import readPackage from "../utils/readPackage.js";
import { __dirname } from "../utils/__dirname.js";
import "../utils/globals.js";

function main() {
async function main() {
const { version } = readPackage(
path.join(__dirname, "..", "..", "package.json")
);
Expand All @@ -18,8 +16,12 @@ function main() {
)
);

const { args } = await import("../utils/arguments.js");

const argv = args();

const { commands } = await import("../commands/index.js");

commands(argv);
}

Expand Down
33 changes: 18 additions & 15 deletions packages/cli/src/commands/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { execa } from "execa";
import { fileURLToPath } from "url";
import readPackage from "../utils/readPackage.js";

const delCommand = os.platform() === "win32" ? "del /s /q" : "rm -rf";

const homeDir = os.homedir();

const __filename = fileURLToPath(import.meta.url);
Expand All @@ -21,7 +23,7 @@ const tests = [
{
name: "NPM install (no cache / no lockfile)",
command: "npm install --force",
pre: "npm cache clean -f && rm -rf node_modules package-lock.json",
pre: `npm cache clean -f && ${delCommand} node_modules package-lock.json`,
spinner: ora(
chalk.green(`Running "NPM install (no cache / no lockfile)"...`)
).stop(),
Expand All @@ -30,7 +32,7 @@ const tests = [
{
name: "NPM install (with cache / no lockfile)",
command: "npm install --force",
pre: "rm -rf node_modules package-lock.json",
pre: `${delCommand} node_modules package-lock.json`,
spinner: ora(
chalk.green(`Running "NPM install (with cache / no lockfile)"...`)
).stop(),
Expand All @@ -39,7 +41,7 @@ const tests = [
{
name: "NPM install (with cache / with lockfile)",
command: "npm install --force",
pre: "rm -rf node_modules/",
pre: `${delCommand} node_modules`,
spinner: ora(
chalk.green(`Running "NPM install (with cache / with lockfile)"...`)
).stop(),
Expand All @@ -48,7 +50,7 @@ const tests = [
{
name: "YARN install (no cache / no lockfile)",
command: "yarn install --force",
pre: "yarn cache clean && rm -rf node_modules yarn.lock",
pre: `yarn cache clean && ${delCommand} node_modules yarn.lock`,
spinner: ora(
chalk.green(`Running "YARN install (no cache / no lockfile)"...`)
).stop(),
Expand All @@ -57,7 +59,7 @@ const tests = [
{
name: "YARN install (with cache / no lockfile)",
command: "yarn install --force",
pre: "rm -rf node_modules yarn.lock",
pre: `${delCommand} node_modules yarn.lock`,
spinner: ora(
chalk.green(`Running "YARN install (with cache / no lockfile)"...`)
).stop(),
Expand All @@ -66,7 +68,7 @@ const tests = [
{
name: "YARN install (with cache / with lockfile)",
command: "yarn install --force",
pre: "rm -rf node_modules",
pre: `${delCommand} node_modules`,
spinner: ora(
chalk.green(`Running "YARN install (with cache / with lockfile)"...`)
).stop(),
Expand All @@ -76,7 +78,7 @@ const tests = [
{
name: "⚡ ULTRA install (no cache / no lockfile)",
command: "ultra install",
pre: "npm cache clean -f && ultra clear",
pre: "ultra clear",
spinner: ora(
chalk.green(`Running "ULTRA install (no cache / no lockfile)"...`)
).stop(),
Expand All @@ -85,7 +87,8 @@ const tests = [
{
name: "⚡ ULTRA install (with cache / no lockfile)",
command: "ultra install",
pre: "rm -rf node_modules ultra.lock",
/* pre: "rm -rf node_modules ultra.lock", */
pre: `${delCommand} node_modules ultra.lock`,
spinner: ora(
chalk.green(`Running "ULTRA install (with cache / no lockfile)"...`)
).stop(),
Expand All @@ -94,7 +97,7 @@ const tests = [
{
name: "⚡ ULTRA install (with cache / with lockfile)",
command: "ultra install",
pre: "rm -rf node_modules",
pre: `${delCommand} node_modules`,
spinner: ora(
chalk.green(`Running "ULTRA install (with cache / with lockfile)"...`)
).stop(),
Expand Down Expand Up @@ -131,15 +134,15 @@ const tests = [
name: "PNPM install (no cache / no lockfile)",
command:
"pnpm install --force --cache-dir=cache/cache --store-dir=cache/store --no-strict-peer-dependencies",
pre: `npm cache clean -f && pnpm store prune && rm -rf node_modules pnpm-lock.yaml ${homeDir}.local/share/pnpm/store/v3 cache/`,
pre: `npm cache clean -f && pnpm store prune && ${delCommand} node_modules pnpm-lock.yaml ${homeDir}.local/share/pnpm/store/v3 cache/`,
spinner: ora(chalk.green(`Running "PNPM install (no cache)"...`)).stop(),
group: 1,
},
{
name: "PNPM install (with cache / no lockfile)",
command:
"pnpm install --force --cache-dir=cache/cache --store-dir=cache/store --no-strict-peer-dependencies",
pre: `rm -rf node_modules pnpm-lock.yaml`,
pre: `${delCommand} node_modules pnpm-lock.yaml`,
spinner: ora(
chalk.green(`Running "PNPM install (with cache / no lockfile)"...`)
).stop(),
Expand All @@ -149,15 +152,15 @@ const tests = [
name: "PNPM install (with cache / with lockfile)",
command:
"pnpm install --force --cache-dir=cache/cache --store-dir=cache/store --no-strict-peer-dependencies",
pre: "rm -rf node_modules",
pre: `${delCommand} node_modules`,
spinner: ora(chalk.green(`Running "PNPM install (with cache)"...`)).stop(),
group: 3,
},

{
name: "Bun install (no cache / no lockfile)",
command: "bun install",
pre: `npm cache clean -f && rm -rf ${homeDir}.bun bun.lockb node_modules package-lock.json yarn.lock`,
pre: `npm cache clean -f && ${delCommand} ${homeDir}.bun bun.lockb node_modules package-lock.json yarn.lock`,
spinner: ora(
chalk.green(`Running "Bun install (no cache / no lockfile)"...`)
).stop(),
Expand All @@ -166,7 +169,7 @@ const tests = [
{
name: "Bun install (with cache / no lockfile)",
command: "bun install",
pre: "rm -rf node_modules bun.lockb package-lock.json yarn.lock",
pre: `${delCommand} node_modules bun.lockb package-lock.json yarn.lock`,
spinner: ora(
chalk.green(`Running "Bun install (with cache / no lockfile)"...`)
).stop(),
Expand All @@ -175,7 +178,7 @@ const tests = [
{
name: "Bun install (with cache / with lockfile)",
command: "bun install",
pre: "rm -rf node_modules",
pre: `${delCommand} node_modules`,
spinner: ora(
chalk.green(`Running "Bun install (with cache / with lockfile)"...`)
).stop(),
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import parseTime from "../utils/parseTime.js";
import { ultraExtract } from "../utils/extract.js";
import readPackage from "../utils/readPackage.js";

export default async function continuousInstall() {
export async function continuousInstall() {
try {
const lockFile: string | null = readFileSync(
join(process.cwd(), "ultra.lock"),
Expand Down Expand Up @@ -90,14 +90,15 @@ async function ciDownloader(spec: string, pathname: string, spinner: Ora) {
});

const tarball = manifest.dist.tarball;
const integrity = manifest.dist.integrity;

if (!existsSync(pathname)) {
mkdirSync(pathname, { recursive: true });
}

spinner.text = chalk.green(`${spec}`);
spinner.prefixText = "📦";
await ultraExtract(pathname, tarball);
await ultraExtract(pathname, tarball, integrity);

spinner.prefixText = "🔗";
const pkg = readPackage(join(pathname, "package.json"));
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getDeps } from "../utils/getDeps.js";
import readPackage from "../utils/readPackage.js";
import manifestFetcher from "../utils/manifestFetcher.js";

export default async function create(args: string[]) {
export async function create(args: string[]) {
if (args.length === 0) {
console.log(
chalk.red(
Expand Down
89 changes: 50 additions & 39 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,76 @@
import path from "node:path";
import { clear } from "./clear.js";
import install from "./install.js";
import { benchmark } from "./benchmark.js";
import upgrade from "./upgrade.js";
import list from "./list.js";
import run from "./run.js";
import { update } from "../utils/readConfig.js";
import create from "./create.js";
import remove from "./remove.js";
import test from "./test.js";
import init from "./init.js";
import continuousInstall from "./ci.js";
import readPackage from "../utils/readPackage.js";

const comms = [
{
name: "install",
description: "Install a package",
command: install,
abr: "i",
params: true,
},
{
name: "benchmark",
description: "Benchmark a package",
command: benchmark,
abr: "b",
params: false,
},
{
name: "upgrade",
description: "Upgrade FNPM",
command: upgrade,
abr: "u",
params: false,
},
{
name: "set",
description: "Set a config value",
command: update,
abr: "s",
params: true,
},
{
name: "list",
description: "List package versions",
command: list,
abr: "ls",
params: true,
},
{
name: "run",
description: "Run a script",
command: run,
abr: "r",
params: true,
},
{
name: "create",
description: "Create a new package from a template",
command: create,
abr: "c",
params: true,
},
{
name: "remove",
description: "Remove a package",
command: remove,
abr: "rm",
params: true,
},
{
name: "clear",
description: "Clear the cache",
command: clear,
abr: "c",
params: false,
},
{
name: "test",
description: "Run a tests",
command: test,
abr: "t",
params: true,
},
{
name: "init",
description: "Initialize a package.json file",
command: init,
abr: "init",
params: true,
},
{
name: "ci",
description: "Run a continuous install",
command: continuousInstall,
abr: "ci",
params: false,
},
Expand All @@ -107,22 +83,57 @@ export async function commands(args: string[]) {
process.exit(0);
}

const comm = comms.find((c) => c.name === command || c.abr === command);

if (comm) {
// @ts-ignore-next-line
return comm.command(rest);
}
if (command === "help" || command === "-h") {
process.exit(0);
} else if (command === "upgrade" || command === "u") {
const { upgrade } = await import("./upgrade.js");
return upgrade();
} else if (command === "install" || command === "i") {
const { install } = await import("./install.js");
return install(rest);
} else if (command === "benchmark" || command === "b") {
const { benchmark } = await import("./benchmark.js");
return benchmark(rest);
} else if (command === "set" || command === "s") {
const { update } = await import("../utils/readConfig.js");
return update(rest);
} else if (command === "list" || command === "ls") {
const { list } = await import("./list.js");
return list(rest);
} else if (command === "run" || command === "r") {
const { run } = await import("./run.js");
return run(rest);
} else if (command === "create" || command === "c") {
const { create } = await import("./create.js");
return create(rest);
} else if (command === "remove" || command === "rm") {
const { remove } = await import("./remove.js");
return remove(rest);
} else if (command === "clear" || command === "c") {
const { clear } = await import("./clear.js");
return clear();
} else if (command === "test" || command === "t") {
const { test } = await import("./test.js");
return test(rest);
} else if (command === "init" || command === "init") {
const { init } = await import("./init.js");
return init(rest);
} else if (command === "ci" || command === "ci") {
const { continuousInstall } = await import("./ci.js");
return continuousInstall();
} else {
const pkg = readPackage(path.join(process.cwd(), "package.json"));

const pkg = readPackage(path.join(process.cwd(), "package.json"));
if (pkg && pkg.scripts && pkg.scripts[command]) {
const { run } = await import("./run.js");
return run([command, ...rest]);
}

if (pkg && pkg.scripts && pkg.scripts[command]) {
return run([command, ...rest]);
console.log("Unknown command");
console.log("Available commands:");
comms.forEach((c) => {
console.log(`- ${c.name}: ${c.description}`);
});
process.exit(1);
}

console.log("Unknown command");
console.log("Available commands:");
comms.forEach((c) => {
console.log(`- ${c.name}: ${c.description}`);
});
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chalk from "chalk";
import { __dirname } from "../utils/__dirname.js";
import samplePkg from "../utils/sample/package.js";

export default async function init(args: string[]) {
export async function init(args: string[]) {
let sampleJson = samplePkg;
if (existsSync("package.json")) {
console.log(
Expand Down
Loading

0 comments on commit b5654e2

Please sign in to comment.