Skip to content

Commit

Permalink
add next-on-pages version to CLI (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz authored Apr 3, 2023
1 parent e0c53fe commit 70b2e80
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-ravens-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': minor
---

show the CLI version and also add the --version flag
2 changes: 1 addition & 1 deletion src/buildApplication/buildMetadataFiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writeFile } from 'fs/promises';
import { version as nextOnPagesVersion } from '../../package.json';
import { nextOnPagesVersion } from '../utils';

/**
* Builds metadata files needed for the worker to correctly run.
Expand Down
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type CliOptions = {
watch: boolean;
skipBuild: boolean;
experimentalMinify: boolean;
version: boolean;
};

/**
Expand All @@ -20,6 +21,7 @@ export function getCliOptions(): CliOptions {
watch: process.argv.includes('--watch'),
skipBuild: process.argv.includes('--skip-build'),
experimentalMinify: process.argv.includes('--experimental-minify'),
version: process.argv.includes('--version'),
};
}

Expand All @@ -36,6 +38,8 @@ export function printCliHelpMessage(): void {
--help: Shows this help message
--version: Shows the version of the package
--skip-build: Doesn't run 'vercel build' automatically
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ import { watch } from 'chokidar';
import pLimit from 'p-limit';
import { cliLog, CliOptions, getCliOptions, printCliHelpMessage } from './cli';
import { buildApplication } from './buildApplication';
import { nextOnPagesVersion } from './utils';

const limit = pLimit(1);

const cliOptions = getCliOptions();
runNextOnPages(cliOptions);

function runNextOnPages(options: CliOptions): void {
cliLog('@cloudflare/next-on-pages CLI');
if (options.version) {
// eslint-disable-next-line no-console -- for the version lets simply print it plainly
console.log(nextOnPagesVersion);
return;
}

cliLog(`@cloudflare/next-on-pages CLI v.${nextOnPagesVersion}`);

if (options.help) {
printCliHelpMessage();
return;
}

runBuild(options);

if (options.watch) {
setWatchMode(() => runBuild(options));
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './fs';
export * from './version';
4 changes: 4 additions & 0 deletions src/utils/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { version } from '../../package.json';

/** Current version of the @cloudflare/next-on-pages package */
export const nextOnPagesVersion = version;

0 comments on commit 70b2e80

Please sign in to comment.