-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement output file transform hook
- Loading branch information
Showing
5 changed files
with
68 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import test from 'ava'; | ||
import template from './fixture/template.js'; | ||
import { themer } from './themer.js'; | ||
import { OutputFileTransform } from './transform/index.js'; | ||
import { basename } from 'node:path'; | ||
|
||
const backupFile: OutputFileTransform = async function* (file) { | ||
yield file; | ||
yield { | ||
...file, | ||
path: `${file.path}.bak`, | ||
}; | ||
}; | ||
|
||
test('supports file post-processing', async (t) => { | ||
const files = []; | ||
for await (const file of themer( | ||
['default'], | ||
[template], | ||
{ wallpaperSizes: [] }, | ||
backupFile, | ||
)) { | ||
files.push(file); | ||
} | ||
|
||
t.plan(9); | ||
|
||
const expectedPaths = [ | ||
'Default/Test/themer-default-dark.txt', | ||
'Default/Test/themer-default-dark.txt.bak', | ||
'Default/Test/themer-default-light.txt', | ||
'Default/Test/themer-default-light.txt.bak', | ||
]; | ||
|
||
const readme = files.find((file) => file.path.endsWith('README.md')); | ||
t.assert(readme, 'No README file in output'); | ||
|
||
for (const path of expectedPaths) { | ||
t.assert( | ||
files.find((file) => file.path === path), | ||
`Output files must contain ${path}`, | ||
); | ||
const base = basename(path); | ||
t.assert(readme?.content.includes(base), `README must contain ${base}`); | ||
} | ||
}); |
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,9 @@ | ||
import { OutputFile } from '../template/index.js'; | ||
|
||
export type OutputFileTransform = ( | ||
file: OutputFile, | ||
) => AsyncGenerator<OutputFile>; | ||
|
||
export const noopTransform: OutputFileTransform = async function* (file) { | ||
yield file; | ||
}; |