pgpm 1.4.1 → 2.0.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/commands/init/index.d.ts +2 -2
- package/commands/init/index.js +178 -16
- package/commands/init/module.js +2 -0
- package/commands/init/workspace.js +5 -3
- package/esm/commands/init/index.js +178 -16
- package/esm/commands/init/module.js +2 -0
- package/esm/commands/init/workspace.js +5 -3
- package/package.json +5 -5
package/commands/init/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
2
|
export declare const createInitUsageText: (binaryName: string, productLabel?: string) => string;
|
|
3
3
|
declare const _default: (argv: Partial<Record<string, any>>, prompter: Inquirerer, _options: CLIOptions) => Promise<{
|
|
4
|
-
[x: string]: any;
|
|
5
|
-
} | {
|
|
6
4
|
cwd: string;
|
|
5
|
+
} | {
|
|
6
|
+
[x: string]: any;
|
|
7
7
|
}>;
|
|
8
8
|
export default _default;
|
package/commands/init/index.js
CHANGED
|
@@ -4,29 +4,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createInitUsageText = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const core_1 = require("@pgpmjs/core");
|
|
10
|
+
const types_1 = require("@pgpmjs/types");
|
|
11
|
+
const inquirerer_1 = require("inquirerer");
|
|
12
|
+
const DEFAULT_MOTD = `
|
|
13
|
+
| _ _
|
|
14
|
+
=== |.===. '\\-//\`
|
|
15
|
+
(o o) {}o o{} (o o)
|
|
16
|
+
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
|
|
17
|
+
`;
|
|
9
18
|
const createInitUsageText = (binaryName, productLabel) => {
|
|
10
19
|
const displayName = productLabel ?? binaryName;
|
|
11
20
|
return `
|
|
12
21
|
Init Command:
|
|
13
22
|
|
|
14
|
-
${binaryName} init [OPTIONS] [
|
|
23
|
+
${binaryName} init [OPTIONS] [<fromPath>]
|
|
15
24
|
|
|
16
|
-
Initialize ${displayName}
|
|
25
|
+
Initialize ${displayName} from a template. The template's type (workspace/module)
|
|
26
|
+
determines the behavior automatically.
|
|
17
27
|
|
|
18
28
|
Options:
|
|
19
29
|
--help, -h Show this help message
|
|
20
30
|
--cwd <directory> Working directory (default: current directory)
|
|
21
31
|
--repo <repo> Template repo (default: https://github.com/constructive-io/pgpm-boilerplates.git)
|
|
22
|
-
--template-path <path> Template sub-path (default: workspace/module) or local path override
|
|
23
32
|
--from-branch <branch> Branch/tag to use when cloning repo
|
|
33
|
+
--dir <variant> Template variant directory (e.g., supabase, drizzle)
|
|
24
34
|
|
|
25
35
|
Examples:
|
|
26
|
-
${binaryName} init Initialize new module
|
|
36
|
+
${binaryName} init Initialize new module (default)
|
|
27
37
|
${binaryName} init workspace Initialize new workspace
|
|
38
|
+
${binaryName} init module Initialize new module explicitly
|
|
39
|
+
${binaryName} init workspace --dir <variant> Use variant templates
|
|
28
40
|
${binaryName} init --repo owner/repo Use templates from GitHub repository
|
|
29
|
-
${binaryName} init --template-path ./custom-templates Use templates from local path
|
|
30
41
|
${binaryName} init --repo owner/repo --from-branch develop Use specific branch
|
|
31
42
|
`;
|
|
32
43
|
};
|
|
@@ -37,16 +48,167 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
37
48
|
console.log((0, exports.createInitUsageText)('pgpm'));
|
|
38
49
|
process.exit(0);
|
|
39
50
|
}
|
|
40
|
-
return
|
|
51
|
+
return handleInit(argv, prompter);
|
|
41
52
|
};
|
|
42
|
-
async function
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
async function handleInit(argv, prompter) {
|
|
54
|
+
const { cwd = process.cwd() } = argv;
|
|
55
|
+
const templateRepo = argv.repo ?? core_1.DEFAULT_TEMPLATE_REPO;
|
|
56
|
+
const branch = argv.fromBranch;
|
|
57
|
+
const dir = argv.dir;
|
|
58
|
+
const noTty = Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true');
|
|
59
|
+
// Get fromPath from first positional arg, default to 'module'
|
|
60
|
+
const fromPath = argv._?.[0] || 'module';
|
|
61
|
+
// Inspect the template to get its type
|
|
62
|
+
const inspection = (0, core_1.inspectTemplate)({
|
|
63
|
+
fromPath,
|
|
64
|
+
templateRepo,
|
|
65
|
+
branch,
|
|
66
|
+
dir,
|
|
67
|
+
toolName: core_1.DEFAULT_TEMPLATE_TOOL_NAME,
|
|
68
|
+
cwd,
|
|
69
|
+
});
|
|
70
|
+
const templateType = inspection.config?.type;
|
|
71
|
+
// Branch based on template type
|
|
72
|
+
if (templateType === 'workspace') {
|
|
73
|
+
return handleWorkspaceInit(argv, prompter, {
|
|
74
|
+
fromPath,
|
|
75
|
+
templateRepo,
|
|
76
|
+
branch,
|
|
77
|
+
dir,
|
|
78
|
+
noTty,
|
|
79
|
+
cwd,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Default to module init (for 'module' type or unknown types)
|
|
83
|
+
return handleModuleInit(argv, prompter, {
|
|
84
|
+
fromPath,
|
|
85
|
+
templateRepo,
|
|
86
|
+
branch,
|
|
87
|
+
dir,
|
|
88
|
+
noTty,
|
|
89
|
+
cwd,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function handleWorkspaceInit(argv, prompter, ctx) {
|
|
93
|
+
const workspaceQuestions = [
|
|
94
|
+
{
|
|
95
|
+
name: 'name',
|
|
96
|
+
message: 'Enter workspace name',
|
|
97
|
+
required: true,
|
|
98
|
+
type: 'text'
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
const answers = await prompter.prompt(argv, workspaceQuestions);
|
|
102
|
+
const targetPath = path_1.default.join(ctx.cwd, (0, core_1.sluggify)(answers.name));
|
|
103
|
+
// Register workspace.dirname resolver so boilerplate templates can use it via defaultFrom/setFrom
|
|
104
|
+
const dirName = path_1.default.basename(targetPath);
|
|
105
|
+
(0, inquirerer_1.registerDefaultResolver)('workspace.dirname', () => dirName);
|
|
106
|
+
await (0, core_1.scaffoldTemplate)({
|
|
107
|
+
fromPath: ctx.fromPath,
|
|
108
|
+
outputDir: targetPath,
|
|
109
|
+
templateRepo: ctx.templateRepo,
|
|
110
|
+
branch: ctx.branch,
|
|
111
|
+
dir: ctx.dir,
|
|
112
|
+
answers: {
|
|
46
113
|
...argv,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
114
|
+
...answers,
|
|
115
|
+
workspaceName: answers.name
|
|
116
|
+
},
|
|
117
|
+
toolName: core_1.DEFAULT_TEMPLATE_TOOL_NAME,
|
|
118
|
+
noTty: ctx.noTty,
|
|
119
|
+
cwd: ctx.cwd,
|
|
120
|
+
prompter
|
|
121
|
+
});
|
|
122
|
+
// Check for .motd file and print it, or use default ASCII art
|
|
123
|
+
const motdPath = path_1.default.join(targetPath, '.motd');
|
|
124
|
+
let motd = DEFAULT_MOTD;
|
|
125
|
+
if (fs_1.default.existsSync(motdPath)) {
|
|
126
|
+
try {
|
|
127
|
+
motd = fs_1.default.readFileSync(motdPath, 'utf8');
|
|
128
|
+
fs_1.default.unlinkSync(motdPath);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Ignore errors reading/deleting .motd
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
process.stdout.write(motd);
|
|
135
|
+
if (!motd.endsWith('\n')) {
|
|
136
|
+
process.stdout.write('\n');
|
|
137
|
+
}
|
|
138
|
+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${dirName}\n`);
|
|
139
|
+
return { ...argv, ...answers, cwd: targetPath };
|
|
140
|
+
}
|
|
141
|
+
async function handleModuleInit(argv, prompter, ctx) {
|
|
142
|
+
const project = new core_1.PgpmPackage(ctx.cwd);
|
|
143
|
+
if (!project.workspacePath) {
|
|
144
|
+
process.stderr.write('Not inside a PGPM workspace.\n');
|
|
145
|
+
throw types_1.errors.NOT_IN_WORKSPACE({});
|
|
146
|
+
}
|
|
147
|
+
if (!project.isInsideAllowedDirs(ctx.cwd) && !project.isInWorkspace() && !project.isParentOfAllowedDirs(ctx.cwd)) {
|
|
148
|
+
process.stderr.write('You must be inside the workspace root or a parent directory of modules (like packages/).\n');
|
|
149
|
+
throw types_1.errors.NOT_IN_WORKSPACE_MODULE({});
|
|
150
|
+
}
|
|
151
|
+
const availExtensions = project.getAvailableModules();
|
|
152
|
+
const moduleQuestions = [
|
|
153
|
+
{
|
|
154
|
+
name: 'moduleName',
|
|
155
|
+
message: 'Enter the module name',
|
|
156
|
+
required: true,
|
|
157
|
+
type: 'text',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: 'extensions',
|
|
161
|
+
message: 'Which extensions?',
|
|
162
|
+
options: availExtensions,
|
|
163
|
+
type: 'checkbox',
|
|
164
|
+
allowCustomOptions: true,
|
|
165
|
+
required: true,
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
const answers = await prompter.prompt(argv, moduleQuestions);
|
|
169
|
+
const modName = (0, core_1.sluggify)(answers.moduleName);
|
|
170
|
+
const extensions = answers.extensions
|
|
171
|
+
.filter((opt) => opt.selected)
|
|
172
|
+
.map((opt) => opt.name);
|
|
173
|
+
const templateAnswers = {
|
|
174
|
+
...argv,
|
|
175
|
+
...answers,
|
|
176
|
+
moduleName: modName,
|
|
177
|
+
packageIdentifier: argv.packageIdentifier || modName
|
|
178
|
+
};
|
|
179
|
+
await project.initModule({
|
|
180
|
+
name: modName,
|
|
181
|
+
description: answers.description || modName,
|
|
182
|
+
author: answers.author || modName,
|
|
183
|
+
extensions,
|
|
184
|
+
templateRepo: ctx.templateRepo,
|
|
185
|
+
templatePath: ctx.fromPath,
|
|
186
|
+
branch: ctx.branch,
|
|
187
|
+
dir: ctx.dir,
|
|
188
|
+
toolName: core_1.DEFAULT_TEMPLATE_TOOL_NAME,
|
|
189
|
+
answers: templateAnswers,
|
|
190
|
+
noTty: ctx.noTty
|
|
191
|
+
});
|
|
192
|
+
const isRoot = path_1.default.resolve(project.getWorkspacePath()) === path_1.default.resolve(ctx.cwd);
|
|
193
|
+
const modulePath = isRoot
|
|
194
|
+
? path_1.default.join(ctx.cwd, 'packages', modName)
|
|
195
|
+
: path_1.default.join(ctx.cwd, modName);
|
|
196
|
+
const motdPath = path_1.default.join(modulePath, '.motd');
|
|
197
|
+
let motd = DEFAULT_MOTD;
|
|
198
|
+
if (fs_1.default.existsSync(motdPath)) {
|
|
199
|
+
try {
|
|
200
|
+
motd = fs_1.default.readFileSync(motdPath, 'utf8');
|
|
201
|
+
fs_1.default.unlinkSync(motdPath);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Ignore errors reading/deleting .motd
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
process.stdout.write(motd);
|
|
208
|
+
if (!motd.endsWith('\n')) {
|
|
209
|
+
process.stdout.write('\n');
|
|
50
210
|
}
|
|
51
|
-
|
|
211
|
+
const relPath = isRoot ? `packages/${modName}` : modName;
|
|
212
|
+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${relPath}\n`);
|
|
213
|
+
return { ...argv, ...answers };
|
|
52
214
|
}
|
package/commands/init/module.js
CHANGED
|
@@ -51,6 +51,7 @@ async function runModuleSetup(argv, prompter) {
|
|
|
51
51
|
.map((opt) => opt.name);
|
|
52
52
|
const templateRepo = argv.repo ?? core_1.DEFAULT_TEMPLATE_REPO;
|
|
53
53
|
const templatePath = argv.templatePath;
|
|
54
|
+
const dir = argv.dir;
|
|
54
55
|
const templateAnswers = {
|
|
55
56
|
...argv,
|
|
56
57
|
...answers,
|
|
@@ -65,6 +66,7 @@ async function runModuleSetup(argv, prompter) {
|
|
|
65
66
|
templateRepo,
|
|
66
67
|
templatePath,
|
|
67
68
|
branch: argv.fromBranch,
|
|
69
|
+
dir,
|
|
68
70
|
toolName: core_1.DEFAULT_TEMPLATE_TOOL_NAME,
|
|
69
71
|
answers: templateAnswers,
|
|
70
72
|
noTty: Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true')
|
|
@@ -35,12 +35,13 @@ async function runWorkspaceSetup(argv, prompter) {
|
|
|
35
35
|
// This provides the intended workspace directory name before the folder is created
|
|
36
36
|
const dirName = path_1.default.basename(targetPath);
|
|
37
37
|
(0, inquirerer_1.registerDefaultResolver)('workspace.dirname', () => dirName);
|
|
38
|
+
const dir = argv.dir;
|
|
38
39
|
await (0, core_1.scaffoldTemplate)({
|
|
39
|
-
|
|
40
|
+
fromPath: templatePath ?? 'workspace',
|
|
40
41
|
outputDir: targetPath,
|
|
41
42
|
templateRepo,
|
|
42
43
|
branch: argv.fromBranch,
|
|
43
|
-
|
|
44
|
+
dir,
|
|
44
45
|
answers: {
|
|
45
46
|
...argv,
|
|
46
47
|
...answers,
|
|
@@ -48,7 +49,8 @@ async function runWorkspaceSetup(argv, prompter) {
|
|
|
48
49
|
},
|
|
49
50
|
toolName: core_1.DEFAULT_TEMPLATE_TOOL_NAME,
|
|
50
51
|
noTty: Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true'),
|
|
51
|
-
cwd
|
|
52
|
+
cwd,
|
|
53
|
+
prompter
|
|
52
54
|
});
|
|
53
55
|
// Check for .motd file and print it, or use default ASCII art
|
|
54
56
|
const motdPath = path_1.default.join(targetPath, '.motd');
|
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { DEFAULT_TEMPLATE_REPO, DEFAULT_TEMPLATE_TOOL_NAME, inspectTemplate, PgpmPackage, scaffoldTemplate, sluggify, } from '@pgpmjs/core';
|
|
4
|
+
import { errors } from '@pgpmjs/types';
|
|
5
|
+
import { registerDefaultResolver } from 'inquirerer';
|
|
6
|
+
const DEFAULT_MOTD = `
|
|
7
|
+
| _ _
|
|
8
|
+
=== |.===. '\\-//\`
|
|
9
|
+
(o o) {}o o{} (o o)
|
|
10
|
+
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
|
|
11
|
+
`;
|
|
3
12
|
export const createInitUsageText = (binaryName, productLabel) => {
|
|
4
13
|
const displayName = productLabel ?? binaryName;
|
|
5
14
|
return `
|
|
6
15
|
Init Command:
|
|
7
16
|
|
|
8
|
-
${binaryName} init [OPTIONS] [
|
|
17
|
+
${binaryName} init [OPTIONS] [<fromPath>]
|
|
9
18
|
|
|
10
|
-
Initialize ${displayName}
|
|
19
|
+
Initialize ${displayName} from a template. The template's type (workspace/module)
|
|
20
|
+
determines the behavior automatically.
|
|
11
21
|
|
|
12
22
|
Options:
|
|
13
23
|
--help, -h Show this help message
|
|
14
24
|
--cwd <directory> Working directory (default: current directory)
|
|
15
25
|
--repo <repo> Template repo (default: https://github.com/constructive-io/pgpm-boilerplates.git)
|
|
16
|
-
--template-path <path> Template sub-path (default: workspace/module) or local path override
|
|
17
26
|
--from-branch <branch> Branch/tag to use when cloning repo
|
|
27
|
+
--dir <variant> Template variant directory (e.g., supabase, drizzle)
|
|
18
28
|
|
|
19
29
|
Examples:
|
|
20
|
-
${binaryName} init Initialize new module
|
|
30
|
+
${binaryName} init Initialize new module (default)
|
|
21
31
|
${binaryName} init workspace Initialize new workspace
|
|
32
|
+
${binaryName} init module Initialize new module explicitly
|
|
33
|
+
${binaryName} init workspace --dir <variant> Use variant templates
|
|
22
34
|
${binaryName} init --repo owner/repo Use templates from GitHub repository
|
|
23
|
-
${binaryName} init --template-path ./custom-templates Use templates from local path
|
|
24
35
|
${binaryName} init --repo owner/repo --from-branch develop Use specific branch
|
|
25
36
|
`;
|
|
26
37
|
};
|
|
@@ -30,16 +41,167 @@ export default async (argv, prompter, _options) => {
|
|
|
30
41
|
console.log(createInitUsageText('pgpm'));
|
|
31
42
|
process.exit(0);
|
|
32
43
|
}
|
|
33
|
-
return
|
|
44
|
+
return handleInit(argv, prompter);
|
|
34
45
|
};
|
|
35
|
-
async function
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
async function handleInit(argv, prompter) {
|
|
47
|
+
const { cwd = process.cwd() } = argv;
|
|
48
|
+
const templateRepo = argv.repo ?? DEFAULT_TEMPLATE_REPO;
|
|
49
|
+
const branch = argv.fromBranch;
|
|
50
|
+
const dir = argv.dir;
|
|
51
|
+
const noTty = Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true');
|
|
52
|
+
// Get fromPath from first positional arg, default to 'module'
|
|
53
|
+
const fromPath = argv._?.[0] || 'module';
|
|
54
|
+
// Inspect the template to get its type
|
|
55
|
+
const inspection = inspectTemplate({
|
|
56
|
+
fromPath,
|
|
57
|
+
templateRepo,
|
|
58
|
+
branch,
|
|
59
|
+
dir,
|
|
60
|
+
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
|
|
61
|
+
cwd,
|
|
62
|
+
});
|
|
63
|
+
const templateType = inspection.config?.type;
|
|
64
|
+
// Branch based on template type
|
|
65
|
+
if (templateType === 'workspace') {
|
|
66
|
+
return handleWorkspaceInit(argv, prompter, {
|
|
67
|
+
fromPath,
|
|
68
|
+
templateRepo,
|
|
69
|
+
branch,
|
|
70
|
+
dir,
|
|
71
|
+
noTty,
|
|
72
|
+
cwd,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Default to module init (for 'module' type or unknown types)
|
|
76
|
+
return handleModuleInit(argv, prompter, {
|
|
77
|
+
fromPath,
|
|
78
|
+
templateRepo,
|
|
79
|
+
branch,
|
|
80
|
+
dir,
|
|
81
|
+
noTty,
|
|
82
|
+
cwd,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async function handleWorkspaceInit(argv, prompter, ctx) {
|
|
86
|
+
const workspaceQuestions = [
|
|
87
|
+
{
|
|
88
|
+
name: 'name',
|
|
89
|
+
message: 'Enter workspace name',
|
|
90
|
+
required: true,
|
|
91
|
+
type: 'text'
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
const answers = await prompter.prompt(argv, workspaceQuestions);
|
|
95
|
+
const targetPath = path.join(ctx.cwd, sluggify(answers.name));
|
|
96
|
+
// Register workspace.dirname resolver so boilerplate templates can use it via defaultFrom/setFrom
|
|
97
|
+
const dirName = path.basename(targetPath);
|
|
98
|
+
registerDefaultResolver('workspace.dirname', () => dirName);
|
|
99
|
+
await scaffoldTemplate({
|
|
100
|
+
fromPath: ctx.fromPath,
|
|
101
|
+
outputDir: targetPath,
|
|
102
|
+
templateRepo: ctx.templateRepo,
|
|
103
|
+
branch: ctx.branch,
|
|
104
|
+
dir: ctx.dir,
|
|
105
|
+
answers: {
|
|
39
106
|
...argv,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
107
|
+
...answers,
|
|
108
|
+
workspaceName: answers.name
|
|
109
|
+
},
|
|
110
|
+
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
|
|
111
|
+
noTty: ctx.noTty,
|
|
112
|
+
cwd: ctx.cwd,
|
|
113
|
+
prompter
|
|
114
|
+
});
|
|
115
|
+
// Check for .motd file and print it, or use default ASCII art
|
|
116
|
+
const motdPath = path.join(targetPath, '.motd');
|
|
117
|
+
let motd = DEFAULT_MOTD;
|
|
118
|
+
if (fs.existsSync(motdPath)) {
|
|
119
|
+
try {
|
|
120
|
+
motd = fs.readFileSync(motdPath, 'utf8');
|
|
121
|
+
fs.unlinkSync(motdPath);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Ignore errors reading/deleting .motd
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
process.stdout.write(motd);
|
|
128
|
+
if (!motd.endsWith('\n')) {
|
|
129
|
+
process.stdout.write('\n');
|
|
130
|
+
}
|
|
131
|
+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${dirName}\n`);
|
|
132
|
+
return { ...argv, ...answers, cwd: targetPath };
|
|
133
|
+
}
|
|
134
|
+
async function handleModuleInit(argv, prompter, ctx) {
|
|
135
|
+
const project = new PgpmPackage(ctx.cwd);
|
|
136
|
+
if (!project.workspacePath) {
|
|
137
|
+
process.stderr.write('Not inside a PGPM workspace.\n');
|
|
138
|
+
throw errors.NOT_IN_WORKSPACE({});
|
|
139
|
+
}
|
|
140
|
+
if (!project.isInsideAllowedDirs(ctx.cwd) && !project.isInWorkspace() && !project.isParentOfAllowedDirs(ctx.cwd)) {
|
|
141
|
+
process.stderr.write('You must be inside the workspace root or a parent directory of modules (like packages/).\n');
|
|
142
|
+
throw errors.NOT_IN_WORKSPACE_MODULE({});
|
|
143
|
+
}
|
|
144
|
+
const availExtensions = project.getAvailableModules();
|
|
145
|
+
const moduleQuestions = [
|
|
146
|
+
{
|
|
147
|
+
name: 'moduleName',
|
|
148
|
+
message: 'Enter the module name',
|
|
149
|
+
required: true,
|
|
150
|
+
type: 'text',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'extensions',
|
|
154
|
+
message: 'Which extensions?',
|
|
155
|
+
options: availExtensions,
|
|
156
|
+
type: 'checkbox',
|
|
157
|
+
allowCustomOptions: true,
|
|
158
|
+
required: true,
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
const answers = await prompter.prompt(argv, moduleQuestions);
|
|
162
|
+
const modName = sluggify(answers.moduleName);
|
|
163
|
+
const extensions = answers.extensions
|
|
164
|
+
.filter((opt) => opt.selected)
|
|
165
|
+
.map((opt) => opt.name);
|
|
166
|
+
const templateAnswers = {
|
|
167
|
+
...argv,
|
|
168
|
+
...answers,
|
|
169
|
+
moduleName: modName,
|
|
170
|
+
packageIdentifier: argv.packageIdentifier || modName
|
|
171
|
+
};
|
|
172
|
+
await project.initModule({
|
|
173
|
+
name: modName,
|
|
174
|
+
description: answers.description || modName,
|
|
175
|
+
author: answers.author || modName,
|
|
176
|
+
extensions,
|
|
177
|
+
templateRepo: ctx.templateRepo,
|
|
178
|
+
templatePath: ctx.fromPath,
|
|
179
|
+
branch: ctx.branch,
|
|
180
|
+
dir: ctx.dir,
|
|
181
|
+
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
|
|
182
|
+
answers: templateAnswers,
|
|
183
|
+
noTty: ctx.noTty
|
|
184
|
+
});
|
|
185
|
+
const isRoot = path.resolve(project.getWorkspacePath()) === path.resolve(ctx.cwd);
|
|
186
|
+
const modulePath = isRoot
|
|
187
|
+
? path.join(ctx.cwd, 'packages', modName)
|
|
188
|
+
: path.join(ctx.cwd, modName);
|
|
189
|
+
const motdPath = path.join(modulePath, '.motd');
|
|
190
|
+
let motd = DEFAULT_MOTD;
|
|
191
|
+
if (fs.existsSync(motdPath)) {
|
|
192
|
+
try {
|
|
193
|
+
motd = fs.readFileSync(motdPath, 'utf8');
|
|
194
|
+
fs.unlinkSync(motdPath);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Ignore errors reading/deleting .motd
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
process.stdout.write(motd);
|
|
201
|
+
if (!motd.endsWith('\n')) {
|
|
202
|
+
process.stdout.write('\n');
|
|
43
203
|
}
|
|
44
|
-
|
|
204
|
+
const relPath = isRoot ? `packages/${modName}` : modName;
|
|
205
|
+
process.stdout.write(`\n✨ Enjoy!\n\ncd ./${relPath}\n`);
|
|
206
|
+
return { ...argv, ...answers };
|
|
45
207
|
}
|
|
@@ -45,6 +45,7 @@ export default async function runModuleSetup(argv, prompter) {
|
|
|
45
45
|
.map((opt) => opt.name);
|
|
46
46
|
const templateRepo = argv.repo ?? DEFAULT_TEMPLATE_REPO;
|
|
47
47
|
const templatePath = argv.templatePath;
|
|
48
|
+
const dir = argv.dir;
|
|
48
49
|
const templateAnswers = {
|
|
49
50
|
...argv,
|
|
50
51
|
...answers,
|
|
@@ -59,6 +60,7 @@ export default async function runModuleSetup(argv, prompter) {
|
|
|
59
60
|
templateRepo,
|
|
60
61
|
templatePath,
|
|
61
62
|
branch: argv.fromBranch,
|
|
63
|
+
dir,
|
|
62
64
|
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
|
|
63
65
|
answers: templateAnswers,
|
|
64
66
|
noTty: Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true')
|
|
@@ -29,12 +29,13 @@ export default async function runWorkspaceSetup(argv, prompter) {
|
|
|
29
29
|
// This provides the intended workspace directory name before the folder is created
|
|
30
30
|
const dirName = path.basename(targetPath);
|
|
31
31
|
registerDefaultResolver('workspace.dirname', () => dirName);
|
|
32
|
+
const dir = argv.dir;
|
|
32
33
|
await scaffoldTemplate({
|
|
33
|
-
|
|
34
|
+
fromPath: templatePath ?? 'workspace',
|
|
34
35
|
outputDir: targetPath,
|
|
35
36
|
templateRepo,
|
|
36
37
|
branch: argv.fromBranch,
|
|
37
|
-
|
|
38
|
+
dir,
|
|
38
39
|
answers: {
|
|
39
40
|
...argv,
|
|
40
41
|
...answers,
|
|
@@ -42,7 +43,8 @@ export default async function runWorkspaceSetup(argv, prompter) {
|
|
|
42
43
|
},
|
|
43
44
|
toolName: DEFAULT_TEMPLATE_TOOL_NAME,
|
|
44
45
|
noTty: Boolean(argv.noTty || argv['no-tty'] || process.env.CI === 'true'),
|
|
45
|
-
cwd
|
|
46
|
+
cwd,
|
|
47
|
+
prompter
|
|
46
48
|
});
|
|
47
49
|
// Check for .motd file and print it, or use default ASCII art
|
|
48
50
|
const motdPath = path.join(targetPath, '.motd');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgpm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL Package Manager - Database migration and package management CLI",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"ts-node": "^10.9.2"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pgpmjs/core": "^
|
|
48
|
+
"@pgpmjs/core": "^4.0.0",
|
|
49
49
|
"@pgpmjs/env": "^2.8.8",
|
|
50
50
|
"@pgpmjs/logger": "^1.3.5",
|
|
51
51
|
"@pgpmjs/types": "^2.12.6",
|
|
52
52
|
"appstash": "^0.2.6",
|
|
53
|
-
"create-gen-app": "^0.
|
|
53
|
+
"create-gen-app": "^0.8.1",
|
|
54
54
|
"find-and-require-package-json": "^0.8.2",
|
|
55
|
-
"inquirerer": "^2.
|
|
55
|
+
"inquirerer": "^2.4.0",
|
|
56
56
|
"js-yaml": "^4.1.0",
|
|
57
57
|
"minimist": "^1.2.8",
|
|
58
58
|
"pg-cache": "^1.6.9",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"pg",
|
|
74
74
|
"pgsql"
|
|
75
75
|
],
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "b1d773f5215ad5ea1dca82b33b550728fdcd1ec0"
|
|
77
77
|
}
|