Skip to content

Commit

Permalink
Feat: Output faust version in dev|build|start commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
theodesp committed Apr 11, 2024
1 parent 002687f commit d7e4caa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
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';
42 changes: 42 additions & 0 deletions packages/faustwp-cli/src/utils/printFaustVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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,
);
infoLog(`Faust.js v${coreVersion}`);

Check failure on line 40 in packages/faustwp-cli/src/utils/printFaustVersion.ts

View workflow job for this annotation

GitHub Actions / lint_packages

Invalid type "string | undefined" of template literal expression
infoLog(`Faust.js CLI v${cliVersion}`);

Check failure on line 41 in packages/faustwp-cli/src/utils/printFaustVersion.ts

View workflow job for this annotation

GitHub Actions / lint_packages

Invalid type "string | undefined" of template literal expression
}

0 comments on commit d7e4caa

Please sign in to comment.