Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/cli/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare const __ENABLE_CLI_TELEMETRY__: boolean;
declare const __IS_PACKAGED_FOR_NPM__: boolean;
declare const __STUDIO_CLI_VERSION__: string;
declare const __MINIMUM_NODE_VERSION__: string;

declare module 'wpcom-xhr-request';
declare module '@wp-playground/blueprints/blueprint-schema-validator';
16 changes: 15 additions & 1 deletion apps/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path';
import { suppressPunycodeWarning } from '@studio/common/lib/suppress-punycode-warning';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import semver from 'semver';
import yargs from 'yargs';
import { registerCommand as registerExportCommand } from 'cli/commands/export';
import { registerCommand as registerImportCommand } from 'cli/commands/import';
Expand All @@ -21,6 +22,19 @@ suppressPunycodeWarning();
async function main() {
const yargsLocale = await loadTranslations();

if ( semver.lt( process.version, __MINIMUM_NODE_VERSION__ ) ) {
console.error(
sprintf(
__(
'Studio CLI requires Node.js %s or newer. You are running %s.\nUpgrade Node.js and run this command again.\nDownload: https://nodejs.org/en/download'
),
__MINIMUM_NODE_VERSION__,
process.version
)
);
process.exit( 1 );
}

const studioArgv: StudioArgv = yargs( process.argv.slice( 2 ) )
.scriptName( 'studio' )
.usage( __( 'WordPress Studio CLI' ) )
Expand Down
18 changes: 16 additions & 2 deletions apps/cli/vite.config.base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import semver from 'semver';
import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import packageJson from './package.json';

const nodeBuiltinExternals: RegExp[] = [
/^node:/,
Expand All @@ -10,8 +11,20 @@ const nodeBuiltinExternals: RegExp[] = [
/^dns\/promises$/,
];

const packageJson = JSON.parse( readFileSync( resolve( __dirname, 'package.json' ), 'utf-8' ) );
const packageJsonDependencies = Object.keys( packageJson.dependencies || {} );
const minimumNodeVersionRange = packageJson.engines?.node;

if ( typeof minimumNodeVersionRange !== 'string' || minimumNodeVersionRange.length === 0 ) {
throw new Error( 'apps/cli/package.json must define engines.node as a non-empty string.' );
}

const minimumNodeVersion = semver.minVersion( minimumNodeVersionRange )?.version;

if ( ! minimumNodeVersion ) {
throw new Error(
`Invalid engines.node range in apps/cli/package.json: ${ minimumNodeVersionRange }`
);
}

export const baseConfig = defineConfig( {
plugins: [
Expand Down Expand Up @@ -78,5 +91,6 @@ export const baseConfig = defineConfig( {
},
define: {
__STUDIO_CLI_VERSION__: JSON.stringify( packageJson.version ),
__MINIMUM_NODE_VERSION__: JSON.stringify( minimumNodeVersion ),
},
} );
Loading