From 3be9299cef9eb42401bcd62e6f557c3cef1861e3 Mon Sep 17 00:00:00 2001 From: Richard Dzurus Date: Fri, 20 Jun 2025 14:54:41 +0200 Subject: [PATCH 1/2] welcome message for users with package version --- lib/welcome.js | 20 ++++++++++++++++++++ package.json | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 lib/welcome.js diff --git a/lib/welcome.js b/lib/welcome.js new file mode 100644 index 0000000..e7ddb17 --- /dev/null +++ b/lib/welcome.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node +const { execSync } = require('child_process'); +const chalk = require('chalk'); + +try { + // Get the version from the CLI + const version = execSync('node build/cli.js --version', { encoding: 'utf-8' }).trim(); + + console.log(''); + console.log(chalk.green('✓ PolyAPI SDK installed successfully!')); + console.log(chalk.blue(`📦 Version: ${version}`)); + console.log(''); + console.log(chalk.yellow('Getting started:')); + console.log(' • Run ' + chalk.cyan('npx poly --help') + ' to see all available commands'); + console.log(' • Run ' + chalk.cyan('npx poly setup') + ' to configure your Poly connection'); + console.log(''); +} catch (error) { + // Silently fail if there's an issue - don't break the installation + console.log(chalk.green('✓ PolyAPI SDK installed successfully!')); +} \ No newline at end of file diff --git a/package.json b/package.json index 13f05d7..95241c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polyapi", - "version": "0.24.0", + "version": "0.24.2", "description": "Poly is a CLI tool to help create and manage your Poly definitions.", "license": "MIT", "repository": { @@ -11,7 +11,8 @@ "files": [ "build/**/*", "index.js", - "index.d.ts" + "index.d.ts", + "lib/welcome.js" ], "main": "index.js", "bin": { @@ -28,6 +29,7 @@ "prepublishOnly": "npm run lint && npm run build", "preversion": "npm run lint", "postversion": "git push && git push --tags", + "postinstall": "node lib/welcome.js", "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js" }, "devDependencies": { From 64017d7bfe3b5ce5fcf29c534f0e4571179614fa Mon Sep 17 00:00:00 2001 From: Richard Dzurus Date: Fri, 20 Jun 2025 16:49:21 +0200 Subject: [PATCH 2/2] show welcome message on first use --- lib/welcome.js | 20 -------------------- package.json | 5 ++--- src/cli.ts | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 23 deletions(-) delete mode 100644 lib/welcome.js diff --git a/lib/welcome.js b/lib/welcome.js deleted file mode 100644 index e7ddb17..0000000 --- a/lib/welcome.js +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node -const { execSync } = require('child_process'); -const chalk = require('chalk'); - -try { - // Get the version from the CLI - const version = execSync('node build/cli.js --version', { encoding: 'utf-8' }).trim(); - - console.log(''); - console.log(chalk.green('✓ PolyAPI SDK installed successfully!')); - console.log(chalk.blue(`📦 Version: ${version}`)); - console.log(''); - console.log(chalk.yellow('Getting started:')); - console.log(' • Run ' + chalk.cyan('npx poly --help') + ' to see all available commands'); - console.log(' • Run ' + chalk.cyan('npx poly setup') + ' to configure your Poly connection'); - console.log(''); -} catch (error) { - // Silently fail if there's an issue - don't break the installation - console.log(chalk.green('✓ PolyAPI SDK installed successfully!')); -} \ No newline at end of file diff --git a/package.json b/package.json index 95241c3..1ea673b 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "files": [ "build/**/*", "index.js", - "index.d.ts", - "lib/welcome.js" + "index.d.ts" ], "main": "index.js", "bin": { @@ -29,7 +28,7 @@ "prepublishOnly": "npm run lint && npm run build", "preversion": "npm run lint", "postversion": "git push && git push --tags", - "postinstall": "node lib/welcome.js", + "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js" }, "devDependencies": { diff --git a/src/cli.ts b/src/cli.ts index 2e6223e..2ce888b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -8,12 +8,47 @@ import { loadConfig } from './config'; import { type RenameT } from './commands/model'; import { DEFAULT_POLY_PATH } from './constants'; import { isValidHttpUrl } from './utils'; +import fs from 'fs'; +import path from 'path'; if (process.env.NO_COLOR) { // Support NO_COLOR env variable https://no-color.org/ chalk.level = 0; } +const showWelcomeIfFirstTime = () => { + try { + const polyDir = DEFAULT_POLY_PATH; + const welcomeFile = path.join(polyDir, '.welcome-shown'); + + // If welcome has already been shown, return early + if (fs.existsSync(welcomeFile)) { + return; + } + + // Get version from package.json + const packagePath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); + const version = packageJson.version; + + // Show welcome message + console.log(''); + console.log(chalk.green('✓ PolyAPI SDK installed successfully!')); + console.log(chalk.blue(`📦 Version: ${version}`)); + console.log(''); + console.log(chalk.yellow('Getting started:')); + console.log(' • Run ' + chalk.cyan('poly --help') + ' to see all available commands'); + console.log(' • Run ' + chalk.cyan('poly setup') + ' to configure your Poly connection'); + console.log(''); + + // Ensure .poly directory exists and mark welcome as shown + fs.mkdirSync(polyDir, { recursive: true }); + fs.writeFileSync(welcomeFile, new Date().toISOString()); + } catch (error) { + // Silently fail if there's an issue - don't break the CLI + } +}; + const checkPolyConfig = (polyPath: string) => { loadConfig(polyPath); @@ -24,6 +59,9 @@ const checkPolyConfig = (polyPath: string) => { return true; }; +// Show welcome message on first usage +showWelcomeIfFirstTime(); + void yargs .usage('$0 [args]') .command(