setup-tea-party 0.0.0-stage → 1.1.0
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.
- package/README.md +31 -2
- package/bin/setup-tea-party.js +16 -0
- package/package.json +40 -4
- package/src/args.js +119 -0
- package/src/cli.js +73 -0
- package/src/prompts.js +194 -0
- package/src/scaffold.js +42 -0
- package/src/templates.js +569 -0
- package/src/ui.js +30 -0
- package/templates/wrapper/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/templates/wrapper/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/templates/wrapper/gradlew +248 -0
- package/templates/wrapper/gradlew.bat +82 -0
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# setup-tea-party
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffold a [solaire-core](https://github.com/FerdaKoplo/solaire-core) (`io.github.ferdakoplo:solaire-core`) web app powered by **TeaVM**, **Vite**, and **Tailwind CSS v4**.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx setup-tea-party my-app
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or non-interactively with flags:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx setup-tea-party my-app --package com.example.myapp --theme tea --yes
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Options
|
|
18
|
+
|
|
19
|
+
- `-p, --package <pkg>`: Java base package (default: `com.example.<project>`)
|
|
20
|
+
- `-t, --theme <tea|tailwind|css>`: `Classnames` preset (`tea`, `tailwind`, or `css`)
|
|
21
|
+
- `--solaire-version <version>`: `solaire-core` Maven version (default: `1.4.1`)
|
|
22
|
+
- `-y, --yes`: Accept defaults without prompting
|
|
23
|
+
- `-f, --force`: Scaffold into a non-empty directory
|
|
24
|
+
- `-h, --help`: Show usage
|
|
25
|
+
- `-v, --version`: Show CLI version
|
|
26
|
+
|
|
27
|
+
## What it creates
|
|
28
|
+
|
|
29
|
+
- Gradle project (`build.gradle`, `settings.gradle`, and bundled `./gradlew` wrapper) configured with `org.teavm` `0.15.0` (`ES2015` output) and `io.github.ferdakoplo:solaire-core`
|
|
30
|
+
- Starter `App.java` + `Main.java` using `JReact.mount`, `AppShell`, `Ui`, and `Classnames`
|
|
31
|
+
- JVM unit test (`AppTest.java`) using `Renderer.RenderScope` + JUnit 5
|
|
32
|
+
- Vite dev/build setup (`package.json`, `vite.config.js`, `index.html`, `src/main/web/main.js`, `src/main/web/style.css`)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { run } from '../src/cli.js';
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const code = await run(process.argv.slice(2));
|
|
7
|
+
process.exitCode = code;
|
|
8
|
+
} catch (err) {
|
|
9
|
+
if (err?.name === 'AbortError') {
|
|
10
|
+
console.error('\nAborted.');
|
|
11
|
+
process.exitCode = 130;
|
|
12
|
+
} else {
|
|
13
|
+
console.error(`Error: ${err?.message ?? String(err)}`);
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "setup-tea-party",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Scaffold a solaire-core (jreact) TeaVM + Vite + Tailwind web application",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"setup-tea-party": "bin/setup-tea-party.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"templates",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "node --test test/*.test.js"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"solaire-core",
|
|
20
|
+
"jreact",
|
|
21
|
+
"teavm",
|
|
22
|
+
"vite",
|
|
23
|
+
"tailwind",
|
|
24
|
+
"tea-party",
|
|
25
|
+
"create",
|
|
26
|
+
"cli"
|
|
27
|
+
],
|
|
28
|
+
"author": "FerdaKoplo",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://github.com/FerdaKoplo/solaire-core/tree/main/setup-tea-party",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/FerdaKoplo/solaire-core.git",
|
|
34
|
+
"directory": "setup-tea-party"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/FerdaKoplo/solaire-core/issues"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/args.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** Valid UI styling themes supported by solaire-core Classnames. */
|
|
2
|
+
export const THEMES = ['tea', 'tailwind', 'css'];
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_PROJECT_NAME = 'my-tea-party';
|
|
5
|
+
export const DEFAULT_THEME = 'tea';
|
|
6
|
+
export const DEFAULT_SOLAIRE_VERSION = '1.4.1';
|
|
7
|
+
|
|
8
|
+
const JAVA_KEYWORDS = new Set([
|
|
9
|
+
'abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch', 'char',
|
|
10
|
+
'class', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum',
|
|
11
|
+
'extends', 'final', 'finally', 'float', 'for', 'goto', 'if', 'implements',
|
|
12
|
+
'import', 'instanceof', 'int', 'interface', 'long', 'native', 'new',
|
|
13
|
+
'package', 'private', 'protected', 'public', 'return', 'short', 'static',
|
|
14
|
+
'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
|
|
15
|
+
'transient', 'try', 'void', 'volatile', 'while', '_',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const PACKAGE_SEGMENT_RE = /^[a-z_][a-z0-9_]*$/;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parse CLI arguments into an options object.
|
|
22
|
+
* Throws an Error on invalid flags or missing option values.
|
|
23
|
+
*/
|
|
24
|
+
export function parseArgs(argv) {
|
|
25
|
+
const opts = {
|
|
26
|
+
targetDir: null,
|
|
27
|
+
packageName: null,
|
|
28
|
+
theme: null,
|
|
29
|
+
solaireVersion: DEFAULT_SOLAIRE_VERSION,
|
|
30
|
+
yes: false,
|
|
31
|
+
force: false,
|
|
32
|
+
help: false,
|
|
33
|
+
version: false,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < argv.length; i++) {
|
|
37
|
+
const arg = argv[i];
|
|
38
|
+
if (arg === '-h' || arg === '--help') {
|
|
39
|
+
opts.help = true;
|
|
40
|
+
} else if (arg === '-v' || arg === '--version') {
|
|
41
|
+
opts.version = true;
|
|
42
|
+
} else if (arg === '-y' || arg === '--yes') {
|
|
43
|
+
opts.yes = true;
|
|
44
|
+
} else if (arg === '-f' || arg === '--force') {
|
|
45
|
+
opts.force = true;
|
|
46
|
+
} else if (arg === '-p' || arg === '--package') {
|
|
47
|
+
opts.packageName = requireValue(argv, ++i, arg);
|
|
48
|
+
} else if (arg.startsWith('--package=')) {
|
|
49
|
+
opts.packageName = arg.slice('--package='.length);
|
|
50
|
+
} else if (arg === '-t' || arg === '--theme') {
|
|
51
|
+
opts.theme = requireValue(argv, ++i, arg);
|
|
52
|
+
} else if (arg.startsWith('--theme=')) {
|
|
53
|
+
opts.theme = arg.slice('--theme='.length);
|
|
54
|
+
} else if (arg === '--solaire-version') {
|
|
55
|
+
opts.solaireVersion = requireValue(argv, ++i, arg);
|
|
56
|
+
} else if (arg.startsWith('--solaire-version=')) {
|
|
57
|
+
opts.solaireVersion = arg.slice('--solaire-version='.length);
|
|
58
|
+
} else if (arg.startsWith('-')) {
|
|
59
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
60
|
+
} else if (opts.targetDir === null) {
|
|
61
|
+
opts.targetDir = arg;
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error(`Unexpected extra argument: ${arg}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (opts.theme !== null && !THEMES.includes(opts.theme)) {
|
|
68
|
+
throw new Error(`Invalid theme "${opts.theme}". Expected one of: ${THEMES.join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
if (opts.packageName !== null) {
|
|
71
|
+
validatePackageName(opts.packageName);
|
|
72
|
+
}
|
|
73
|
+
return opts;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function requireValue(argv, index, flag) {
|
|
77
|
+
if (index >= argv.length || argv[index].startsWith('-')) {
|
|
78
|
+
throw new Error(`Missing value for ${flag}`);
|
|
79
|
+
}
|
|
80
|
+
return argv[index];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Validate a Java package name (e.g. "com.example.myapp"). */
|
|
84
|
+
export function validatePackageName(pkg) {
|
|
85
|
+
if (!pkg || typeof pkg !== 'string') {
|
|
86
|
+
throw new Error('Java package name cannot be empty.');
|
|
87
|
+
}
|
|
88
|
+
const segments = pkg.split('.');
|
|
89
|
+
for (const seg of segments) {
|
|
90
|
+
if (!PACKAGE_SEGMENT_RE.test(seg) || JAVA_KEYWORDS.has(seg)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Invalid Java package segment "${seg}" in "${pkg}". Use lowercase identifiers (e.g. com.example.teaparty).`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return pkg;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Derive a valid Java base package name from a project directory name. */
|
|
100
|
+
export function toDefaultPackage(projectName) {
|
|
101
|
+
const cleaned = String(projectName || '')
|
|
102
|
+
.toLowerCase()
|
|
103
|
+
.replace(/[^a-z0-9]/g, '');
|
|
104
|
+
let leaf = cleaned || 'teaparty';
|
|
105
|
+
if (/^[0-9]/.test(leaf) || JAVA_KEYWORDS.has(leaf)) {
|
|
106
|
+
leaf = `app${leaf}`;
|
|
107
|
+
}
|
|
108
|
+
return `com.example.${leaf}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Derive a human-readable app title from a project directory name. */
|
|
112
|
+
export function toAppTitle(projectName) {
|
|
113
|
+
const words = String(projectName || 'Tea Party')
|
|
114
|
+
.trim()
|
|
115
|
+
.split(/[-_\s]+/)
|
|
116
|
+
.filter(Boolean);
|
|
117
|
+
if (words.length === 0) return 'Tea Party';
|
|
118
|
+
return words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
119
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { stdout } from 'node:process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { DEFAULT_SOLAIRE_VERSION, THEMES, parseArgs } from './args.js';
|
|
6
|
+
import { resolveConfig } from './prompts.js';
|
|
7
|
+
import { scaffoldProject } from './scaffold.js';
|
|
8
|
+
import { c, printBanner } from './ui.js';
|
|
9
|
+
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
/** Print CLI usage help. */
|
|
13
|
+
export function formatHelp() {
|
|
14
|
+
return `Usage: setup-tea-party [project-name] [options]
|
|
15
|
+
|
|
16
|
+
Scaffold a solaire-core (jreact) TeaVM + Vite web application.
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
-p, --package <pkg> Java base package (e.g. com.example.teaparty)
|
|
20
|
+
-t, --theme <theme> UI theme preset: ${THEMES.join(' | ')} (default: tea)
|
|
21
|
+
--solaire-version <v> solaire-core Maven version (default: ${DEFAULT_SOLAIRE_VERSION})
|
|
22
|
+
-y, --yes Skip prompts and use defaults
|
|
23
|
+
-f, --force Allow writing into a non-empty directory
|
|
24
|
+
-h, --help Show this help message
|
|
25
|
+
-v, --version Show CLI version
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function readCliVersion() {
|
|
30
|
+
const pkgRaw = await readFile(path.resolve(__dirname, '../package.json'), 'utf8');
|
|
31
|
+
return JSON.parse(pkgRaw).version;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Run the setup-tea-party CLI. Returns an integer exit code. */
|
|
35
|
+
export async function run(argv) {
|
|
36
|
+
const opts = parseArgs(argv);
|
|
37
|
+
|
|
38
|
+
if (opts.help) {
|
|
39
|
+
console.log(formatHelp());
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const version = await readCliVersion();
|
|
44
|
+
|
|
45
|
+
if (opts.version) {
|
|
46
|
+
console.log(version);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (stdout.isTTY && !opts.yes) {
|
|
51
|
+
printBanner(version);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const config = await resolveConfig(opts, {
|
|
55
|
+
basenameOfCwd: path.basename(process.cwd()),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const result = await scaffoldProject(config);
|
|
59
|
+
const cdHint = config.targetDir === '.' ? '' : ` ${c.cyan(`cd ${config.targetDir}`)}\n`;
|
|
60
|
+
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log(` ${c.sage('✔')} ${c.bold('Tea Party ready!')} ${c.dim(result.targetDir)}`);
|
|
63
|
+
console.log(` ${c.dim('package')} ${config.packageName}`);
|
|
64
|
+
console.log(` ${c.dim('theme')} ${config.theme}`);
|
|
65
|
+
console.log(` ${c.dim('core')} io.github.ferdakoplo:solaire-core:${config.solaireVersion}`);
|
|
66
|
+
console.log('');
|
|
67
|
+
console.log(` ${c.bold('Next steps:')}`);
|
|
68
|
+
process.stdout.write(cdHint);
|
|
69
|
+
console.log(` ${c.cyan('npm install')}`);
|
|
70
|
+
console.log(` ${c.cyan('npm run tea-party')}`);
|
|
71
|
+
console.log('');
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
package/src/prompts.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import { createInterface } from 'node:readline/promises';
|
|
3
|
+
import { stdin, stdout } from 'node:process';
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_PROJECT_NAME,
|
|
6
|
+
DEFAULT_THEME,
|
|
7
|
+
THEMES,
|
|
8
|
+
toDefaultPackage,
|
|
9
|
+
validatePackageName,
|
|
10
|
+
} from './args.js';
|
|
11
|
+
import { c } from './ui.js';
|
|
12
|
+
|
|
13
|
+
const THEME_OPTIONS = [
|
|
14
|
+
{
|
|
15
|
+
value: 'tea',
|
|
16
|
+
title: 'Tea Party',
|
|
17
|
+
hint: 'Warm amber, cream & sage palette (Tailwind v4)',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: 'tailwind',
|
|
21
|
+
title: 'Tailwind',
|
|
22
|
+
hint: 'Clean slate & blue utility classes (Tailwind v4)',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
value: 'css',
|
|
26
|
+
title: 'Plain CSS',
|
|
27
|
+
hint: 'Semantic CSS stylesheet without Tailwind',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pure navigation helper for arrow-key / j-k / numeric selection menus.
|
|
33
|
+
* Returns { index, submit, cancel }.
|
|
34
|
+
*/
|
|
35
|
+
export function handleMenuKey(currentIndex, key, total) {
|
|
36
|
+
if (!key || total <= 0) return { index: currentIndex, submit: false, cancel: false };
|
|
37
|
+
if (key.ctrl && key.name === 'c') return { index: currentIndex, submit: false, cancel: true };
|
|
38
|
+
if (key.name === 'escape') return { index: currentIndex, submit: false, cancel: true };
|
|
39
|
+
if (key.name === 'return' || key.name === 'enter') {
|
|
40
|
+
return { index: currentIndex, submit: true, cancel: false };
|
|
41
|
+
}
|
|
42
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
43
|
+
return { index: (currentIndex - 1 + total) % total, submit: false, cancel: false };
|
|
44
|
+
}
|
|
45
|
+
if (key.name === 'down' || key.name === 'j') {
|
|
46
|
+
return { index: (currentIndex + 1) % total, submit: false, cancel: false };
|
|
47
|
+
}
|
|
48
|
+
const num = Number.parseInt(key.sequence ?? '', 10);
|
|
49
|
+
if (num >= 1 && num <= total) {
|
|
50
|
+
return { index: num - 1, submit: false, cancel: false };
|
|
51
|
+
}
|
|
52
|
+
return { index: currentIndex, submit: false, cancel: false };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolve configuration interactively when running in a TTY without --yes,
|
|
57
|
+
* or non-interactively using flags + defaults.
|
|
58
|
+
*/
|
|
59
|
+
export async function resolveConfig(opts, { basenameOfCwd } = {}) {
|
|
60
|
+
const interactive = Boolean(stdin.isTTY && stdout.isTTY && !opts.yes);
|
|
61
|
+
|
|
62
|
+
if (!interactive) {
|
|
63
|
+
const targetDir = opts.targetDir ?? DEFAULT_PROJECT_NAME;
|
|
64
|
+
const projectName = targetDir === '.' ? (basenameOfCwd || DEFAULT_PROJECT_NAME) : leafName(targetDir);
|
|
65
|
+
const packageName = opts.packageName ?? toDefaultPackage(projectName);
|
|
66
|
+
const theme = opts.theme ?? DEFAULT_THEME;
|
|
67
|
+
return {
|
|
68
|
+
targetDir,
|
|
69
|
+
projectName,
|
|
70
|
+
packageName,
|
|
71
|
+
theme,
|
|
72
|
+
solaireVersion: opts.solaireVersion,
|
|
73
|
+
force: opts.force,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const targetDir =
|
|
78
|
+
opts.targetDir ?? (await promptText('Project directory', DEFAULT_PROJECT_NAME));
|
|
79
|
+
const projectName =
|
|
80
|
+
targetDir === '.' ? (basenameOfCwd || DEFAULT_PROJECT_NAME) : leafName(targetDir);
|
|
81
|
+
const defaultPkg = toDefaultPackage(projectName);
|
|
82
|
+
|
|
83
|
+
const packageName =
|
|
84
|
+
opts.packageName ??
|
|
85
|
+
(await promptText('Java base package', defaultPkg, validatePackageName));
|
|
86
|
+
|
|
87
|
+
const theme = opts.theme ?? (await promptSelect('Choose a UI theme', THEME_OPTIONS, DEFAULT_THEME));
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
targetDir,
|
|
91
|
+
projectName,
|
|
92
|
+
packageName,
|
|
93
|
+
theme,
|
|
94
|
+
solaireVersion: opts.solaireVersion,
|
|
95
|
+
force: opts.force,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function promptText(label, fallback, validate) {
|
|
100
|
+
while (true) {
|
|
101
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
102
|
+
let raw;
|
|
103
|
+
try {
|
|
104
|
+
raw = await rl.question(
|
|
105
|
+
` ${c.amber('◇')} ${c.bold(label)} ${c.dim(`(${fallback})`)}: `
|
|
106
|
+
);
|
|
107
|
+
} finally {
|
|
108
|
+
rl.close();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const value = raw.trim() || fallback;
|
|
112
|
+
try {
|
|
113
|
+
if (validate) validate(value);
|
|
114
|
+
// Replace prompt line with clean confirmed summary line
|
|
115
|
+
stdout.write(`\x1b[1A\x1b[2K ${c.sage('◆')} ${c.bold(label)} ${c.dim('·')} ${c.cyan(value)}\n`);
|
|
116
|
+
return value;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.log(` ${c.red('!')} ${err.message}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function promptSelect(label, options, defaultValue) {
|
|
124
|
+
let index = Math.max(0, options.findIndex((o) => o.value === defaultValue));
|
|
125
|
+
const totalLines = options.length + 2; // header + options + hint
|
|
126
|
+
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
let rendered = false;
|
|
129
|
+
|
|
130
|
+
const render = () => {
|
|
131
|
+
if (rendered) {
|
|
132
|
+
stdout.write(`\x1b[${totalLines}A\x1b[0J`);
|
|
133
|
+
}
|
|
134
|
+
rendered = true;
|
|
135
|
+
stdout.write(` ${c.amber('◇')} ${c.bold(label)}\n`);
|
|
136
|
+
options.forEach((opt, i) => {
|
|
137
|
+
const active = i === index;
|
|
138
|
+
const pointer = active ? c.amber('❯') : ' ';
|
|
139
|
+
const radio = active ? c.amber('●') : c.dim('○');
|
|
140
|
+
const title = active ? c.bold(c.amber(opt.title)) : opt.title;
|
|
141
|
+
const hint = c.dim(` — ${opt.hint}`);
|
|
142
|
+
stdout.write(` ${pointer} ${radio} ${title}${hint}\n`);
|
|
143
|
+
});
|
|
144
|
+
stdout.write(` ${c.dim('Use ↑/↓ arrows (or 1-3) and Enter to confirm')}\n`);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const cleanup = () => {
|
|
148
|
+
stdin.removeListener('keypress', onKeypress);
|
|
149
|
+
if (stdin.isTTY) stdin.setRawMode(false);
|
|
150
|
+
stdin.pause();
|
|
151
|
+
stdout.write('\x1b[?25h');
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const onKeypress = (_str, key) => {
|
|
155
|
+
const action = handleMenuKey(index, key, options.length);
|
|
156
|
+
if (action.cancel) {
|
|
157
|
+
stdout.write(`\x1b[${totalLines}A\x1b[0J`);
|
|
158
|
+
cleanup();
|
|
159
|
+
const err = new Error('Cancelled');
|
|
160
|
+
err.name = 'AbortError';
|
|
161
|
+
reject(err);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (action.submit) {
|
|
165
|
+
const chosen = options[index];
|
|
166
|
+
stdout.write(`\x1b[${totalLines}A\x1b[0J`);
|
|
167
|
+
stdout.write(
|
|
168
|
+
` ${c.sage('◆')} ${c.bold(label)} ${c.dim('·')} ${c.cyan(chosen.title)} ${c.dim(`(${chosen.value})`)}\n`
|
|
169
|
+
);
|
|
170
|
+
cleanup();
|
|
171
|
+
resolve(chosen.value);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (action.index !== index) {
|
|
175
|
+
index = action.index;
|
|
176
|
+
render();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
readline.emitKeypressEvents(stdin);
|
|
181
|
+
if (stdin.isTTY) stdin.setRawMode(true);
|
|
182
|
+
stdin.resume();
|
|
183
|
+
stdout.write('\x1b[?25l');
|
|
184
|
+
render();
|
|
185
|
+
stdin.on('keypress', onKeypress);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function leafName(targetDir) {
|
|
190
|
+
const parts = targetDir.replace(/[/\\]+$/, '').split(/[/\\]/).filter(Boolean);
|
|
191
|
+
return parts[parts.length - 1] || DEFAULT_PROJECT_NAME;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { THEME_OPTIONS, THEMES };
|
package/src/scaffold.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { chmod, cp, mkdir, readdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { renderTemplates } from './templates.js';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const WRAPPER_DIR = path.resolve(__dirname, '../templates/wrapper');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Scaffold a new Tea Party project into targetDir.
|
|
11
|
+
* Throws if targetDir exists and is non-empty unless force is true.
|
|
12
|
+
*/
|
|
13
|
+
export async function scaffoldProject(config) {
|
|
14
|
+
const absDir = path.resolve(config.targetDir);
|
|
15
|
+
await ensureTargetDir(absDir, config.force);
|
|
16
|
+
|
|
17
|
+
const files = renderTemplates(config);
|
|
18
|
+
for (const [relPath, content] of Object.entries(files)) {
|
|
19
|
+
const dest = path.join(absDir, relPath);
|
|
20
|
+
await mkdir(path.dirname(dest), { recursive: true });
|
|
21
|
+
await writeFile(dest, content, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await cp(WRAPPER_DIR, absDir, { recursive: true });
|
|
25
|
+
await chmod(path.join(absDir, 'gradlew'), 0o755);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
targetDir: absDir,
|
|
29
|
+
files: Object.keys(files),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function ensureTargetDir(absDir, force) {
|
|
34
|
+
await mkdir(absDir, { recursive: true });
|
|
35
|
+
const entries = await readdir(absDir);
|
|
36
|
+
const meaningful = entries.filter((name) => name !== '.DS_Store' && name !== '.git');
|
|
37
|
+
if (meaningful.length > 0 && !force) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Target directory "${absDir}" is not empty. Choose another directory or pass --force.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|