Skip to content

Commit d46dc5e

Browse files
authored
Merge pull request #474 from constructive-io/devin/1766637311-upgrade-inquirerer-create-gen-app
chore: upgrade inquirerer/create-gen-app and add init welcome messages
2 parents c9a7995 + fa66b19 commit d46dc5e

9 files changed

Lines changed: 90 additions & 53 deletions

File tree

packages/cli/__tests__/__snapshots__/cli.test.ts.snap

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ exports[`Inquirerer prompts user and correctly processes delayed input 2`] = `
1515
exports[`Inquirerer prompts user and correctly processes delayed input 3`] = `
1616
[
1717
"",
18-
"autocompleteField?
19-
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
20-
><SPACE>Your<SPACE>input:
21-
$<SPACE>
18+
"autocompleteField?<SPACE>(--autocompleteField)
19+
><SPACE>
2220
",
2321
"><SPACE>first<SPACE>option
2422
",
@@ -27,10 +25,8 @@ $<SPACE>
2725
"<SPACE><SPACE>firry<SPACE>third<SPACE>option
2826
",
2927
"",
30-
"autocompleteField?
31-
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
32-
><SPACE>Your<SPACE>input:
33-
$<SPACE>
28+
"autocompleteField?<SPACE>(--autocompleteField)
29+
><SPACE>
3430
",
3531
"<SPACE><SPACE>first<SPACE>option
3632
",
@@ -39,10 +35,8 @@ $<SPACE>
3935
"<SPACE><SPACE>firry<SPACE>third<SPACE>option
4036
",
4137
"",
42-
"autocompleteField?
43-
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
44-
><SPACE>Your<SPACE>input:
45-
$<SPACE>
38+
"autocompleteField?<SPACE>(--autocompleteField)
39+
><SPACE>
4640
",
4741
"<SPACE><SPACE>first<SPACE>option
4842
",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@pgpmjs/server-utils": "workspace:^",
5656
"@pgpmjs/types": "workspace:^",
5757
"find-and-require-package-json": "^0.8.2",
58-
"inquirerer": "^2.2.0",
58+
"inquirerer": "^2.3.0",
5959
"js-yaml": "^4.1.0",
6060
"minimist": "^1.2.8",
6161
"pg-cache": "workspace:^",

packages/csv-to-pg/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@pgsql/types": "^17.6.2",
4747
"@pgsql/utils": "^17.8.3",
4848
"csv-parser": "^2.3.3",
49-
"inquirerer": "^2.0.3",
49+
"inquirerer": "^2.3.0",
5050
"js-yaml": "^3.14.0",
5151
"pgsql-deparser": "^17.12.2"
5252
}

pgpm/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
"@pgpmjs/logger": "workspace:^",
5151
"@pgpmjs/types": "workspace:^",
5252
"appstash": "^0.2.6",
53-
"create-gen-app": "^0.6.0",
53+
"create-gen-app": "^0.6.2",
5454
"find-and-require-package-json": "^0.8.2",
55-
"inquirerer": "^2.2.0",
55+
"inquirerer": "^2.3.0",
5656
"js-yaml": "^4.1.0",
5757
"minimist": "^1.2.8",
5858
"pg-cache": "workspace:^",

pgpm/cli/src/commands/cache.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { Logger } from '@pgpmjs/logger';
21
import { CLIOptions, Inquirerer } from 'inquirerer';
32
import { CacheManager } from 'create-gen-app';
43
import { cliExitWithError } from '../utils/cli-error';
54

