-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add watch support for GLSL files (#22)
Monitor for new GLSL files and changes to existing ones so that their corresponding shader programs can be re-generated
- Loading branch information
1 parent
e391ebd
commit ec4c19e
Showing
5 changed files
with
64 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Builds all .glsl files under <shaderPath>. | ||
* @param shaderPath - The path to the shaders to watch | ||
* @param importPath - The path to import the converted shaders | ||
* @example node buildShaders.js <shaderPath> <importPath> | ||
*/ | ||
|
||
import { convertShaders } from "./shaderConverter.js"; | ||
|
||
const externalArguments = process.argv.slice(2); | ||
if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1]) { | ||
convertShaders(externalArguments[0], externalArguments[1]); | ||
} |
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,40 @@ | ||
/* eslint-disable no-console */ | ||
/** | ||
* Watches all .glsl files under <shaderPath> and rebuilds them when changed. | ||
* @param shaderPath - The path to the shaders to watch | ||
* @param importPath - The path to import the converted shaders | ||
* @example node watchShaders.js <shaderPath> <importPath> | ||
*/ | ||
|
||
import { convertShader } from "./shaderConverter.js"; | ||
import { watch } from "chokidar"; | ||
import { extname } from "path"; | ||
|
||
const externalArguments = process.argv.slice(2); | ||
if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1]) { | ||
const shaderPath = externalArguments[0]; | ||
const importPath = externalArguments[1]; | ||
|
||
watch(shaderPath).on("all", (event, file) => { | ||
// Only process file changes and added files | ||
if (event !== "change" && event !== "add") { | ||
return; | ||
} | ||
|
||
// Only process .glsl files | ||
if (extname(file) !== ".glsl") { | ||
return; | ||
} | ||
|
||
// Wrap in try-catch to prevent the watcher from crashing | ||
// if the new shader changes are invalid | ||
try { | ||
convertShader(file, importPath); | ||
console.log(`Successfully updated shader ${file}`); | ||
} catch (error) { | ||
console.error(`Failed to convert shader ${file}: ${error}`); | ||
} | ||
}); | ||
|
||
console.log(`Watching for shader changes in ${shaderPath}`); | ||
} |
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