-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkspace.ts
More file actions
81 lines (70 loc) · 2.65 KB
/
workspace.ts
File metadata and controls
81 lines (70 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import fs from 'fs';
import path from 'path';
import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, scaffoldTemplate, sluggify } from '@pgpmjs/core';
import { Inquirerer, Question, registerDefaultResolver } from 'inquirerer';
const DEFAULT_MOTD = `
| _ _
=== |.===. '\\-//\`
(o o) {}o o{} (o o)
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
`;
export default async function runWorkspaceSetup(
argv: Partial<Record<string, any>>,
prompter: Inquirerer
) {
const workspaceQuestions: Question[] = [
{
name: 'name',
message: 'Enter workspace name',
required: true,
type: 'text'
}
];
const answers = await prompter.prompt(argv, workspaceQuestions);
const { cwd = process.cwd() } = argv;
const targetPath = path.join(cwd, sluggify(answers.name));
// Note: Don't close prompter here - it's still needed by scaffoldTemplate for template prompts.
// The prompter will be closed by the CLI framework after the command completes.
const templateRepo = (argv.repo as string) ?? DEFAULT_TEMPLATE_REPO;
// Don't set default template - let scaffoldTemplate use metadata-driven resolution
// Support both --template (new) and --template-path (deprecated) for backward compatibility
const template = (argv.template || argv.templatePath) as string | undefined;
// Register workspace.dirname resolver so boilerplate templates can use it via defaultFrom/setFrom
// This provides the intended workspace directory name before the folder is created
const dirName = path.basename(targetPath);
registerDefaultResolver('workspace.dirname', () => dirName);
const dir = argv.dir as string | undefined;
await scaffoldTemplate({
fromPath: template ?? 'workspace',
outputDir: targetPath,
templateRepo,
branch: argv.fromBranch as string | undefined,
dir,
answers: {
...argv,
...answers,
workspaceName: answers.name
},
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
noTty: Boolean((argv as any).noTty || argv['no-tty'] || argv.tty === false || process.env.CI === 'true'),
cwd,
prompter
});
// Check for .motd file and print it, or use default ASCII art
const motdPath = path.join(targetPath, '.motd');
let motd = DEFAULT_MOTD;
if (fs.existsSync(motdPath)) {
try {
motd = fs.readFileSync(motdPath, 'utf8');
fs.unlinkSync(motdPath);
} catch {
// Ignore errors reading/deleting .motd
}
}
process.stdout.write(motd);
if (!motd.endsWith('\n')) {
process.stdout.write('\n');
}
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${dirName}\n`);
return { ...argv, ...answers, cwd: targetPath };
}