Skip to content

Commit

Permalink
refactor: remove default exports (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin authored Dec 27, 2024
1 parent 7cf54f3 commit 7c6cfdc
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 142 deletions.
6 changes: 3 additions & 3 deletions src/commands/defaultconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ajv, type JSONSchemaType } from "ajv";
import chalk from "chalk";
import { Command } from "commander";

import util from "../lib/util.js";
import { getNodeCGPath, isBundleFolder } from "../lib/util.js";

const ajv = new Ajv({ useDefaults: true, strict: true });

Expand All @@ -18,10 +18,10 @@ export function defaultconfigCommand(program: Command) {

function action(bundleName?: string) {
const cwd = process.cwd();
const nodecgPath = util.getNodeCGPath();
const nodecgPath = getNodeCGPath();

if (!bundleName) {
if (util.isBundleFolder(cwd)) {
if (isBundleFolder(cwd)) {
bundleName = bundleName ?? path.basename(cwd);
} else {
console.error(
Expand Down
8 changes: 4 additions & 4 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import HostedGitInfo from "hosted-git-info";
import npa from "npm-package-arg";
import semver, { SemVer } from "semver";

import fetchTags from "../lib/fetch-tags.js";
import installBundleDeps from "../lib/install-bundle-deps.js";
import util from "../lib/util.js";
import { fetchTags } from "../lib/fetch-tags.js";
import { installBundleDeps } from "../lib/install-bundle-deps.js";
import { getNodeCGPath } from "../lib/util.js";

export function installCommand(program: Command) {
program
Expand Down Expand Up @@ -40,7 +40,7 @@ function action(repo: string, options: { dev: boolean }) {
repo = repoParts[0] ?? "";
}

const nodecgPath = util.getNodeCGPath();
const nodecgPath = getNodeCGPath();
const parsed = npa(repo);
if (!parsed.hosted) {
console.error(
Expand Down
14 changes: 9 additions & 5 deletions src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import inquirer from "inquirer";
import semver from "semver";
import * as tar from "tar";

import fetchTags from "../lib/fetch-tags.js";
import util from "../lib/util.js";
import { fetchTags } from "../lib/fetch-tags.js";
import {
getCurrentNodeCGVersion,
getNodeCGRelease,
pathContainsNodeCG,
} from "../lib/util.js";

const NODECG_GIT_URL = "https://github.com/nodecg/nodecg.git";

Expand All @@ -36,7 +40,7 @@ async function decideActionVersion(
// If NodeCG exists in the cwd, but the `-u` flag was not supplied, display an error and return.
// If it was supplied, fetch the latest tags and set the `isUpdate` flag to true for later use.
// Else, if this is a clean, empty directory, then we need to clone a fresh copy of NodeCG into the cwd.
if (util.pathContainsNodeCG(process.cwd())) {
if (pathContainsNodeCG(process.cwd())) {
if (!options.update) {
console.error("NodeCG is already installed in this directory.");
console.error(
Expand Down Expand Up @@ -101,7 +105,7 @@ async function decideActionVersion(
let downgrade = false;

if (isUpdate) {
current = util.getCurrentNodeCGVersion();
current = getCurrentNodeCGVersion();

if (semver.eq(target, current)) {
console.log(
Expand Down Expand Up @@ -230,7 +234,7 @@ async function actionV2(
}

process.stdout.write(`Downloading ${target} from npm... `);
const release = await util.getNodeCGRelease(target);
const release = await getNodeCGRelease(target);

process.stdout.write(chalk.green("done!") + os.EOL);

Expand Down
4 changes: 2 additions & 2 deletions src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execSync } from "node:child_process";

import { Command } from "commander";

import util from "../lib/util.js";
import { pathContainsNodeCG } from "../lib/util.js";

export function startCommand(program: Command) {
program
Expand All @@ -11,7 +11,7 @@ export function startCommand(program: Command) {
.description("Start NodeCG")
.action((options: { disableSourceMaps: boolean }) => {
// Check if nodecg is already installed
if (util.pathContainsNodeCG(process.cwd())) {
if (pathContainsNodeCG(process.cwd())) {
if (options.disableSourceMaps) {
execSync("node index.js", { stdio: "inherit" });
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chalk from "chalk";
import { Command } from "commander";
import inquirer from "inquirer";

import util from "../lib/util.js";
import { getNodeCGPath } from "../lib/util.js";

export function uninstallCommand(program: Command) {
program
Expand All @@ -17,7 +17,7 @@ export function uninstallCommand(program: Command) {
}

function action(bundleName: string, options: { force: boolean }) {
const nodecgPath = util.getNodeCGPath();
const nodecgPath = getNodeCGPath();
const bundlePath = path.join(nodecgPath, "bundles/", bundleName);

if (!fs.existsSync(bundlePath)) {
Expand Down
1 change: 0 additions & 1 deletion src/dts/packages.d.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chalk from "chalk";
import { Command } from "commander";
import semver from "semver";

import util from "./lib/util.js";
import { getLatestCLIRelease } from "./lib/util.js";

const program = new Command("nodecg");
const dirname = path.dirname(fileURLToPath(import.meta.url));
Expand All @@ -17,8 +17,7 @@ const packageVersion: string = JSON.parse(
);

// Check for updates, asynchronously, so as to not make the CLI startup time excessively slow
util
.getLatestCLIRelease()
getLatestCLIRelease()
.then((release) => {
if (semver.gt(release.version, packageVersion)) {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fetch-tags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from "child_process";

export default function (repoUrl: string) {
export function fetchTags(repoUrl: string) {
const rawTags = execSync(`git ls-remote --refs --tags ${repoUrl}`)
.toString()
.trim()
Expand Down
6 changes: 3 additions & 3 deletions src/lib/install-bundle-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { format } from "node:util";

import chalk from "chalk";

import util from "./util.js";
import { isBundleFolder } from "./util.js";

/**
* Installs npm and bower dependencies for the NodeCG bundle present at the given path.
* @param bundlePath - The path of the NodeCG bundle to install dependencies for.
* @param installDev - Whether to install devDependencies.
*/
export default function (bundlePath: string, installDev = false) {
if (!util.isBundleFolder(bundlePath)) {
export function installBundleDeps(bundlePath: string, installDev = false) {
if (!isBundleFolder(bundlePath)) {
console.error(
chalk.red("Error:") +
" There doesn't seem to be a valid NodeCG bundle in this folder:" +
Expand Down
98 changes: 98 additions & 0 deletions src/lib/sample/npm-release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"name": "nodecg-cli",
"version": "8.7.0",
"license": "MIT",
"_id": "[email protected]",
"maintainers": [
{ "name": "mattmcnam", "email": "[email protected]" },
{ "name": "hoishin", "email": "[email protected]" }
],
"contributors": [
{
"url": "https://alexvan.camp/",
"name": "Alex Van Camp",
"email": "[email protected]"
},
{
"url": "http://mattmcn.com/",
"name": "Matthew McNamara",
"email": "[email protected]"
},
{ "name": "Keiichiro Amemiya", "email": "[email protected]" }
],
"homepage": "https://github.com/nodecg/nodecg-cli#readme",
"bugs": { "url": "http://github.com/nodecg/nodecg-cli/issues" },
"bin": { "nodecg": "dist/bin/nodecg.js" },
"dist": {
"shasum": "bd59db2d98c2077bc03623cb9be59ff45fb511a2",
"tarball": "https://registry.npmjs.org/nodecg-cli/-/nodecg-cli-8.7.0.tgz",
"fileCount": 28,
"integrity": "sha512-RcoE8PhtivBz1dtKDmgBh3MTozckwymcPr9UC1oiagYMlDLoTvLC1Bqssef5h+rNNK/aBeVB33leySFEQWNbjQ==",
"signatures": [
{
"sig": "MEUCIQDuXO/x48us+Bt7A9SskHcLDaAmDFhEDCgbMcTfolZHUQIgNLF0GtmhOF5COKdZue+HwYIRAeO8KbScnZeE/U6PQe4=",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 155193
},
"type": "module",
"engines": { "node": "^18.17.0 || ^20.9.0 || ^22.11.0" },
"gitHead": "15d3992ec6d6eeb874d9c20473a63435689acbc9",
"scripts": {
"dev": "tsc --build tsconfig.build.json --watch",
"fix": "run-s fix:*",
"test": "vitest",
"build": "del-cli dist && tsc --build tsconfig.build.json",
"format": "prettier --write \"**/*.ts\"",
"static": "run-s static:*",
"fix:eslint": "eslint --fix",
"fix:prettier": "prettier --write \"**/*.ts\"",
"static:eslint": "eslint --cache",
"static:prettier": "prettier --check \"**/*.ts\""
},
"_npmUser": { "name": "hoishin", "email": "[email protected]" },
"prettier": {},
"repository": {
"url": "git://github.com/nodecg/nodecg-cli.git",
"type": "git"
},
"_npmVersion": "10.9.0",
"description": "The NodeCG command line interface.",
"directories": {},
"_nodeVersion": "22.12.0",
"dependencies": {
"tar": "^7.4.3",
"chalk": "^5.4.1",
"semver": "^7.6.3",
"inquirer": "^12.3.0",
"commander": "^12.1.0",
"hosted-git-info": "^8.0.2",
"npm-package-arg": "^12.0.1",
"json-schema-defaults": "0.4.0",
"json-schema-to-typescript": "^15.0.3"
},
"_hasShrinkwrap": false,
"devDependencies": {
"eslint": "^9.17.0",
"vitest": "^2.1.8",
"del-cli": "^6.0.0",
"prettier": "^3.4.2",
"type-fest": "^4.31.0",
"@eslint/js": "^9.17.0",
"typescript": "~5.7.2",
"@types/node": "18",
"npm-run-all2": "^7.0.2",
"@types/semver": "^7.5.8",
"typescript-eslint": "^8.18.2",
"@vitest/coverage-v8": "^2.1.8",
"@types/hosted-git-info": "^3.0.5",
"@types/npm-package-arg": "^6.1.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-simple-import-sort": "^12.1.1"
},
"_npmOperationalInternal": {
"tmp": "tmp/nodecg-cli_8.7.0_1735252303987_0.756945223884677",
"host": "s3://npm-registry-packages-npm-production"
}
}
3 changes: 3 additions & 0 deletions src/lib/sample/npm-release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import npmRelease from "./npm-release.json" with { type: "json" };

export type NpmRelease = typeof npmRelease;
Loading

0 comments on commit 7c6cfdc

Please sign in to comment.