Skip to content

Commit

Permalink
Feat: Add script to run examples using args
Browse files Browse the repository at this point in the history
  • Loading branch information
sandypockets committed Dec 16, 2023
1 parent 05c9d70 commit ed8182d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"build": "webpack",
"prep": "yarn prettier . --write && yarn build",
"test": "jest"
"test": "jest",
"example": "node ./scripts/runExample.js"
},
"jest": {
"testEnvironment": "node",
Expand Down
21 changes: 21 additions & 0 deletions scripts/runExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { execSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const argument = process.argv[2];

if (!argument) {
console.error('Error: No argument provided.');
process.exit(1);
}

const command = `cd examples && cd ${argument} && npm run dev`;

try {
execSync(command, { stdio: 'inherit', cwd: path.resolve(__dirname, '..') });
} catch (error) {
console.error('Failed to execute the command:', error);
}

0 comments on commit ed8182d

Please sign in to comment.