-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup yarn workspace for AE design patterns mock form app (#33506)
* add package.json for using yarn workspaces * fix: get workspace working by adding package path to root package.json * fix: remove comma * add nodemon package to workspace * test node script to nuke all the node_modules with a fancy spinner lol * jsdoc comments
- Loading branch information
1 parent
9548fe8
commit 20acea2
Showing
5 changed files
with
1,060 additions
and
264 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
29 changes: 29 additions & 0 deletions
29
src/applications/_mock-form-ae-design-patterns/package.json
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,29 @@ | ||
{ | ||
"name": "@department-of-veterans-affairs/applications-mock-form-ae-design-patterns", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"demo": "echo DEMOING $npm_package_name v $npm_package_version with WORKSPACES" | ||
}, | ||
"licence": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@testing-library/dom": "^7.26.6", | ||
"@testing-library/react": "^11.1.2", | ||
"chai": "^4.3.4", | ||
"mockdate": "^3.0.5", | ||
"mocker-api": "^2.9.0", | ||
"nodemon": "^3.1.7", | ||
"sinon": "^3.2.1" | ||
}, | ||
"peerDependencies": { | ||
"lodash": "*", | ||
"prop-types": "*", | ||
"react": "*", | ||
"react-redux": "*", | ||
"react-router": "*", | ||
"react-router-dom": "*", | ||
"redux": "*", | ||
"redux-mock-store": "*" | ||
}, | ||
"private": true | ||
} |
99 changes: 99 additions & 0 deletions
99
src/applications/_mock-form-ae-design-patterns/script/nuke-node-modules.js
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,99 @@ | ||
// disabling rule since this is run in node and not in browser | ||
/* eslint-disable no-console */ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const readline = require('readline'); | ||
const createSpinner = require('./spinner'); | ||
|
||
/** | ||
* find all node_modules directories in a directory | ||
* @param {string} dir - directory to search for node_modules | ||
* @returns {string[]} array of paths to node_modules directories that were found | ||
*/ | ||
const findNodeModules = dir => { | ||
try { | ||
const results = []; | ||
const items = fs.readdirSync(dir); | ||
|
||
for (const item of items) { | ||
const fullPath = path.join(dir, item); | ||
const stat = fs.statSync(fullPath); | ||
|
||
if (stat.isDirectory()) { | ||
if (item === 'node_modules') { | ||
results.push(fullPath); | ||
} else if (!fullPath.includes('node_modules')) { | ||
// Don't search inside other node_modules directories | ||
results.push(...findNodeModules(fullPath)); | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} catch (err) { | ||
console.error(`Error searching directory ${dir}:`, err); | ||
return []; | ||
} | ||
}; | ||
|
||
/** | ||
* confirm deletion of node_modules directories | ||
* @param {string[]} folders - array of paths to node_modules directories | ||
* @returns {Promise<boolean>} resolves to true if confirmed deletion, false otherwise | ||
*/ | ||
const confirmDeletion = async folders => { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
console.log('Found these node_modules folders:'); | ||
folders.forEach(folder => console.log(folder)); | ||
|
||
return new Promise(resolve => { | ||
rl.question( | ||
'Are you sure you want to delete these directories? (Y/N) ', | ||
answer => { | ||
rl.close(); | ||
resolve(answer.toLowerCase() === 'y'); | ||
}, | ||
); | ||
}); | ||
}; | ||
|
||
/** | ||
* delete all node_modules directories in a directory | ||
* @param {string} startDir - directory to search for node_modules | ||
*/ | ||
const deleteNodeModules = async (startDir = '.') => { | ||
try { | ||
const foundDirs = findNodeModules(startDir); | ||
|
||
if (foundDirs.length === 0) { | ||
console.log('No node_modules directories found.'); | ||
return; | ||
} | ||
|
||
const confirmed = await confirmDeletion(foundDirs); | ||
|
||
if (confirmed) { | ||
const spinner = createSpinner('Deleting node_modules directories...'); | ||
await Promise.all( | ||
foundDirs.map(dir => { | ||
console.log(`Deleted ${dir}`); | ||
return fs.remove(dir); | ||
}), | ||
); | ||
spinner.stop('Deletion complete.'); | ||
} else { | ||
console.log('Operation cancelled.'); | ||
} | ||
} catch (err) { | ||
console.error('Error:', err); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
// Get directory from command line argument or use current directory | ||
const targetDir = process.argv[2] || '.'; | ||
deleteNodeModules(targetDir); |
22 changes: 22 additions & 0 deletions
22
src/applications/_mock-form-ae-design-patterns/script/spinner.js
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,22 @@ | ||
/* eslint-disable no-console */ | ||
const createSpinner = message => { | ||
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; | ||
let i = 0; | ||
|
||
process.stdout.write('\x1B[?25l'); // Hide cursor | ||
const spinner = setInterval(() => { | ||
process.stdout.write(`\r${frames[i]} ${message}`); | ||
i = (i + 1) % frames.length; | ||
}, 80); | ||
|
||
return { | ||
stop: endMessage => { | ||
clearInterval(spinner); | ||
process.stdout.write('\r\x1B[K'); // Clear line | ||
process.stdout.write('\x1B[?25h'); // Show cursor | ||
if (endMessage) console.log(endMessage); | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = createSpinner; |
Oops, something went wrong.