Skip to content

Commit

Permalink
Update CLI commands (#1228)
Browse files Browse the repository at this point in the history
* Update CLI commands
  • Loading branch information
thekevinscott authored Oct 16, 2023
1 parent a9674c2 commit 8372693
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 133 deletions.
9 changes: 8 additions & 1 deletion internals/bundlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"scripts": {
"run-bundle": "wireit",
"serve-bundle": "wireit",
"build": "wireit",
"_lint": "wireit",
"copy-files": "wireit",
Expand All @@ -34,6 +35,12 @@
"build"
]
},
"serve-bundle": {
"command": "node ./dist/bin/serve-bundle.js",
"dependencies": [
"build"
]
},
"_lint": {
"command": "eslint -c eslintrc.cjs src --ext .ts --ext .mts",
"dependencies": [
Expand All @@ -50,7 +57,7 @@
"../http-server:build"
],
"files": [
"src/**/*.ts",
"src/**/*",
"!src/**/*.test.ts",
"_templates/**/*.ejs",
"package.json",
Expand Down
35 changes: 23 additions & 12 deletions internals/bundlers/src/bin/run-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UMDBundler, } from '@internals/bundlers/umd';
import { NodeBundler, } from '@internals/bundlers/node';
import { WebpackBundler, } from '@internals/bundlers/webpack';
import { getBundlerOutputDir, } from '../utils/get-bundler-output-dir.js';
import { parseArgs } from "node:util";

const bundlers: Record<BundlerName, typeof Bundler> = {
esbuild: EsbuildBundler,
Expand All @@ -22,15 +23,25 @@ export const runBundle = async (bundlerName: BundlerName, {
return bundler;
};

const bundlerName = process.argv.pop();
if (bundlerName === undefined) {
throw new Error('You must provide a bundler name')
}
if (!isValidBundlerName(bundlerName)) {
throw new Error(`Invalid bundler provided: ${bundlerName}`)
}
const start = performance.now();
await runBundle(bundlerName);
// const duration = Math.round((performance.now() - start) / 100) * 10;
const duration = ((performance.now() - start) / 1000).toFixed(2);
console.log(`Bundled ${bundlerName} in ${duration}s`);
const main = async () => {
const {
positionals: [
bundlerName,
]
} = parseArgs({
allowPositionals: true,
});
if (bundlerName === undefined) {
throw new Error('You must provide a bundler name')
}
if (!isValidBundlerName(bundlerName)) {
throw new Error(`Invalid bundler provided: ${bundlerName}`)
}
const start = performance.now();
await runBundle(bundlerName);
// const duration = Math.round((performance.now() - start) / 100) * 10;
const duration = ((performance.now() - start) / 1000).toFixed(2);
console.log(`Bundled ${bundlerName} in ${duration}s`);
};

main();
49 changes: 37 additions & 12 deletions internals/bundlers/src/bin/serve-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UMDBundler, } from '@internals/bundlers/umd';
import { NodeBundler, } from '@internals/bundlers/node';
import { WebpackBundler, } from '@internals/bundlers/webpack';
import { getBundlerOutputDir, } from '../utils/get-bundler-output-dir.js';
import { parseArgs } from "node:util";

const bundlers: Record<BundlerName, typeof Bundler> = {
esbuild: EsbuildBundler,
Expand All @@ -21,7 +22,7 @@ interface ServeBundleOptions {

export const serveBundle = async (bundlerName: BundlerName, {
port,
useTunnel = true,
useTunnel = false,
}: ServeBundleOptions = {}): Promise<void> => {
const Bundler = bundlers[bundlerName];
const bundler = new Bundler(getBundlerOutputDir(Bundler));
Expand All @@ -39,14 +40,38 @@ export const serveBundle = async (bundlerName: BundlerName, {
].join('\n'));
};

const bundlerName = process.argv.pop();
if (bundlerName === undefined) {
throw new Error('You must provide a bundler name')
}
if (!isValidBundlerName(bundlerName)) {
throw new Error(`Invalid bundler provided: ${bundlerName}`)
}
if (bundlerName === 'node') {
throw new Error('Serving node bundles is not supported');
}
await serveBundle(bundlerName);
const main = async () => {
const {
values,
positionals: [
bundlerName,
]
} = parseArgs({
options: {
port: {
type: "string",
short: "p",
},
'use-tunnel': {
type: "boolean",
short: "t",
},
},
allowPositionals: true,
});

if (!isValidBundlerName(bundlerName)) {
throw new Error(`Invalid bundler provided: ${bundlerName}`)
}
if (bundlerName === 'node') {
throw new Error('Serving node bundles is not supported');
}
const port = values.port ? parseInt(values.port) : undefined;
await serveBundle(bundlerName, {
port,
useTunnel: values['use-tunnel'],
});

};

main();
27 changes: 0 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,6 @@
"update:npm:dependencies": {
"command": "pnpm --filter @upscalerjs/scripts update:npm:dependencies"
},
"bundle:webpack": {
"command": "pnpm --filter @internals/bundlers run-bundle -- webpack",
"dependencies": [
"./packages/upscalerjs:build:browser:esm",
"build:models:esm"
],
"files": [
"./package.json"
],
"output": [
"tmp/bundlers/webpack/**/*",
"!tmp/bundlers/webpack/node_modules"
]
},
"bundle:esbuild": {
"command": "pnpm --filter @internals/bundlers run-bundle -- esbuild",
"dependencies": [
Expand Down Expand Up @@ -295,19 +281,6 @@
"!tmp/bundlers/webpack/node_modules"
]
},
"bundle:umd": {
"command": "pnpm --filter @internals/bundlers run-bundle -- umd",
"dependencies": [
"./packages/upscalerjs:build:browser:umd",
"build:models:umd"
],
"files": [
"./package.json"
],
"output": [
"tmp/bundlers/umd/**/*"
]
},
"bundle:node": {
"command": "pnpm --filter @internals/bundlers run-bundle -- node",
"dependencies": [
Expand Down
81 changes: 0 additions & 81 deletions test/lib/start-test-server.ts

This file was deleted.

0 comments on commit 8372693

Please sign in to comment.