Skip to content

Commit e48e6b7

Browse files
committed
removing plugin from script dir
1 parent c785442 commit e48e6b7

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

scripts/prependDirectivePlugin.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

tsup.config.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint @stylistic/quote-props: ["error", "consistent"] */
22

33
import { defineConfig, Options } from 'tsup'
4-
import { prependDirective } from './scripts/prependDirectivePlugin.ts'
4+
import { readFileSync, writeFileSync } from 'fs'
55
import { ExpectedBuildOutput, validateBuildFiles } from './scripts/validateBuild.ts'
66

77
const expectedBuildOutput: ExpectedBuildOutput = {
@@ -104,3 +104,25 @@ process.on('beforeExit', (code) => {
104104
validateBuildFiles(expectedBuildOutput)
105105
console.log('[POST-BUILD] Validation successful! Build complete.')
106106
})
107+
108+
function prependDirective(directive: string, filePatterns: string[]): NonNullable<Options['plugins']>[number] {
109+
if (!Array.isArray(filePatterns)) {
110+
throw Error('FilePatterns given to prependDirective plugin must be an array.')
111+
}
112+
return {
113+
name: 'prepend-directive',
114+
// At the end of the build step, directly prepend the specified directive to files with specified pattern
115+
116+
buildEnd(ctx) {
117+
for (const file of ctx.writtenFiles) {
118+
for (const filePattern of filePatterns) {
119+
if (file.name.startsWith(filePattern)) {
120+
const fileContent = readFileSync(file.name, 'utf8')
121+
writeFileSync(file.name, `${directive};${fileContent}`)
122+
console.log(`Prepended ${directive} directive to ${file.name}`)
123+
}
124+
}
125+
}
126+
},
127+
}
128+
}

0 commit comments

Comments
 (0)