-
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.
Support loading external color sets and templates
- Loading branch information
Showing
5 changed files
with
231 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import test from 'ava'; | ||
import flattenDeep from 'lodash/flattenDeep.js'; | ||
import { spawn } from 'node:child_process'; | ||
import { rm, stat } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
import type { BuiltInColorSet, BuiltInTemplate } from './index.js'; | ||
|
||
const TEST_OUTPUT_DIR = 'bin-test'; | ||
|
||
test.afterEach.always('clean up test output', async () => { | ||
await rm(TEST_OUTPUT_DIR, { force: true, recursive: true }); | ||
}); | ||
|
||
async function run( | ||
colorSetParams: (BuiltInColorSet | string)[], | ||
templateParams: (BuiltInTemplate | string)[], | ||
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const cp = spawn( | ||
'node', | ||
flattenDeep([ | ||
'./dist/bin.js', | ||
colorSetParams.map((param) => ['--color-set', param]), | ||
...templateParams.map((param) => ['--template', param]), | ||
['--output', TEST_OUTPUT_DIR], | ||
]), | ||
); | ||
cp.on('error', reject); | ||
cp.on('exit', (code) => { | ||
if (code === 0) resolve(); | ||
else reject(); | ||
}); | ||
}); | ||
} | ||
|
||
test.serial('basic CLI', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run(['default'], ['slack']); | ||
await stat( | ||
join( | ||
TEST_OUTPUT_DIR, | ||
'Default', | ||
'Slack sidebar', | ||
'themer-default-dark.txt', | ||
), | ||
); | ||
await stat(join(TEST_OUTPUT_DIR, 'Default', 'README.md')); | ||
}); | ||
}); | ||
|
||
test.serial('multiple color sets', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run(['default', 'green-as-a-whistle'], ['slack']); | ||
await stat(join(TEST_OUTPUT_DIR, 'Default', 'README.md')); | ||
await stat(join(TEST_OUTPUT_DIR, 'Green as a Whistle', 'README.md')); | ||
}); | ||
}); | ||
|
||
test.serial('multiple templates', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run(['default'], ['slack', 'alfred']); | ||
await stat( | ||
join( | ||
TEST_OUTPUT_DIR, | ||
'Default', | ||
'Slack sidebar', | ||
'themer-default-dark.txt', | ||
), | ||
); | ||
await stat( | ||
join( | ||
TEST_OUTPUT_DIR, | ||
'Default', | ||
'Alfred', | ||
'themer-default-dark.alfredappearance', | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
test.serial('load color set from file', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run([join('dist', 'fixture', 'color-set.js')], ['slack']); | ||
await stat( | ||
join(TEST_OUTPUT_DIR, 'Test', 'Slack sidebar', 'themer-test-dark.txt'), | ||
); | ||
}); | ||
}); | ||
|
||
test.serial('load template from file', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run(['default'], [join('dist', 'fixture', 'template.js')]); | ||
await stat( | ||
join(TEST_OUTPUT_DIR, 'Default', 'Test', 'themer-default-dark.txt'), | ||
); | ||
}); | ||
}); | ||
|
||
test.serial.only('load base16 file', async (t) => { | ||
await t.notThrowsAsync(async () => { | ||
await run([join('src', 'fixture', 'base16.yaml')], ['slack']); | ||
await stat( | ||
join( | ||
TEST_OUTPUT_DIR, | ||
'base16', | ||
'Slack sidebar', | ||
'themer-base-16-dark.txt', | ||
), | ||
); | ||
}); | ||
}); |
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,18 @@ | ||
scheme: 'base16' | ||
author: 'Themer (https://themer.dev)' | ||
base00: '000000' | ||
base01: 'ffffff' | ||
base02: 'ffffff' | ||
base03: 'ffffff' | ||
base04: 'ffffff' | ||
base05: 'ffffff' | ||
base06: 'ffffff' | ||
base07: 'ffffff' | ||
base08: 'ffffff' | ||
base09: 'ffffff' | ||
base0A: 'ffffff' | ||
base0B: 'ffffff' | ||
base0C: 'ffffff' | ||
base0D: 'ffffff' | ||
base0E: 'ffffff' | ||
base0F: 'ffffff' |
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,21 @@ | ||
import type { ColorSet } from '../color-set'; | ||
|
||
const colors: ColorSet = { | ||
name: 'Test', | ||
variants: { | ||
dark: { | ||
shade0: '#000000', | ||
shade7: '#ffffff', | ||
accent0: '#ffffff', | ||
accent1: '#ffffff', | ||
accent2: '#ffffff', | ||
accent3: '#ffffff', | ||
accent4: '#ffffff', | ||
accent5: '#ffffff', | ||
accent6: '#ffffff', | ||
accent7: '#ffffff', | ||
}, | ||
}, | ||
}; | ||
|
||
export default colors; |
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,15 @@ | ||
import type { Template } from '../index.js'; | ||
import { colorSetToVariants } from '../color-set/index.js'; | ||
|
||
const template: Template = { | ||
name: 'Test', | ||
render: async function* (colorSet) { | ||
yield* colorSetToVariants(colorSet).map(({ title }) => ({ | ||
path: `${title.kebab}.txt`, | ||
content: Buffer.from(title.human, 'utf8'), | ||
})); | ||
}, | ||
renderInstructions: (paths) => paths.join('\n'), | ||
}; | ||
|
||
export default template; |