-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
75 additions
and
61 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
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 |
---|---|---|
@@ -1,43 +1,49 @@ | ||
import os from 'os'; | ||
import { execSync } from 'child_process'; | ||
import phpfmt from 'use-phpfmt'; | ||
import type { TransformationItem } from './types'; | ||
import { exec } from './utils'; | ||
|
||
export class Transformations { | ||
private readonly phpBin: string; | ||
|
||
public constructor(phpBin: string) { | ||
this.phpBin = phpBin; | ||
} | ||
public constructor(private readonly phpBin: string) {} | ||
|
||
private get baseCmd(): string { | ||
return `${this.phpBin} "${phpfmt.pharPath}"`; | ||
} | ||
|
||
public getTransformations(): TransformationItem[] { | ||
const output = execSync(`${this.baseCmd} --list-simple`).toString(); | ||
|
||
return output | ||
.trim() | ||
.split(os.EOL) | ||
.map(v => { | ||
const splited = v.split(' '); | ||
|
||
return { | ||
key: splited[0], | ||
description: splited | ||
.filter((value, index) => value && index > 0) | ||
.join(' ') | ||
.trim() | ||
}; | ||
}); | ||
public async getTransformations(): Promise<TransformationItem[]> { | ||
try { | ||
const { stdout } = await exec(`${this.baseCmd} --list-simple`); | ||
|
||
return stdout | ||
.trim() | ||
.split(os.EOL) | ||
.map(v => { | ||
const splited = v.split(' '); | ||
|
||
return { | ||
key: splited[0], | ||
description: splited | ||
.filter((value, index) => value && index > 0) | ||
.join(' ') | ||
.trim() | ||
}; | ||
}); | ||
} catch (err) { | ||
return []; | ||
} | ||
} | ||
|
||
public getExample(transformationItem: TransformationItem): string { | ||
const output = execSync( | ||
`${this.baseCmd} --help-pass ${transformationItem.key}` | ||
).toString(); | ||
|
||
return output.trim(); | ||
public async getExample( | ||
transformationItem: TransformationItem | ||
): Promise<string> { | ||
try { | ||
const { stdout } = await exec( | ||
`${this.baseCmd} --help-pass ${transformationItem.key}` | ||
); | ||
|
||
return stdout; | ||
} catch (err) { | ||
return ''; | ||
} | ||
} | ||
} |
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,4 @@ | ||
import childProcess from 'child_process'; | ||
import util from 'util'; | ||
|
||
export const exec = util.promisify(childProcess.exec); |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"extensions.supportUntrustedWorkspaces": true, | ||
"phpfmt.psr2": true, | ||
"phpfmt.indent_with_space": 4 | ||
"phpfmt.indent_with_space": 4, | ||
"phpfmt.ignore": [ | ||
".ctp", | ||
".blade.php" | ||
] | ||
} |