-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Output faust version in dev|build|start commands.
- Loading branch information
Showing
5 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
infoLog(`Faust.js CLI v${cliVersion}`); | ||
} |