Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions packages/cli/__tests__/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ exports[`Inquirerer prompts user and correctly processes delayed input 2`] = `
exports[`Inquirerer prompts user and correctly processes delayed input 3`] = `
[
"",
"autocompleteField?
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
><SPACE>Your<SPACE>input:
$<SPACE>
"autocompleteField?<SPACE>(--autocompleteField)
><SPACE>
",
"><SPACE>first<SPACE>option
",
Expand All @@ -27,10 +25,8 @@ $<SPACE>
"<SPACE><SPACE>firry<SPACE>third<SPACE>option
",
"",
"autocompleteField?
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
><SPACE>Your<SPACE>input:
$<SPACE>
"autocompleteField?<SPACE>(--autocompleteField)
><SPACE>
",
"<SPACE><SPACE>first<SPACE>option
",
Expand All @@ -39,10 +35,8 @@ $<SPACE>
"<SPACE><SPACE>firry<SPACE>third<SPACE>option
",
"",
"autocompleteField?
Argument<SPACE>--autocompleteField<SPACE>type<SPACE>[autocomplete]
><SPACE>Your<SPACE>input:
$<SPACE>
"autocompleteField?<SPACE>(--autocompleteField)
><SPACE>
",
"<SPACE><SPACE>first<SPACE>option
",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
"find-and-require-package-json": "^0.8.2",
"inquirerer": "^2.2.0",
"inquirerer": "^2.3.0",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"pg-cache": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-to-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@pgsql/types": "^17.6.2",
"@pgsql/utils": "^17.8.3",
"csv-parser": "^2.3.3",
"inquirerer": "^2.0.3",
"inquirerer": "^2.3.0",
"js-yaml": "^3.14.0",
"pgsql-deparser": "^17.12.2"
}
Expand Down
4 changes: 2 additions & 2 deletions pgpm/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/types": "workspace:^",
"appstash": "^0.2.6",
"create-gen-app": "^0.6.0",
"create-gen-app": "^0.6.2",
"find-and-require-package-json": "^0.8.2",
"inquirerer": "^2.2.0",
"inquirerer": "^2.3.0",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"pg-cache": "workspace:^",
Expand Down
6 changes: 1 addition & 5 deletions pgpm/cli/src/commands/cache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Logger } from '@pgpmjs/logger';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { CacheManager } from 'create-gen-app';
import { cliExitWithError } from '../utils/cli-error';

const log = new Logger('cache');

const cacheUsageText = `
Cache Command:

Expand Down Expand Up @@ -35,8 +32,7 @@ export default async (
const cacheManager = new CacheManager({ toolName });

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

return argv;
};
39 changes: 34 additions & 5 deletions pgpm/cli/src/commands/init/module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import fs from 'fs';
import path from 'path';

import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, PgpmPackage, sluggify } from '@pgpmjs/core';
import { Logger } from '@pgpmjs/logger';
import { errors } from '@pgpmjs/types';
import { Inquirerer, OptionValue, Question } from 'inquirerer';

const log = new Logger('module-init');
const DEFAULT_MOTD = `
| _ _
=== |.===. '\\-//\`
(o o) {}o o{} (o o)
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
`;

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

if (!project.workspacePath) {
log.error('Not inside a PGPM workspace.');
process.stderr.write('Not inside a PGPM workspace.\n');
throw errors.NOT_IN_WORKSPACE({});
}

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

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

log.success(`Initialized module: ${modName}`);
const isRoot = path.resolve(project.getWorkspacePath()!) === path.resolve(cwd);
const modulePath = isRoot
? path.join(cwd, 'packages', modName)
: path.join(cwd, modName);

const motdPath = path.join(modulePath, '.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');
}

const relPath = isRoot ? `packages/${modName}` : modName;
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${relPath}\n`);

return { ...argv, ...answers };
}
36 changes: 27 additions & 9 deletions pgpm/cli/src/commands/init/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import fs from 'fs';
import path from 'path';

import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, scaffoldTemplate, sluggify } from '@pgpmjs/core';
import { Logger } from '@pgpmjs/logger';
import { Inquirerer, Question, registerDefaultResolver } from 'inquirerer';
import path from 'path';

const log = new Logger('workspace-init');
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>>,
Expand Down Expand Up @@ -33,7 +39,7 @@ export default async function runWorkspaceSetup(
const dirName = path.basename(targetPath);
registerDefaultResolver('workspace.dirname', () => dirName);

const scaffoldResult = await scaffoldTemplate({
await scaffoldTemplate({
type: 'workspace',
outputDir: targetPath,
templateRepo,
Expand All @@ -49,11 +55,23 @@ export default async function runWorkspaceSetup(
cwd
});

const cacheMessage = scaffoldResult.cacheUsed
? `Using cached templates from ${scaffoldResult.templateDir}`
: `Fetched templates into ${scaffoldResult.templateDir}`;
log.success(cacheMessage);
log.success('Workspace templates rendered.');
// 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 };
}
2 changes: 1 addition & 1 deletion pgpm/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
"create-gen-app": "^0.6.0",
"create-gen-app": "^0.6.2",
"csv-to-pg": "^2.0.10",
"glob": "^13.0.0",
"komoji": "^0.7.11",
Expand Down
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.