Skip to content

Commit 467bf9f

Browse files
authored
Merge pull request #144 from ChetanXpro/feat/add-workflow-for-code-formatting
feat: add workflow for code formatting
2 parents 2993c43 + d5432fb commit 467bf9f

File tree

6 files changed

+55
-41
lines changed

6 files changed

+55
-41
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,35 @@ on:
66
pull_request:
77
branches: [main]
88

9-
env:
10-
NODE_VERSION: 16.x
11-
129
jobs:
13-
typecheck:
10+
build:
1411
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
1514

1615
steps:
17-
- uses: actions/setup-node@v3
18-
with:
19-
node-version: ${{ env.NODE_VERSION }}
20-
- uses: actions/checkout@v3
21-
- run: |
22-
npm install
23-
npm run typecheck
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.head_ref }}
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run type check
31+
run: npm run typecheck
32+
33+
- name: Format code
34+
run: npm run format
35+
36+
- name: Commit changes
37+
uses: stefanzweifel/git-auto-commit-action@v5
38+
with:
39+
commit_message: "style: format code with prettier"
40+
branch: ${{ github.head_ref }}

cpp/whisper.cpp

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"access": "public"
99
},
1010
"bin": {
11-
"download": "dist/downloadModel.js"
11+
"nodejs-whisper": "dist/downloadModel.js"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -43,13 +43,7 @@
4343
"nodejs-whisper",
4444
"audio-to-subtitles"
4545
],
46-
"author": "chetan baliyan",
47-
"contributors": [
48-
{
49-
"name": "Michael Heuberger",
50-
"email": "[email protected]"
51-
}
52-
],
46+
"author": "chetan",
5347
"license": "MIT",
5448
"homepage": "https://github.com/ChetanXpro/nodejs-whisper#readme",
5549
"bugs": {

src/WhisperHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const constructCommand = (filePath: string, args: IOptions): string => {
2727
}
2828

2929
const modelName = MODEL_OBJECT[args.modelName as keyof typeof MODEL_OBJECT]
30-
let command = `./main ${constructOptionsFlags(args)} -l ${args.whisperOptions?.language ? args.whisperOptions?.language : 'auto'} -m "./models/${modelName}" -f "${filePath}"`
30+
let command = `./main ${constructOptionsFlags(args)} -l ${args.whisperOptions?.language ? args.whisperOptions?.language : 'auto'} -m "./models/${modelName}" -f "${filePath}"`
3131

3232
return command
3333
}

src/autoDownloadModel.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ export default async function autoDownloadModel(
4747
shell.cd('../')
4848

4949
let compileCommand
50-
if (process.platform === 'win32') {
51-
// Try mingw32-make first
52-
if (shell.which('mingw32-make')) {
53-
compileCommand = withCuda ? 'WHISPER_CUDA=1 mingw32-make -j' : 'mingw32-make -j'
54-
} else if (shell.which('make')) {
55-
compileCommand = withCuda ? 'WHISPER_CUDA=1 make -j' : 'make -j'
56-
} else {
57-
throw new Error('[Nodejs-whisper] Neither mingw32-make nor make found. Please install MinGW-w64 or MSYS2.')
58-
}
59-
} else {
60-
compileCommand = withCuda ? 'WHISPER_CUDA=1 make -j' : 'make -j'
61-
}
62-
63-
const compileResult = shell.exec(compileCommand)
50+
if (process.platform === 'win32') {
51+
// Try mingw32-make first
52+
if (shell.which('mingw32-make')) {
53+
compileCommand = withCuda ? 'WHISPER_CUDA=1 mingw32-make -j' : 'mingw32-make -j'
54+
} else if (shell.which('make')) {
55+
compileCommand = withCuda ? 'WHISPER_CUDA=1 make -j' : 'make -j'
56+
} else {
57+
throw new Error(
58+
'[Nodejs-whisper] Neither mingw32-make nor make found. Please install MinGW-w64 or MSYS2.'
59+
)
60+
}
61+
} else {
62+
compileCommand = withCuda ? 'WHISPER_CUDA=1 make -j' : 'make -j'
63+
}
6464

65+
const compileResult = shell.exec(compileCommand)
6566

6667
if (compileResult.code !== 0) {
6768
throw new Error(`[Nodejs-whisper] Failed to compile model: ${compileResult.stderr}`)

src/downloadModel.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const askIfUserWantToUseCuda = async (logger = console) => {
4646
}
4747
}
4848

49-
export default async function downloadModel(logger = console) {
49+
async function downloadModel(logger = console) {
5050
try {
5151
shell.cd(path.join(__dirname, '..', './cpp/whisper.cpp/models'))
5252

@@ -60,10 +60,9 @@ export default async function downloadModel(logger = console) {
6060
})
6161

6262
if (anyModelExist.length > 0) {
63-
return
64-
// logger.log('Models already exist. Skipping download.')
65-
} else {
66-
logger.log('[Nodejs-whisper] Models do not exist. Please Select a model to download.\n')
63+
console.log('\n[Nodejs-whisper] Currently installed models:')
64+
anyModelExist.forEach(model => console.log(`- ${model}`))
65+
console.log('\n[Nodejs-whisper] You can install additional models from the list below.\n')
6766
}
6867

6968
logger.log(`
@@ -115,4 +114,7 @@ export default async function downloadModel(logger = console) {
115114
}
116115
}
117116
// run on npx nodejs-whisper download
118-
downloadModel()
117+
downloadModel().catch(error => {
118+
console.error('Failed to download:', error)
119+
process.exit(1)
120+
})

0 commit comments

Comments
 (0)