Skip to content

Commit 97ac4de

Browse files
committed
Remove node dependencies
1 parent 7f4057c commit 97ac4de

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

.changeset/nice-candles-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"scan-chart": patch
3+
---
4+
5+
Remove node dependencies

src/audio/audio-scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getBasename, hasAudioExtension, hasAudioName } from '../utils'
55

66
// TODO: use _max_threads
77
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8-
export function scanAudio(files: { fileName: string; data: Uint8Array }[], _max_threads: number) {
8+
export function scanAudio(files: { fileName: string; data: Uint8Array }[]) {
99
const folderIssues: { folderIssue: FolderIssueType; description: string }[] = []
1010

1111
const findAudioDataResult = findAudioData(files)

src/chart/chart-scanner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ function findChartData(files: { fileName: string; data: Uint8Array }[]) {
111111

112112
const chartFiles = _.chain(files)
113113
.filter(f => hasChartExtension(f.fileName))
114-
.orderBy([f => hasChartName(f.fileName), f => getExtension(f.fileName).toLowerCase() === '.mid'], ['desc', 'desc'])
114+
.orderBy([f => hasChartName(f.fileName), f => getExtension(f.fileName).toLowerCase() === 'mid'], ['desc', 'desc'])
115115
.value()
116116

117117
for (const file of chartFiles) {
118118
if (!hasChartName(file.fileName)) {
119119
folderIssues.push({
120120
folderIssue: 'invalidChart',
121-
description: `"${file.fileName}" is not named "notes${getExtension(file.fileName).toLowerCase()}".`,
121+
description: `"${file.fileName}" is not named "notes.${getExtension(file.fileName).toLowerCase()}".`,
122122
})
123123
}
124124
}
@@ -133,7 +133,7 @@ function findChartData(files: { fileName: string; data: Uint8Array }[]) {
133133
} else {
134134
return {
135135
chartData: chartFiles[0].data,
136-
format: (getExtension(chartFiles[0].fileName).toLowerCase() === '.mid' ? 'mid' : 'chart') as 'mid' | 'chart',
136+
format: (getExtension(chartFiles[0].fileName).toLowerCase() === 'mid' ? 'mid' : 'chart') as 'mid' | 'chart',
137137
folderIssues,
138138
}
139139
}

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { md5 } from 'js-md5'
22
import * as _ from 'lodash'
3-
import { cpus } from 'os'
43

54
import { scanAudio } from './audio'
65
import { scanChart } from './chart'
@@ -106,7 +105,7 @@ export function scanChartFolder(files: { fileName: string; data: Uint8Array }[])
106105
}
107106
}
108107

109-
const audioData = scanAudio(files, cpus().length - 1)
108+
const audioData = scanAudio(files)
110109
chart.folderIssues.push(...audioData.folderIssues)
111110

112111
if (!chartData.notesData || chart.folderIssues.find(i => i!.folderIssue === 'noAudio') /* TODO: || !audioData.audioHash */) {

src/utils.ts

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as _ from 'lodash'
2-
import { parse } from 'path'
32

43
declare global {
54
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -54,66 +53,59 @@ export function appearsToBeChartFolder(extensions: string[]) {
5453
}
5554

5655
/**
57-
* @returns extension of a file, including the dot. (e.g. "song.ogg" -> ".ogg")
56+
* @returns extension of a file, excluding the dot. (e.g. "song.ogg" -> "ogg")
5857
*/
5958
export function getExtension(fileName: string) {
60-
return parse(fileName).ext
59+
return _.last(fileName.split('.')) ?? ''
6160
}
6261

6362
/**
64-
*
65-
* @returns basename of a file, without the extension. (e.g. "song.ogg" -> "song")
63+
* @returns basename of a file, excluding the dot. (e.g. "song.ogg" -> "song")
6664
*/
6765
export function getBasename(fileName: string) {
68-
return parse(fileName).name
66+
const parts = fileName.split('.')
67+
return parts.length > 1 ? parts.slice(0, -1).join('.') : fileName
6968
}
7069

7170
/**
72-
* @returns `true` if `name` has a valid sng file extension.
71+
* @returns `true` if `fileName` has a valid ini file extension.
7372
*/
74-
export function hasSngExtension(name: string) {
75-
return '.sng' === getExtension(name).toLowerCase()
73+
export function hasIniExtension(fileName: string) {
74+
return 'ini' === getExtension(fileName).toLowerCase()
7675
}
7776

7877
/**
79-
* @returns `true` if `name` has a valid ini file extension.
78+
* @returns `true` if `fileName` is a valid ini fileName.
8079
*/
81-
export function hasIniExtension(name: string) {
82-
return '.ini' === getExtension(name).toLowerCase()
80+
export function hasIniName(fileName: string) {
81+
return fileName === 'song.ini'
8382
}
8483

8584
/**
86-
* @returns `true` if `name` is a valid ini fileName.
85+
* @returns `true` if `fileName` has a valid chart file extension.
8786
*/
88-
export function hasIniName(name: string) {
89-
return name === 'song.ini'
87+
export function hasChartExtension(fileName: string) {
88+
return ['chart', 'mid'].includes(getExtension(fileName).toLowerCase())
9089
}
9190

9291
/**
93-
* @returns `true` if `name` has a valid chart file extension.
92+
* @returns `true` if `fileName` is a valid chart fileName.
9493
*/
95-
export function hasChartExtension(name: string) {
96-
return ['.chart', '.mid'].includes(getExtension(name).toLowerCase())
94+
export function hasChartName(fileName: string) {
95+
return ['notes.chart', 'notes.mid'].includes(fileName)
9796
}
9897

9998
/**
100-
* @returns `true` if `name` is a valid chart fileName.
99+
* @returns `true` if `fileName` has a valid chart audio file extension.
101100
*/
102-
export function hasChartName(name: string) {
103-
return ['notes.chart', 'notes.mid'].includes(name)
101+
export function hasAudioExtension(fileName: string) {
102+
return ['ogg', 'mp3', 'wav', 'opus'].includes(getExtension(fileName).toLowerCase())
104103
}
105104

106105
/**
107-
* @returns `true` if `name` has a valid chart audio file extension.
106+
* @returns `true` if `fileName` has a valid chart audio fileName.
108107
*/
109-
export function hasAudioExtension(name: string) {
110-
return ['.ogg', '.mp3', '.wav', '.opus'].includes(getExtension(name).toLowerCase())
111-
}
112-
113-
/**
114-
* @returns `true` if `name` has a valid chart audio fileName.
115-
*/
116-
export function hasAudioName(name: string) {
108+
export function hasAudioName(fileName: string) {
117109
return (
118110
[
119111
'song',
@@ -131,29 +123,29 @@ export function hasAudioName(name: string) {
131123
'drums_4',
132124
'crowd',
133125
'preview',
134-
].includes(getBasename(name)) && ['.ogg', '.mp3', '.wav', '.opus'].includes(getExtension(name))
126+
].includes(getBasename(fileName)) && ['ogg', 'mp3', 'wav', 'opus'].includes(getExtension(fileName))
135127
)
136128
}
137129

138130
/**
139-
* @returns `true` if `name` is a valid album fileName.
131+
* @returns `true` if `fileName` is a valid album fileName.
140132
*/
141-
export function hasAlbumName(name: string) {
142-
return ['album.jpg', 'album.jpeg', 'album.png'].includes(name)
133+
export function hasAlbumName(fileName: string) {
134+
return ['album.jpg', 'album.jpeg', 'album.png'].includes(fileName)
143135
}
144136

145137
/**
146-
* @returns `true` if `name` is a valid video fileName.
138+
* @returns `true` if `fileName` is a valid video fileName.
147139
*/
148-
export function hasVideoName(name: string) {
149-
return getBasename(name) === 'video' && ['.mp4', '.avi', '.webm', '.vp8', '.ogv', '.mpeg'].includes(getExtension(name))
140+
export function hasVideoName(fileName: string) {
141+
return getBasename(fileName) === 'video' && ['mp4', 'avi', 'webm', 'vp8', 'ogv', 'mpeg'].includes(getExtension(fileName))
150142
}
151143

152144
/**
153-
* @returns `true` if `name` is a video fileName that is not supported on Linux.
145+
* @returns `true` if `fileName` is a video fileName that is not supported on Linux.
154146
*/
155-
export function hasBadVideoName(name: string) {
156-
return getBasename(name) === 'video' && ['.mp4', '.avi', '.mpeg'].includes(getExtension(name))
147+
export function hasBadVideoName(fileName: string) {
148+
return getBasename(fileName) === 'video' && ['mp4', 'avi', 'mpeg'].includes(getExtension(fileName))
157149
}
158150

159151
const allowedTags = [

0 commit comments

Comments
 (0)