wad-lab 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/index.js +52 -37
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -46,55 +46,70 @@ function renderMenu() {
46
46
  console.log('\nPress Ctrl+C to cancel.');
47
47
  }
48
48
 
49
- function unpack(choice) {
50
- const destDir = process.cwd();
51
-
52
- if (choice === 'all') {
53
- fs.cpSync(templatesRoot, destDir, { recursive: true });
54
- console.log('\nSuccessfully unpacked ALL templates into: ' + destDir);
55
- } else {
56
- const src = path.join(templatesRoot, choice);
57
- const dest = path.join(destDir, choice);
58
- fs.cpSync(src, dest, { recursive: true });
59
- console.log('\nSuccessfully unpacked [' + choice + '] into: ' + dest);
49
+ function promptFolderName(choice) {
50
+ if (process.stdin.isTTY) {
51
+ process.stdin.setRawMode(false);
60
52
  }
61
- process.exit(0);
53
+
54
+ const defaultFolder = choice === 'all' ? 'wad-all-templates' : choice;
55
+ const rl = readline.createInterface({
56
+ input: process.stdin,
57
+ output: process.stdout
58
+ });
59
+
60
+ console.log('\nSelected: ' + choice);
61
+ rl.question(`Enter destination folder name (default: "${defaultFolder}"): `, (answer) => {
62
+ rl.close();
63
+ const folder = answer.trim() || defaultFolder;
64
+ const dest = path.resolve(process.cwd(), folder);
65
+
66
+ if (!fs.existsSync(dest)) {
67
+ fs.mkdirSync(dest, { recursive: true });
68
+ }
69
+
70
+ if (choice === 'all') {
71
+ fs.cpSync(templatesRoot, dest, { recursive: true });
72
+ console.log('\nSuccessfully unpacked ALL templates into: ' + dest);
73
+ } else {
74
+ const src = path.join(templatesRoot, choice);
75
+ fs.cpSync(src, dest, { recursive: true });
76
+ console.log('\nSuccessfully unpacked [' + choice + '] into: ' + dest);
77
+ }
78
+ process.exit(0);
79
+ });
62
80
  }
63
81
 
64
82
  if (process.argv[2]) {
65
83
  const arg = process.argv[2];
66
84
  const found = templates.find(t => t.value === arg);
67
85
  if (found) {
68
- unpack(found.value);
86
+ promptFolderName(found.value);
69
87
  } else {
70
88
  console.error('Unknown template: ' + arg);
71
89
  process.exit(1);
72
90
  }
73
- }
74
-
75
- readline.emitKeypressEvents(process.stdin);
76
- if (process.stdin.isTTY) {
77
- process.stdin.setRawMode(true);
78
- }
91
+ } else {
92
+ readline.emitKeypressEvents(process.stdin);
93
+ if (process.stdin.isTTY) {
94
+ process.stdin.setRawMode(true);
95
+ }
79
96
 
80
- renderMenu();
97
+ renderMenu();
81
98
 
82
- process.stdin.on('keypress', (str, key) => {
83
- if (key.ctrl && key.name === 'c') {
84
- process.exit(0);
85
- }
99
+ process.stdin.on('keypress', (str, key) => {
100
+ if (key.ctrl && key.name === 'c') {
101
+ process.exit(0);
102
+ }
86
103
 
87
- if (key.name === 'up') {
88
- selectedIndex = (selectedIndex - 1 + templates.length) % templates.length;
89
- renderMenu();
90
- } else if (key.name === 'down') {
91
- selectedIndex = (selectedIndex + 1) % templates.length;
92
- renderMenu();
93
- } else if (key.name === 'return' || key.name === 'enter') {
94
- if (process.stdin.isTTY) {
95
- process.stdin.setRawMode(false);
104
+ if (key.name === 'up') {
105
+ selectedIndex = (selectedIndex - 1 + templates.length) % templates.length;
106
+ renderMenu();
107
+ } else if (key.name === 'down') {
108
+ selectedIndex = (selectedIndex + 1) % templates.length;
109
+ renderMenu();
110
+ } else if (key.name === 'return' || key.name === 'enter') {
111
+ const chosen = templates[selectedIndex].value;
112
+ promptFolderName(chosen);
96
113
  }
97
- const chosen = templates[selectedIndex].value;
98
- unpack(chosen);
99
- }
100
- });
114
+ });
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wad-lab",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Interactive CLI for WAD Lab starter templates (Spring Boot, MongoDB, Vue 3, Servlets)",
5
5
  "bin": {
6
6
  "wad-lab": "./bin/index.js"