codepen-commander 1.3.0 → 1.4.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 +103 -11
- package/api/client.js +129 -106
- package/cli.js +34 -29
- package/commands/auth/default.js +40 -0
- package/commands/auth/index.js +83 -0
- package/commands/auth/list.js +78 -0
- package/commands/auth/login.js +136 -0
- package/commands/auth/logout.js +186 -0
- package/commands/auth/status.js +212 -0
- package/commands/build.js +256 -0
- package/commands/clone.js +13 -581
- package/commands/delete.js +548 -80
- package/commands/deploy.js +164 -169
- package/commands/domains.js +83 -39
- package/commands/fork.js +13 -317
- package/commands/info.js +152 -0
- package/commands/init.js +375 -0
- package/commands/list.js +95 -78
- package/commands/new.js +155 -83
- package/commands/open.js +29 -19
- package/commands/privacy.js +52 -36
- package/commands/pull.js +123 -110
- package/commands/push.js +221 -376
- package/commands/restore.js +251 -0
- package/commands/rollback.js +141 -0
- package/commands/serve.js +119 -0
- package/commands/settings.js +126 -0
- package/commands/shell.js +305 -0
- package/commands/status.js +133 -39
- package/commands/sync.js +330 -0
- package/commands/undeploy.js +102 -0
- package/commands/unlink.js +191 -0
- package/commands/versions.js +100 -163
- package/config/auth.js +4 -374
- package/config/pen-blocks.js +166 -0
- package/config/project.js +103 -231
- package/config/user-store.js +364 -0
- package/constants.js +42 -0
- package/errors.js +17 -0
- package/package.json +1 -1
- package/shell/index.html +79 -0
- package/shell/scripts.js +276 -0
- package/shell/styles.css +492 -0
- package/site/blocks/classic.js +270 -0
- package/site/blocks/context.js +63 -0
- package/site/blocks/index.js +4 -0
- package/site/blocks/packages.js +242 -0
- package/site/blocks/unsupported-page.js +328 -0
- package/site/builder.js +475 -0
- package/site/detect.js +65 -0
- package/site/ignore-files.js +90 -0
- package/site/manifest.js +227 -0
- package/site/server.js +483 -0
- package/site/shell.js +363 -0
- package/sync/fs.js +19 -17
- package/sync/info.js +6 -81
- package/utils/browser.js +17 -10
- package/utils/cli-options.js +79 -0
- package/utils/codepen-url.js +183 -0
- package/utils/format.js +39 -30
- package/utils/fs-safe.js +95 -0
- package/utils/html.js +40 -1
- package/utils/json.js +4 -19
- package/utils/output.js +37 -0
- package/utils/package-paths.js +51 -0
- package/utils/prompts/index.js +5 -0
- package/utils/prompts/multi-select.js +185 -0
- package/utils/prompts/secret.js +65 -0
- package/utils/prompts/select.js +141 -0
- package/utils/prompts/text.js +99 -0
- package/utils/prompts/tty-list.js +165 -0
- package/utils/prompts/types.js +35 -0
- package/utils/strings.js +98 -0
- package/utils/watcher.js +82 -0
- package/{commands → workflows}/auth-context.js +13 -7
- package/workflows/batch-pens.js +1647 -0
- package/workflows/batch-target.js +184 -0
- package/workflows/classic-convert.js +241 -0
- package/workflows/clone-pen.js +381 -0
- package/{commands → workflows}/create-pen.js +59 -84
- package/workflows/discover-pens.js +91 -0
- package/workflows/fork-pen.js +314 -0
- package/workflows/missing-pen.js +212 -0
- package/workflows/pull-pen.js +204 -0
- package/workflows/push-pen.js +318 -0
- package/{commands → workflows}/scaffold.js +4 -3
- package/workflows/sync-pen.js +227 -0
- package/{commands → workflows}/unowned-pen.js +16 -12
- package/commands/auth.js +0 -593
- package/commands/meta.js +0 -184
- package/utils/prompts.js +0 -316
- /package/{types.js → api/types.js} +0 -0
package/commands/deploy.js
CHANGED
|
@@ -1,191 +1,186 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { CodePenClient } from '../api/client.js';
|
|
3
|
-
import { findNearestConfig
|
|
3
|
+
import { findNearestConfig } from '../config/project.js';
|
|
4
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
6
|
+
import { assertValidVersionLabel, resolveAccessOrVisibility } from '../utils/cli-options.js';
|
|
4
7
|
import { fmt, shortId } from '../utils/format.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
import { printJsonResponse } from '../utils/json.js';
|
|
9
|
+
import { defaultOutput } from '../utils/output.js';
|
|
10
|
+
import { isInteractive } from '../utils/prompts/index.js';
|
|
11
|
+
import { getGlobalProfileOption, resolveCommandAuth } from '../workflows/auth-context.js';
|
|
12
|
+
import { createPenFromDirectory } from '../workflows/create-pen.js';
|
|
13
|
+
import { fetchLinkedPenOrHandleMissing } from '../workflows/missing-pen.js';
|
|
14
|
+
import { executePush } from '../workflows/push-pen.js';
|
|
15
|
+
export async function runDeployCommand(options = {}) {
|
|
16
|
+
const output = options.output ?? defaultOutput;
|
|
17
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
18
|
+
const jsonMode = Boolean(options.json);
|
|
19
|
+
const interactive = !jsonMode && (options.interactive ?? isInteractive());
|
|
20
|
+
assertValidVersionLabel(options.label);
|
|
21
|
+
const resolvedAccess = resolveAccessOrVisibility(options.access, options.visibility);
|
|
22
|
+
const nearest = await findNearestConfig(cwd);
|
|
23
|
+
let project = nearest?.linked
|
|
24
|
+
? {
|
|
25
|
+
rootDir: nearest.rootDir,
|
|
26
|
+
configPath: nearest.configPath,
|
|
27
|
+
config: nearest.config,
|
|
25
28
|
}
|
|
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
|
-
|
|
29
|
+
: null;
|
|
30
|
+
let versionIdToDeploy = options.version;
|
|
31
|
+
let client;
|
|
32
|
+
let activeProfile;
|
|
33
|
+
let createdPen = false;
|
|
34
|
+
let pushedChanges = false;
|
|
35
|
+
if (!project) {
|
|
36
|
+
if (options.push === false || options.version) {
|
|
37
|
+
throw new CliError(404, nearest
|
|
38
|
+
? `${PROJECT_CONFIG_FILENAME} in ${nearest.rootDir} only contains Pen info and is not linked to an online Pen yet.\n` +
|
|
39
|
+
'Run `cdpn deploy` without --no-push/--version to create and link it first.'
|
|
40
|
+
: `No ${PROJECT_CONFIG_FILENAME} found in this directory or any parent directory.\n` +
|
|
41
|
+
'Run `cdpn clone <url>` to clone a Pen or run `cdpn deploy` without --no-push/--version to create one first.');
|
|
42
|
+
}
|
|
43
|
+
const targetDir = nearest ? nearest.rootDir : cwd;
|
|
44
|
+
const folderDisplay = path.relative(cwd, targetDir) || '.';
|
|
45
|
+
if (!jsonMode) {
|
|
46
|
+
output.log(fmt.dim(nearest
|
|
47
|
+
? `Found unlinked ${PROJECT_CONFIG_FILENAME} with saved Pen info — pushing this local folder as a new CodePen 2.0 Pen before deploying.`
|
|
48
|
+
: `No ${PROJECT_CONFIG_FILENAME} found — pushing this local folder as a new CodePen 2.0 Pen before deploying.`));
|
|
49
|
+
}
|
|
50
|
+
const created = await createPenFromDirectory({
|
|
51
|
+
targetDir,
|
|
52
|
+
folderDisplay,
|
|
53
|
+
explicitProfile: options.explicitProfile,
|
|
54
|
+
title: options.title,
|
|
55
|
+
access: resolvedAccess,
|
|
56
|
+
password: options.password,
|
|
57
|
+
force: options.force,
|
|
58
|
+
wait: true,
|
|
59
|
+
silent: jsonMode,
|
|
60
|
+
output,
|
|
61
|
+
baseUrl: options.baseUrl,
|
|
62
|
+
interactive,
|
|
63
|
+
env: options.env,
|
|
64
|
+
homeDir: options.homeDir,
|
|
65
|
+
prompts: options.prompts,
|
|
66
|
+
});
|
|
67
|
+
if (!created) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (created.build?.status === 'Failed') {
|
|
71
|
+
throw new CliError(422, 'Aborting deploy because the build failed. Fix build errors and try again.', {
|
|
72
|
+
pen_id: created.pen.id,
|
|
73
|
+
version_id: created.versionId,
|
|
74
|
+
build: created.build,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
createdPen = true;
|
|
78
|
+
pushedChanges = true;
|
|
79
|
+
project = created.project;
|
|
80
|
+
versionIdToDeploy = created.versionId ?? undefined;
|
|
81
|
+
activeProfile = created.auth.profile;
|
|
82
|
+
client = new CodePenClient({ apiKey: created.auth.apiKey, baseUrl: options.baseUrl });
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const auth = await resolveCommandAuth({
|
|
86
|
+
explicitProfile: options.explicitProfile,
|
|
87
|
+
project,
|
|
88
|
+
interactive,
|
|
89
|
+
persistProfileToProject: !jsonMode,
|
|
90
|
+
output,
|
|
91
|
+
env: options.env,
|
|
92
|
+
homeDir: options.homeDir,
|
|
93
|
+
selectProfile: options.prompts?.select,
|
|
94
|
+
});
|
|
95
|
+
activeProfile = auth.profile;
|
|
96
|
+
client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
97
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
98
|
+
client,
|
|
99
|
+
project,
|
|
100
|
+
auth,
|
|
101
|
+
commandName: 'deploy',
|
|
102
|
+
interactive,
|
|
103
|
+
json: jsonMode,
|
|
104
|
+
output,
|
|
105
|
+
prompts: options.prompts,
|
|
106
|
+
});
|
|
107
|
+
if (!penLookup.found) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (!versionIdToDeploy && options.push !== false) {
|
|
111
|
+
const pushResult = await executePush(client, project, {
|
|
62
112
|
force: options.force,
|
|
113
|
+
label: options.label,
|
|
63
114
|
wait: true,
|
|
64
|
-
|
|
65
|
-
|
|
115
|
+
prefetchedPen: penLookup.pen,
|
|
116
|
+
silent: jsonMode,
|
|
117
|
+
output,
|
|
66
118
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (created.build?.status === 'Failed') {
|
|
119
|
+
pushedChanges = pushResult.pushed;
|
|
120
|
+
if (pushResult.build?.status === 'Failed') {
|
|
71
121
|
throw new CliError(422, 'Aborting deploy because the build failed. Fix build errors and try again.', {
|
|
72
|
-
pen_id:
|
|
73
|
-
version_id:
|
|
74
|
-
build:
|
|
122
|
+
pen_id: project.config.pen_id,
|
|
123
|
+
version_id: pushResult.versionId,
|
|
124
|
+
build: pushResult.build,
|
|
75
125
|
});
|
|
76
126
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
project = created.project;
|
|
80
|
-
versionIdToDeploy = created.versionId ?? undefined;
|
|
81
|
-
activeProfile = created.auth.profile;
|
|
82
|
-
client = new CodePenClient({ apiKey: created.auth.apiKey });
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
const auth = await resolveCommandAuth({
|
|
86
|
-
explicitProfile,
|
|
87
|
-
project,
|
|
88
|
-
interactive: !options.json && isInteractive(),
|
|
89
|
-
persistProfileToProject: !options.json,
|
|
90
|
-
});
|
|
91
|
-
activeProfile = auth.profile;
|
|
92
|
-
client = new CodePenClient({ apiKey: auth.apiKey });
|
|
93
|
-
if (!versionIdToDeploy && options.push !== false) {
|
|
94
|
-
const pushResult = await executePush(client, project, {
|
|
95
|
-
force: options.force,
|
|
96
|
-
label: options.label,
|
|
97
|
-
wait: true,
|
|
98
|
-
silent: Boolean(options.json),
|
|
99
|
-
});
|
|
100
|
-
pushedChanges = pushResult.pushed;
|
|
101
|
-
if (pushResult.build?.status === 'Failed') {
|
|
102
|
-
throw new CliError(422, 'Aborting deploy because the build failed. Fix build errors and try again.', {
|
|
103
|
-
pen_id: project.config.pen_id,
|
|
104
|
-
version_id: pushResult.versionId,
|
|
105
|
-
build: pushResult.build,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (pushResult.versionId) {
|
|
109
|
-
versionIdToDeploy = pushResult.versionId;
|
|
110
|
-
}
|
|
127
|
+
if (pushResult.versionId) {
|
|
128
|
+
versionIdToDeploy = pushResult.versionId;
|
|
111
129
|
}
|
|
112
130
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
}
|
|
132
|
+
if (!jsonMode) {
|
|
133
|
+
output.log(versionIdToDeploy
|
|
134
|
+
? `\nDeploying version ${fmt.dim(shortId(versionIdToDeploy))}…`
|
|
135
|
+
: '\nDeploying saved head…');
|
|
136
|
+
}
|
|
137
|
+
const deployment = await client.deployPen(project.config.pen_id, versionIdToDeploy);
|
|
138
|
+
if (jsonMode) {
|
|
139
|
+
printJsonResponse(200, 'Deployed successfully.', {
|
|
140
|
+
pen_id: project.config.pen_id,
|
|
141
|
+
profile: activeProfile,
|
|
142
|
+
created: createdPen,
|
|
143
|
+
pushed: pushedChanges,
|
|
144
|
+
version_id: deployment.version_id,
|
|
145
|
+
deployment,
|
|
146
|
+
}, output);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
output.log(`${fmt.green('✓')} Deployed successfully!`);
|
|
131
150
|
if (activeProfile) {
|
|
132
|
-
|
|
151
|
+
output.log(` Profile: ${fmt.cyan(activeProfile)}`);
|
|
133
152
|
}
|
|
134
|
-
|
|
135
|
-
|
|
153
|
+
output.log(` URL: ${fmt.cyan(deployment.url)}`);
|
|
154
|
+
output.log(` Version: ${fmt.dim(shortId(deployment.version_id))}`);
|
|
136
155
|
if (deployment.custom_domains.length > 0) {
|
|
137
|
-
|
|
156
|
+
output.log(` Domains: ${deployment.custom_domains.map((d) => fmt.cyan(`https://${d}`)).join(', ')}`);
|
|
138
157
|
}
|
|
139
|
-
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
penId: project.config.pen_id,
|
|
161
|
+
profile: activeProfile,
|
|
162
|
+
created: createdPen,
|
|
163
|
+
pushed: pushedChanges,
|
|
164
|
+
deployment,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export function registerDeployCommand(program) {
|
|
140
168
|
program
|
|
141
|
-
.command('
|
|
142
|
-
.description('
|
|
143
|
-
.option('-
|
|
144
|
-
.option('--
|
|
169
|
+
.command('deploy')
|
|
170
|
+
.description('Push local changes and deploy the Pen to CodePen Hosting')
|
|
171
|
+
.option('--no-push', 'Deploy the current remote saved head without pushing local files first')
|
|
172
|
+
.option('--version <version-id>', 'Deploy a specific saved version ID instead of pushing')
|
|
173
|
+
.option('-f, --force', 'Overwrite remote head if moved (or skip missing index.html prompt on first push)')
|
|
174
|
+
.option('-m, --label <label>', 'Label for the saved version created by push')
|
|
175
|
+
.option('-t, --title <title>', 'Title for a new Pen when deploying an unlinked folder for the first time')
|
|
176
|
+
.option('--access <level>', 'Privacy for a new Pen: Public, Private, Protected, or Collaborators')
|
|
177
|
+
.option('--visibility <level>', 'Alias for --access')
|
|
178
|
+
.option('--password <password>', 'Password for a new Protected Pen (min 8 chars)')
|
|
179
|
+
.option('--json', 'Output deployment result as JSON')
|
|
145
180
|
.action(async (options, command) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const auth = await resolveCommandAuth({
|
|
181
|
+
await runDeployCommand({
|
|
182
|
+
...options,
|
|
149
183
|
explicitProfile: getGlobalProfileOption(command),
|
|
150
|
-
project,
|
|
151
|
-
interactive,
|
|
152
|
-
persistProfileToProject: !options.json,
|
|
153
184
|
});
|
|
154
|
-
const client = new CodePenClient({ apiKey: auth.apiKey });
|
|
155
|
-
const pen = await client.getPen(project.config.pen_id);
|
|
156
|
-
if (!pen.deployment) {
|
|
157
|
-
if (options.json) {
|
|
158
|
-
printJsonResponse(200, 'This Pen is not currently deployed.', {
|
|
159
|
-
pen_id: project.config.pen_id,
|
|
160
|
-
profile: auth.profile,
|
|
161
|
-
undeployed: false,
|
|
162
|
-
previous_deployment: null,
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
console.log(fmt.dim('This Pen is not currently deployed.'));
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (!options.yes) {
|
|
170
|
-
if (!interactive) {
|
|
171
|
-
throw new CliError(400, 'Refusing to undeploy in non-interactive mode without --yes.');
|
|
172
|
-
}
|
|
173
|
-
const ok = await promptConfirm(`Take down live deployment at ${fmt.cyan(pen.deployment.url)}?`, false);
|
|
174
|
-
if (!ok) {
|
|
175
|
-
console.log('Aborted.');
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
await client.undeployPen(project.config.pen_id);
|
|
180
|
-
if (options.json) {
|
|
181
|
-
printJsonResponse(200, 'Deployment taken down. Your Pen and saved versions remain intact.', {
|
|
182
|
-
pen_id: project.config.pen_id,
|
|
183
|
-
profile: auth.profile,
|
|
184
|
-
undeployed: true,
|
|
185
|
-
previous_deployment: pen.deployment,
|
|
186
|
-
});
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
console.log(`${fmt.green('✓')} Deployment taken down. Your Pen and saved versions remain intact.`);
|
|
190
185
|
});
|
|
191
186
|
}
|
package/commands/domains.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { CodePenClient } from '../api/client.js';
|
|
2
2
|
import { requireProject } from '../config/project.js';
|
|
3
|
+
import { CliError } from '../errors.js';
|
|
4
|
+
import { resolveInheritedJsonOption } from '../utils/cli-options.js';
|
|
3
5
|
import { fmt, formatTable } from '../utils/format.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { printJsonResponse } from '../utils/json.js';
|
|
7
|
+
import { defaultOutput } from '../utils/output.js';
|
|
8
|
+
import { isInteractive, promptConfirm } from '../utils/prompts/index.js';
|
|
9
|
+
import { getGlobalProfileOption, resolveCommandAuth } from '../workflows/auth-context.js';
|
|
10
|
+
import { fetchLinkedPenOrHandleMissing, } from '../workflows/missing-pen.js';
|
|
11
|
+
export function renderDomains(domains, defaultUrl, output = defaultOutput) {
|
|
8
12
|
if (defaultUrl) {
|
|
9
|
-
|
|
13
|
+
output.log(`Default URL: ${fmt.cyan(defaultUrl)}`);
|
|
10
14
|
}
|
|
11
15
|
else {
|
|
12
|
-
|
|
16
|
+
output.log(`Default URL: ${fmt.dim('not deployed (run `cdpn deploy` to deploy)')}`);
|
|
13
17
|
}
|
|
14
|
-
|
|
18
|
+
output.log('');
|
|
15
19
|
if (domains.length === 0) {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
output.log(fmt.dim('No custom domains configured for this Pen.'));
|
|
21
|
+
output.log(fmt.dim('Add one with: cdpn domains add <host>'));
|
|
18
22
|
return;
|
|
19
23
|
}
|
|
20
24
|
const rows = domains.map((d) => {
|
|
@@ -25,19 +29,20 @@ export function renderDomains(domains, defaultUrl) {
|
|
|
25
29
|
: fmt.yellow(d.status);
|
|
26
30
|
return [fmt.cyan(d.host), status, d.cname_record, d.a_record];
|
|
27
31
|
});
|
|
28
|
-
|
|
32
|
+
output.log(formatTable(['Host', 'Status', 'CNAME', 'A Record'], rows));
|
|
29
33
|
const needingDns = domains.filter((d) => d.status !== 'Verified' && d.dns.length > 0);
|
|
30
34
|
if (needingDns.length > 0) {
|
|
31
|
-
|
|
35
|
+
output.log('\nRequired DNS records:');
|
|
32
36
|
for (const domain of needingDns) {
|
|
33
|
-
|
|
37
|
+
output.log(` ${fmt.bold(domain.host)}:`);
|
|
34
38
|
for (const rec of domain.dns) {
|
|
35
|
-
|
|
39
|
+
output.log(` ${fmt.cyan(rec.type.padEnd(6))} ${rec.name} → ${fmt.bold(rec.value)}`);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
|
-
export async function
|
|
44
|
+
export async function runDomainsListCommand(options = {}) {
|
|
45
|
+
const output = options.output ?? defaultOutput;
|
|
41
46
|
const cwd = options.cwd ?? process.cwd();
|
|
42
47
|
const interactive = (options.interactive ?? isInteractive()) && !options.json;
|
|
43
48
|
const project = await requireProject(cwd);
|
|
@@ -46,14 +51,26 @@ export async function listPenDomains(options = {}) {
|
|
|
46
51
|
project,
|
|
47
52
|
interactive,
|
|
48
53
|
persistProfileToProject: !options.json,
|
|
54
|
+
output,
|
|
49
55
|
env: options.env,
|
|
50
56
|
homeDir: options.homeDir,
|
|
51
57
|
});
|
|
52
58
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
53
|
-
const
|
|
54
|
-
client
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
60
|
+
client,
|
|
61
|
+
project,
|
|
62
|
+
auth,
|
|
63
|
+
commandName: 'domains',
|
|
64
|
+
interactive,
|
|
65
|
+
json: options.json,
|
|
66
|
+
output,
|
|
67
|
+
prompts: options.prompts,
|
|
68
|
+
});
|
|
69
|
+
if (!penLookup.found) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const pen = penLookup.pen;
|
|
73
|
+
const domains = await client.listDomains(project.config.pen_id);
|
|
57
74
|
const defaultUrl = pen.deployment?.url ?? null;
|
|
58
75
|
if (options.json) {
|
|
59
76
|
const message = domains.length === 0
|
|
@@ -62,14 +79,15 @@ export async function listPenDomains(options = {}) {
|
|
|
62
79
|
printJsonResponse(200, message, {
|
|
63
80
|
default_url: defaultUrl,
|
|
64
81
|
domains,
|
|
65
|
-
});
|
|
82
|
+
}, output);
|
|
66
83
|
}
|
|
67
84
|
else {
|
|
68
|
-
renderDomains(domains, defaultUrl);
|
|
85
|
+
renderDomains(domains, defaultUrl, output);
|
|
69
86
|
}
|
|
70
87
|
return { defaultUrl, domains, pen, project, auth };
|
|
71
88
|
}
|
|
72
|
-
export async function
|
|
89
|
+
export async function runDomainsAddCommand(host, options = {}) {
|
|
90
|
+
const output = options.output ?? defaultOutput;
|
|
73
91
|
const cleanHost = host.trim().replace(/^https?:\/\//i, '').replace(/\/+$/, '');
|
|
74
92
|
if (!cleanHost || !/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(cleanHost)) {
|
|
75
93
|
throw new CliError(400, `Invalid domain host: "${host}". Provide a hostname like www.example.com.`);
|
|
@@ -82,10 +100,24 @@ export async function addPenDomain(host, options = {}) {
|
|
|
82
100
|
project,
|
|
83
101
|
interactive,
|
|
84
102
|
persistProfileToProject: !options.json,
|
|
103
|
+
output,
|
|
85
104
|
env: options.env,
|
|
86
105
|
homeDir: options.homeDir,
|
|
87
106
|
});
|
|
88
107
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
108
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
109
|
+
client,
|
|
110
|
+
project,
|
|
111
|
+
auth,
|
|
112
|
+
commandName: 'domains add',
|
|
113
|
+
interactive,
|
|
114
|
+
json: options.json,
|
|
115
|
+
output,
|
|
116
|
+
prompts: options.prompts,
|
|
117
|
+
});
|
|
118
|
+
if (!penLookup.found) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
89
121
|
const domains = await client.addDomain(project.config.pen_id, cleanHost);
|
|
90
122
|
const pen = await client.getPen(project.config.pen_id);
|
|
91
123
|
const defaultUrl = pen.deployment?.url ?? null;
|
|
@@ -94,15 +126,16 @@ export async function addPenDomain(host, options = {}) {
|
|
|
94
126
|
host: cleanHost,
|
|
95
127
|
default_url: defaultUrl,
|
|
96
128
|
domains,
|
|
97
|
-
});
|
|
129
|
+
}, output);
|
|
98
130
|
}
|
|
99
131
|
else {
|
|
100
|
-
|
|
101
|
-
renderDomains(domains, defaultUrl);
|
|
132
|
+
output.log(`${fmt.green('✓')} Added custom domain ${fmt.cyan(cleanHost)}.\n`);
|
|
133
|
+
renderDomains(domains, defaultUrl, output);
|
|
102
134
|
}
|
|
103
135
|
return { defaultUrl, domains, pen, project, auth };
|
|
104
136
|
}
|
|
105
|
-
export async function
|
|
137
|
+
export async function runDomainsDeleteCommand(host, options = {}) {
|
|
138
|
+
const output = options.output ?? defaultOutput;
|
|
106
139
|
const cleanHost = host.trim().replace(/^https?:\/\//i, '').replace(/\/+$/, '');
|
|
107
140
|
if (!cleanHost) {
|
|
108
141
|
throw new CliError(400, `Invalid domain host: "${host}". Provide a hostname like www.example.com.`);
|
|
@@ -115,7 +148,7 @@ export async function deletePenDomain(host, options = {}) {
|
|
|
115
148
|
}
|
|
116
149
|
const ok = await confirmImpl(`Delete custom domain ${fmt.cyan(cleanHost)}?`, false);
|
|
117
150
|
if (!ok) {
|
|
118
|
-
|
|
151
|
+
output.log('Aborted.');
|
|
119
152
|
return null;
|
|
120
153
|
}
|
|
121
154
|
}
|
|
@@ -126,10 +159,24 @@ export async function deletePenDomain(host, options = {}) {
|
|
|
126
159
|
project,
|
|
127
160
|
interactive,
|
|
128
161
|
persistProfileToProject: !options.json,
|
|
162
|
+
output,
|
|
129
163
|
env: options.env,
|
|
130
164
|
homeDir: options.homeDir,
|
|
131
165
|
});
|
|
132
166
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
167
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
168
|
+
client,
|
|
169
|
+
project,
|
|
170
|
+
auth,
|
|
171
|
+
commandName: 'domains delete',
|
|
172
|
+
interactive,
|
|
173
|
+
json: options.json,
|
|
174
|
+
output,
|
|
175
|
+
prompts: options.prompts,
|
|
176
|
+
});
|
|
177
|
+
if (!penLookup.found) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
133
180
|
const remaining = await client.removeDomain(project.config.pen_id, cleanHost);
|
|
134
181
|
const pen = await client.getPen(project.config.pen_id);
|
|
135
182
|
const defaultUrl = pen.deployment?.url ?? null;
|
|
@@ -138,24 +185,21 @@ export async function deletePenDomain(host, options = {}) {
|
|
|
138
185
|
host: cleanHost,
|
|
139
186
|
default_url: defaultUrl,
|
|
140
187
|
domains: remaining,
|
|
141
|
-
});
|
|
188
|
+
}, output);
|
|
142
189
|
}
|
|
143
190
|
else {
|
|
144
|
-
|
|
145
|
-
renderDomains(remaining, defaultUrl);
|
|
191
|
+
output.log(`${fmt.green('✓')} Deleted custom domain ${fmt.cyan(cleanHost)}.\n`);
|
|
192
|
+
renderDomains(remaining, defaultUrl, output);
|
|
146
193
|
}
|
|
147
194
|
return { defaultUrl, domains: remaining, pen, project, auth };
|
|
148
195
|
}
|
|
149
|
-
function resolveDomainsJsonOption(options, command) {
|
|
150
|
-
return Boolean(options.json || command.parent?.opts().json);
|
|
151
|
-
}
|
|
152
196
|
export function registerDomainsCommand(program) {
|
|
153
197
|
const domainsCmd = program
|
|
154
198
|
.command('domains')
|
|
155
199
|
.description('Show the default deployed URL and manage custom domains for the Pen’s deployment')
|
|
156
200
|
.option('--json', 'Output default deployed URL and domains as JSON')
|
|
157
201
|
.action(async (options, command) => {
|
|
158
|
-
await
|
|
202
|
+
await runDomainsListCommand({
|
|
159
203
|
json: options.json,
|
|
160
204
|
explicitProfile: getGlobalProfileOption(command),
|
|
161
205
|
});
|
|
@@ -166,8 +210,8 @@ export function registerDomainsCommand(program) {
|
|
|
166
210
|
.description('Show the default deployed URL, custom domains, and required DNS records')
|
|
167
211
|
.option('--json', 'Output default deployed URL and domains as JSON')
|
|
168
212
|
.action(async (options, command) => {
|
|
169
|
-
await
|
|
170
|
-
json:
|
|
213
|
+
await runDomainsListCommand({
|
|
214
|
+
json: resolveInheritedJsonOption(options, command),
|
|
171
215
|
explicitProfile: getGlobalProfileOption(command),
|
|
172
216
|
});
|
|
173
217
|
});
|
|
@@ -176,8 +220,8 @@ export function registerDomainsCommand(program) {
|
|
|
176
220
|
.description('Attach a custom domain (e.g. www.example.com) to this Pen’s deployment')
|
|
177
221
|
.option('--json', 'Output default deployed URL and updated domains as JSON')
|
|
178
222
|
.action(async (host, options, command) => {
|
|
179
|
-
await
|
|
180
|
-
json:
|
|
223
|
+
await runDomainsAddCommand(host, {
|
|
224
|
+
json: resolveInheritedJsonOption(options, command),
|
|
181
225
|
explicitProfile: getGlobalProfileOption(command),
|
|
182
226
|
});
|
|
183
227
|
});
|
|
@@ -188,9 +232,9 @@ export function registerDomainsCommand(program) {
|
|
|
188
232
|
.option('-y, --yes', 'Skip confirmation prompt')
|
|
189
233
|
.option('--json', 'Output default deployed URL and remaining domains as JSON')
|
|
190
234
|
.action(async (host, options, command) => {
|
|
191
|
-
await
|
|
235
|
+
await runDomainsDeleteCommand(host, {
|
|
192
236
|
yes: options.yes,
|
|
193
|
-
json:
|
|
237
|
+
json: resolveInheritedJsonOption(options, command),
|
|
194
238
|
explicitProfile: getGlobalProfileOption(command),
|
|
195
239
|
});
|
|
196
240
|
});
|