6-
const log = new Logger('cache');
7-
85
const cacheUsageText = `
96
Cache Command:
107
@@ -35,8 +32,7 @@ export default async (
3532
const cacheManager = new CacheManager({ toolName });
3633

3734
cacheManager.clearAll();
38-
log.success(`Cleared template cache for "${toolName}".`);
39-
log.debug(`Cache location: ${cacheManager.getReposDir()}`);
35+
process.stdout.write(`Cleared template cache for "${toolName}".\n`);
4036

4137
return argv;
4238
};

pgpm/cli/src/commands/init/module.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
14
import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, PgpmPackage, sluggify } from '@pgpmjs/core';
2-
import { Logger } from '@pgpmjs/logger';
35
import { errors } from '@pgpmjs/types';
46
import { Inquirerer, OptionValue, Question } from 'inquirerer';
57

6-
const log = new Logger('module-init');
8+
const DEFAULT_MOTD = `
9+
| _ _
10+
=== |.===. '\\-//\`
11+
(o o) {}o o{} (o o)
12+
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
13+
`;
714

815
export default async function runModuleSetup(
916
argv: Partial<Record<string, any>>,
@@ -14,12 +21,12 @@ export default async function runModuleSetup(
1421
const project = new PgpmPackage(cwd);
1522

1623
if (!project.workspacePath) {
17-
log.error('Not inside a PGPM workspace.');
24+
process.stderr.write('Not inside a PGPM workspace.\n');
1825
throw errors.NOT_IN_WORKSPACE({});
1926
}
2027

2128
if (!project.isInsideAllowedDirs(cwd) && !project.isInWorkspace() && !project.isParentOfAllowedDirs(cwd)) {
22-
log.error('You must be inside the workspace root or a parent directory of modules (like packages/).');
29+
process.stderr.write('You must be inside the workspace root or a parent directory of modules (like packages/).\n');
2330
throw errors.NOT_IN_WORKSPACE_MODULE({});
2431
}
2532

@@ -74,6 +81,28 @@ export default async function runModuleSetup(
7481
noTty: Boolean((argv as any).noTty || argv['no-tty'] || process.env.CI === 'true')
7582
});
7683

77-
log.success(`Initialized module: ${modName}`);
84+
const isRoot = path.resolve(project.getWorkspacePath()!) === path.resolve(cwd);
85+
const modulePath = isRoot
86+
? path.join(cwd, 'packages', modName)
87+
: path.join(cwd, modName);
88+
89+
const motdPath = path.join(modulePath, '.motd');
90+
let motd = DEFAULT_MOTD;
91+
if (fs.existsSync(motdPath)) {
92+
try {
93+
motd = fs.readFileSync(motdPath, 'utf8');
94+
fs.unlinkSync(motdPath);
95+
} catch {
96+
// Ignore errors reading/deleting .motd
97+
}
98+
}
99+
process.stdout.write(motd);
100+
if (!motd.endsWith('\n')) {
101+
process.stdout.write('\n');
102+
}
103+
104+
const relPath = isRoot ? `packages/${modName}` : modName;
105+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${relPath}\n`);
106+
78107
return { ...argv, ...answers };
79108
}

pgpm/cli/src/commands/init/workspace.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
14
import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, scaffoldTemplate, sluggify } from '@pgpmjs/core';
2-
import { Logger } from '@pgpmjs/logger';
35
import { Inquirerer, Question, registerDefaultResolver } from 'inquirerer';
4-
import path from 'path';
56

6-
const log = new Logger('workspace-init');
7+
const DEFAULT_MOTD = `
8+
| _ _
9+
=== |.===. '\\-//\`
10+
(o o) {}o o{} (o o)
11+
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
12+
`;
713

814
export default async function runWorkspaceSetup(
915
argv: Partial<Record<string, any>>,
@@ -33,7 +39,7 @@ export default async function runWorkspaceSetup(
3339
const dirName = path.basename(targetPath);
3440
registerDefaultResolver('workspace.dirname', () => dirName);
3541

36-
const scaffoldResult = await scaffoldTemplate({
42+
await scaffoldTemplate({
3743
type: 'workspace',
3844
outputDir: targetPath,
3945
templateRepo,
@@ -49,11 +55,23 @@ export default async function runWorkspaceSetup(
4955
cwd
5056
});
5157

52-
const cacheMessage = scaffoldResult.cacheUsed
53-
? `Using cached templates from ${scaffoldResult.templateDir}`
54-
: `Fetched templates into ${scaffoldResult.templateDir}`;
55-
log.success(cacheMessage);
56-
log.success('Workspace templates rendered.');
58+
// Check for .motd file and print it, or use default ASCII art
59+
const motdPath = path.join(targetPath, '.motd');
60+
let motd = DEFAULT_MOTD;
61+
if (fs.existsSync(motdPath)) {
62+
try {
63+
motd = fs.readFileSync(motdPath, 'utf8');
64+
fs.unlinkSync(motdPath);
65+
} catch {
66+
// Ignore errors reading/deleting .motd
67+
}
68+
}
69+
process.stdout.write(motd);
70+
if (!motd.endsWith('\n')) {
71+
process.stdout.write('\n');
72+
}
73+
74+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${dirName}\n`);
5775

5876
return { ...argv, ...answers, cwd: targetPath };
5977
}

pgpm/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@pgpmjs/logger": "workspace:^",
5252
"@pgpmjs/server-utils": "workspace:^",
5353
"@pgpmjs/types": "workspace:^",
54-
"create-gen-app": "^0.6.0",
54+
"create-gen-app": "^0.6.2",
5555
"csv-to-pg": "^2.0.10",
5656
"glob": "^13.0.0",
5757
"komoji": "^0.7.11",

pnpm-lock.yaml

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)