Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make check-format succeed #19

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
- 22
runs-on: ${{ matrix.os }}
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test/test-bundle/dashboard
test/test-bundle/graphics
test/test-bundle/shared
14 changes: 7 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

### Contributors:

- [@zoton2](https://github.com/zoton2)
- [@Hoishin](https://github.com/Hoishin)
- [@zoton2](https://github.com/zoton2)
- [@Hoishin](https://github.com/Hoishin)

### Features:

- (BREAKING) Update vite to v4 and rollup to v3 ([#1](https://github.com/Dan-Shields/vite-plugin-nodecg/pull/1))
- (BREAKING) Support custom input <-> template matching with globbing (rollup inputs overwritten, see README)
- (BREAKING) Update vite to v4 and rollup to v3 ([#1](https://github.com/Dan-Shields/vite-plugin-nodecg/pull/1))
- (BREAKING) Support custom input <-> template matching with globbing (rollup inputs overwritten, see README)

### Fixes:

- Support recursive css assets ([#3](https://github.com/dan-shields/vite-plugin-nodecg/issues/3))
- Read host & port of dev server directly from the server itself so are always correct ([#4](https://github.com/dan-shields/vite-plugin-nodecg/issues/4))
- Remove cheerio as dependency ([#10](https://github.com/dan-shields/vite-plugin-nodecg/pull/4))
- Support recursive css assets ([#3](https://github.com/dan-shields/vite-plugin-nodecg/issues/3))
- Read host & port of dev server directly from the server itself so are always correct ([#4](https://github.com/dan-shields/vite-plugin-nodecg/issues/4))
- Remove cheerio as dependency ([#10](https://github.com/dan-shields/vite-plugin-nodecg/pull/4))
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ When determining which input to use, `vite-plugin-nodecg` will iterate top to bo

### Source directory & file structure

`<bundle-dir>/src` is the default base path for any input files found inside, such that the input's path relative to it is reflected in the output directory of the .html file, e.g. the input `<bundle-dir>/src/graphics/graphic1/main.js` will html file output to `<bundle-dir>/graphics/graphic1/main.html`. Any inputs inside who's first sub-directory relative to `<bundle-dir>/src` is _not_ `graphics` or `dsahboard`, will not be picked up by NodeCG and (probably) pointless.
`<bundle-dir>/src` is the default base path for any input files found inside, such that the input's path relative to it is reflected in the output directory of the .html file, e.g. the input `<bundle-dir>/src/graphics/graphic1/main.js` will html file output to `<bundle-dir>/graphics/graphic1/main.html`. Any inputs inside who's first sub-directory relative to `<bundle-dir>/src` is _not_ `graphics` or `dsahboard`, will not be picked up by NodeCG and (probably) pointless.

If you want `vite-plugin-nodecg` to look in a different directory to `./src` for your input files, specify this using the `srcDir` config option.

Expand All @@ -69,7 +69,8 @@ export default defineConfig(() => {
plugins: [
NodeCGPlugin({
inputs: {
'graphics/special_graphic/main.js': './templates/special_template.html',
'graphics/special_graphic/main.js':
'./templates/special_template.html',
'graphics/*/main.js': './templates/graphics.html',
'dashboard/*/main.js': './templates/dashboard.html',
},
Expand All @@ -95,18 +96,19 @@ export default defineConfig(() => {

### To manually test:

- ensure the latest version of the plugin has been built locally and exists in `/dist`
- clear out the `dashboard`, `graphics` and `shared` directories from the `test/test-bundle`
- run `pnpm build` in `test-bundle` and examine the built files
- the new files should be identical to the committed ones
- for development, run `pnpm dev` and for now a manual review of the built files is required
- ensure the latest version of the plugin has been built locally and exists in `/dist`
- clear out the `dashboard`, `graphics` and `shared` directories from the `test/test-bundle`
- run `pnpm build` in `test-bundle` and examine the built files
- the new files should be identical to the committed ones
- for development, run `pnpm dev` and for now a manual review of the built files is required

## Todo

- ~~Write tests~~ Automate the diff-test and consider unit tests. See [#9](https://github.com/Dan-Shields/vite-plugin-nodecg/issues/9)
- ~~Investigate other template setup possibilties~~ (see [#2](https://github.com/Dan-Shields/vite-plugin-nodecg/issues/2))
- ~~Write tests~~ Automate the diff-test and consider unit tests. See [#9](https://github.com/Dan-Shields/vite-plugin-nodecg/issues/9)
- ~~Investigate other template setup possibilties~~ (see [#2](https://github.com/Dan-Shields/vite-plugin-nodecg/issues/2))

## Acknowledgements

- [Dan Shields](https://github.com/Dan-Shields) - Author and Maintainer
- [Keiichiro "Hoishin" Amemiya](https://twitter.com/hoishinxii) - Contributor
- [zoton2](https://github.com/zoton2) - Contributor
38 changes: 19 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {

const inputPatterns = [
...Object.keys(inputConfig).map((matchPath) =>
path.posix.join(srcDir, matchPath)
path.posix.join(srcDir, matchPath),
),
'!**.d.ts',
]
Expand All @@ -61,7 +61,7 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
Object.keys(inputConfig).forEach((matchPath) => {
if (
!inputs.some((input) =>
minimatch(input, path.posix.join(srcDir, matchPath))
minimatch(input, path.posix.join(srcDir, matchPath)),
)
)
delete inputConfig[matchPath]
Expand Down Expand Up @@ -92,32 +92,32 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
dSrvHost,
'bundles',
bundleName,
'@vite/client'
)}"></script>`
'@vite/client',
)}"></script>`,
)
tags.push(
`<script type="module" src="${dSrvProtocol}://${path.posix.join(
dSrvHost,
'bundles',
bundleName,
entry
)}"></script>`
entry,
)}"></script>`,
)
} else if (config.mode === 'production' && assetManifest) {
let entryChunk = assetManifest[entry]

function generateCssTags(
chunk: ManifestChunk,
alreadyProcessed: string[] = []
alreadyProcessed: string[] = [],
) {
chunk.css?.forEach((cssPath) => {
if (alreadyProcessed.includes(cssPath)) return // de-dupe assets

tags.push(
`<link rel="stylesheet" href="${path.posix.join(
config.base,
cssPath
)}" />`
cssPath,
)}" />`,
)

alreadyProcessed.push(cssPath)
Expand All @@ -134,8 +134,8 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
tags.push(
`<script type="module" src="${path.posix.join(
config.base,
entryChunk.file
)}"></script>`
entryChunk.file,
)}"></script>`,
)
}

Expand Down Expand Up @@ -174,15 +174,15 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
// check template was found in the inputConfig and we loaded it from disk, otherwise skip this input
if (!template) {
console.error(
`vite-plugin-nodecg: No template found to match input "${inputPath}". This probably means the input file was manually specified in the vite rollup config, and the graphic/dashboard will not be built.`
`vite-plugin-nodecg: No template found to match input "${inputPath}". This probably means the input file was manually specified in the vite rollup config, and the graphic/dashboard will not be built.`,
)
return
}

// add asset tags to template
const html = injectAssetsTags(
templates[templatePath],
inputPath.replace(/^(\.\/)/, '')
inputPath.replace(/^(\.\/)/, ''),
)

const buildDir = path.dirname(path.relative(srcDir, inputPath))
Expand All @@ -201,14 +201,14 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
fs.mkdirSync(dir, { recursive: true })
} catch (e) {
console.error(
`vite-plugin-nodecg: Could not create directory ${dir} for input ${filePath}. Skipping...`
`vite-plugin-nodecg: Could not create directory ${dir} for input ${filePath}. Skipping...`,
)
continue
}

fs.writeFile(fullFilePath, htmlDoc, () => {
console.log(
`vite-plugin-nodecg: Wrote input ${filePath} to disk`
`vite-plugin-nodecg: Wrote input ${filePath} to disk`,
)
})
}
Expand Down Expand Up @@ -256,14 +256,14 @@ export default function viteNodeCGPlugin(pluginConfig: PluginConfig): Plugin {
path.posix.join(
process.cwd(),
config.build.outDir,
'manifest.json'
)
'manifest.json',
),
)
.toString()
.toString(),
)
} catch (err) {
console.error(
"vite-plugin-nodecg: Failed to load manifest.json from build directory. HTML files won't be generated."
"vite-plugin-nodecg: Failed to load manifest.json from build directory. HTML files won't be generated.",
)
return
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"devDependencies": {
"@types/node": "^20.11.25",
"prettier": "^3.4.2",
"rollup": "^4.12.1",
"typescript": "^5.4.2",
"vite": "^5.1.5"
Expand Down
Loading
Loading