Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Output faust version in dev|build|start commands. #1874

Merged
merged 12 commits into from
Apr 12, 2024
15 changes: 15 additions & 0 deletions .changeset/shaggy-carpets-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@faustwp/cli': patch
---

Faust CLI now outputs version number when running dev|build|start commands.

When running those commands it will print the current Faust core and cli versions in the console:

```bash
% npm run dev -w examples/next/faustwp-getting-started
info - Faust.js v3.0.1
info - Faust.js CLI v3.0.1
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
...
```
3 changes: 3 additions & 0 deletions packages/faustwp-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getNextCliArgs,
getWpSecret,
isDebug,
printFaustVersion,
} from './utils/index.js';
import { marshallTelemetryData, sendTelemetryData } from './telemetry/index.js';

Expand Down Expand Up @@ -81,6 +82,8 @@ import { marshallTelemetryData, sendTelemetryData } from './telemetry/index.js';
}
}

printFaustVersion();

/**
* Spawn a child process using the args captured in argv and continue the
* standard i/o for the Next.js CLI.
Expand Down
29 changes: 1 addition & 28 deletions packages/faustwp-cli/src/telemetry/marshallTelemetryData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import { getCliArgs } from '../utils/index.js';
import { sanitizePackageJsonVersion } from '../utils/printFaustVersion.js';

export interface TelemetryData {
node_faustwp_core_version?: string;
Expand All @@ -14,34 +15,6 @@ export interface TelemetryData {
command?: string;
}

/**
* Sanitizes the version from a dependency in package.json.
*
* @param version The dependency version.
* @returns A sanitized version or undefined if the version is a path.
*/
const sanitizePackageJsonVersion = (_version: string | undefined) => {
let version = _version;

if (!version) {
return undefined;
}

if (version.charAt(0) === '^' || version.charAt(0) === '~') {
version = version.substring(1);
}

/**
* If a dependency is a file path set the value to undefined as we
* don't want to collect file paths in telemetry
*/
if (version.startsWith('file:')) {
version = undefined;
}

return version;
};

/**
* Marshall the JS telemetry data.
* @param command Command that initiated the request
Expand Down
1 change: 1 addition & 0 deletions packages/faustwp-cli/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { getWpSecret } from './getWpSecret.js';
export { getWpUrl } from './getWpUrl.js';
export { getGraphqlEndpoint } from './getGraphqlEndpoint.js';
export { hasYarn } from './hasYarn.js';
export { printFaustVersion } from './printFaustVersion.js';
43 changes: 43 additions & 0 deletions packages/faustwp-cli/src/utils/printFaustVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from 'fs';
import { infoLog } from '../stdout/index.js';

/**
* Sanitizes the version from a dependency in package.json.
*
* @param version The dependency version.
* @returns A sanitized version or undefined if the version is a path.
*/
export function sanitizePackageJsonVersion(_version: string | undefined) {
let version = _version;

if (!version) {
return undefined;
}

if (version.charAt(0) === '^' || version.charAt(0) === '~') {
version = version.substring(1);
}

/**
* If a dependency is a file path set the value to undefined as we
* don't want to collect file paths in telemetry
*/
if (version.startsWith('file:')) {
version = undefined;
}

return version;
}

export function printFaustVersion(): void {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const coreVersion = sanitizePackageJsonVersion(
packageJson?.dependencies?.['@faustwp/core'] as string | undefined,
);
const cliVersion = sanitizePackageJsonVersion(
packageJson?.dependencies?.['@faustwp/cli'] as string | undefined,
);
// eslint-disable-next-line
infoLog(`Faust.js v${coreVersion || 'unknown'}`);
infoLog(`Faust.js CLI v${cliVersion || 'unknown'}`);
}
Loading