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

Add platform verifier #65

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/common",
"version": "4.6.0",
"version": "4.7.0",
"description": "The Athenna common helpers to use in any Node.js ESM project.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/Exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { debug } from '#src/debug'
import { Is } from '#src/helpers/Is'
import { promisify } from 'node:util'
import { Transform } from 'node:stream'
import { File } from '#src/helpers/File'
Expand Down Expand Up @@ -56,7 +57,7 @@ export class Exec {
try {
const execOptions: ExecOptions = {}

if (process.platform === 'win32' && Uuid.verify(process.env.WT_SESSION)) {
if (Is.Windows() && Uuid.verify(process.env.WT_SESSION)) {
execOptions.shell = 'powershell'
}

Expand All @@ -73,6 +74,7 @@ export class Exec {
debug('command has failed')
debug('command stdout: %s', error.stdout)
debug('command stderr: %s', error.stderr)

if (options.ignoreErrors) {
return { stdout: error.stdout, stderr: error.stderr }
}
Expand Down
21 changes: 21 additions & 0 deletions src/helpers/Is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ export class Is {
return kind
}

/**
* Verify if the current platform is Linux.
*/
public static Linux() {
return process.platform === 'linux'
}

/**
* Verify if the current platform is Mac.
*/
public static Mac() {
return process.platform === 'darwin'
}

/**
* Verify if the current platform is Windows.
*/
public static Windows() {
return process.platform === 'win32'
}

/**
* Verify if is valid Uuid.
*/
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/ExecTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { Test, BeforeEach, type Context } from '@athenna/test'
import { Clean, Exec, File, Folder, Module, Path } from '#src'
import { Clean, Exec, File, Folder, Is, Module, Path } from '#src'
import { NodeCommandException } from '#src/exceptions/NodeCommandException'

export default class ExecTest {
Expand All @@ -24,6 +24,10 @@ export default class ExecTest {

@Test()
public async shouldBeAbleToExecuteACommandInTheVMAndGetTheStdout({ assert }: Context) {
if (Is.Windows()) {
return
}

const { stdout } = await Exec.command('ls')

assert.isTrue(stdout.includes('README.md'))
Expand All @@ -40,7 +44,7 @@ export default class ExecTest {

@Test()
public async shouldBeAbleToExecuteACommandThatThrowsErrorsAndIgnoreItInUnix({ assert }: Context) {
if (process.platform === 'win32') {
if (Is.Windows()) {
return
}

Expand Down
Loading