codepen-commander 0.0.0-stage → 1.1.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.
@@ -0,0 +1,249 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { CodePenClient } from '../api/client.js';
4
+ import { buildSyncedFileMap, hasProjectConfigInDir, PROJECT_CONFIG_FILENAME, writeProjectConfig, } from '../config/project.js';
5
+ import { scanLocalFiles } from '../sync/fs.js';
6
+ import { syncRemoteFilesToDisk } from '../sync/materialize.js';
7
+ import { fmt, printBuildSummary, shortId } from '../utils/format.js';
8
+ import { extractHtmlTitle } from '../utils/html.js';
9
+ import { CliError } from '../utils/json.js';
10
+ import { isInteractive, promptConfirm, promptSecret, promptSelect, promptText, } from '../utils/prompts.js';
11
+ import { resolveCommandAuth } from './auth-context.js';
12
+ const VALID_ACCESS = new Set(['public', 'private', 'protected', 'collaborators']);
13
+ export function normalizeAccess(raw) {
14
+ if (!raw)
15
+ return undefined;
16
+ const lower = raw.trim().toLowerCase();
17
+ if (!VALID_ACCESS.has(lower)) {
18
+ throw new CliError(400, `Invalid access level "${raw}". Use: Public, Private, Protected, or Collaborators.`);
19
+ }
20
+ return (lower[0].toUpperCase() + lower.slice(1));
21
+ }
22
+ /**
23
+ * Validates or interactively prompts for Pen visibility (`Public` default, `Private`,
24
+ * `Protected`, or `Collaborators`) and password when `Protected` is chosen.
25
+ */
26
+ export async function resolveVisibilityAndPassword(options) {
27
+ const selectImpl = options.prompts?.select ?? promptSelect;
28
+ const secretImpl = options.prompts?.secret ?? promptSecret;
29
+ let access = normalizeAccess(options.rawAccess);
30
+ if (access === 'Protected' && options.rawPassword !== undefined && options.rawPassword.length < 8) {
31
+ throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
32
+ }
33
+ if (access === 'Protected' && !options.rawPassword && !options.interactive) {
34
+ throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
35
+ }
36
+ if (!access) {
37
+ if (options.interactive) {
38
+ access = await selectImpl('Pen visibility:', [
39
+ { value: 'Public', label: 'Public', description: 'visible to everyone (default)' },
40
+ { value: 'Private', label: 'Private', description: 'visible only to you / your team' },
41
+ {
42
+ value: 'Protected',
43
+ label: 'Protected',
44
+ description: 'password-protected (min 8 characters)',
45
+ },
46
+ {
47
+ value: 'Collaborators',
48
+ label: 'Collaborators',
49
+ description: 'visible only to you and collaborators',
50
+ },
51
+ ], 0);
52
+ }
53
+ else {
54
+ access = 'Public';
55
+ }
56
+ }
57
+ let password = options.rawPassword;
58
+ if (access === 'Protected' && (!password || password.length < 8)) {
59
+ if (!options.interactive) {
60
+ throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
61
+ }
62
+ for (;;) {
63
+ password = await secretImpl('Password for Protected Pen (min 8 characters)');
64
+ if (password.length >= 8)
65
+ break;
66
+ console.log(fmt.yellow('Password must be at least 8 characters.'));
67
+ }
68
+ }
69
+ return {
70
+ access,
71
+ ...(access === 'Protected' && password ? { password } : {}),
72
+ };
73
+ }
74
+ export function printMissingIndexHtmlWarning(targetDir, fileCount) {
75
+ const headline = ' WARNING: No index.html found in this folder! ';
76
+ const border = '═'.repeat(headline.length);
77
+ console.log('');
78
+ console.log(fmt.yellow(fmt.bold(`╔${border}╗`)));
79
+ console.log(fmt.yellow(fmt.bold(`║${headline}║`)));
80
+ console.log(fmt.yellow(fmt.bold(`╚${border}╝`)));
81
+ console.log(fmt.yellow(`CodePen expects an index.html file at the root of your demo.\n` +
82
+ `Double-check that you are in the right folder before pushing:\n` +
83
+ ` Folder: ${targetDir} (${fileCount} file(s) found)`));
84
+ console.log('');
85
+ }
86
+ /**
87
+ * First-time Pen creation flow used by `cdpn push` and `cdpn deploy` when invoked inside
88
+ * an unlinked local demo folder:
89
+ *
90
+ * 1. Checks for `/index.html`; if absent, displays a prominent warning and asks for confirmation.
91
+ * 2. Resolves or asks which CodePen account/profile to push to (when multiple keys are in `~/.cdpn`).
92
+ * 3. Asks for a title (pre-filled from `index.html`'s `<title>` when available).
93
+ * 4. Asks for visibility (`Public` default, `Private`, `Protected`, or `Collaborators`).
94
+ */
95
+ export async function createPenFromDirectory(options) {
96
+ const silent = Boolean(options.silent);
97
+ const interactive = silent ? false : (options.interactive ?? isInteractive());
98
+ const confirmImpl = options.prompts?.confirm ?? promptConfirm;
99
+ const textImpl = options.prompts?.text ?? promptText;
100
+ const selectImpl = options.prompts?.select ?? promptSelect;
101
+ // Validate --access / --password early before prompting or scanning
102
+ const prevalidatedAccess = normalizeAccess(options.access);
103
+ if (prevalidatedAccess === 'Protected' && options.password !== undefined && options.password.length < 8) {
104
+ throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
105
+ }
106
+ if (prevalidatedAccess === 'Protected' && !options.password && !interactive) {
107
+ throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
108
+ }
109
+ const targetDir = path.resolve(options.targetDir);
110
+ const folderDisplay = options.folderDisplay;
111
+ if (await hasProjectConfigInDir(targetDir)) {
112
+ throw new CliError(409, `${targetDir} already contains ${PROJECT_CONFIG_FILENAME}. Use \`cdpn push\` to update the existing Pen.`);
113
+ }
114
+ const scanned = await scanLocalFiles(targetDir);
115
+ if (scanned.size === 0) {
116
+ throw new CliError(400, `No ${PROJECT_CONFIG_FILENAME} found and no syncable files in ${targetDir}.\n` +
117
+ 'Run `cdpn clone <url>` to clone an existing Pen or `cdpn new` to scaffold a brand-new Pen.');
118
+ }
119
+ const indexFile = scanned.get('/index.html');
120
+ // 1. Check for index.html before pushing a local demo for the first time
121
+ if (!indexFile) {
122
+ if (!silent) {
123
+ printMissingIndexHtmlWarning(targetDir, scanned.size);
124
+ }
125
+ if (!options.force) {
126
+ if (!interactive) {
127
+ throw new CliError(400, `No index.html found in ${targetDir}. Pass --force to push this folder without an index.html.`);
128
+ }
129
+ const ok = await confirmImpl('Are you sure you want to push this folder without an index.html?', false);
130
+ if (!ok) {
131
+ console.log('Aborted.');
132
+ return null;
133
+ }
134
+ }
135
+ }
136
+ // 2. Ask which account/profile to push to (only prompts if multiple keys exist in ~/.cdpn)
137
+ const auth = await resolveCommandAuth({
138
+ explicitProfile: options.explicitProfile,
139
+ promptMessage: 'Which CodePen account/profile would you like to push to?',
140
+ interactive,
141
+ env: options.env,
142
+ homeDir: options.homeDir,
143
+ selectProfile: selectImpl,
144
+ });
145
+ const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
146
+ // 3. Determine title (defaulting to index.html's <title> when present)
147
+ const htmlTitle = indexFile && !indexFile.isBinary && indexFile.textContent
148
+ ? extractHtmlTitle(indexFile.textContent)
149
+ : null;
150
+ const fallbackTitle = path.basename(targetDir) || 'Untitled';
151
+ const defaultTitle = htmlTitle ?? fallbackTitle;
152
+ let title = options.title?.trim();
153
+ if (!title) {
154
+ if (interactive) {
155
+ title = (await textImpl('Pen title', defaultTitle)).trim() || defaultTitle;
156
+ }
157
+ else {
158
+ title = defaultTitle;
159
+ }
160
+ }
161
+ // 4. Ask for visibility (Public by default, Private, Protected, or Collaborators)
162
+ const { access, password } = await resolveVisibilityAndPassword({
163
+ rawAccess: options.access,
164
+ rawPassword: options.password,
165
+ interactive,
166
+ prompts: options.prompts,
167
+ });
168
+ const textFiles = [];
169
+ const binaryFiles = [];
170
+ for (const [filePath, lf] of scanned) {
171
+ if (lf.isBinary && lf.buffer.length > 0) {
172
+ binaryFiles.push({ path: filePath, content: lf.buffer });
173
+ }
174
+ else {
175
+ textFiles.push({ path: filePath, content: lf.textContent ?? '' });
176
+ }
177
+ }
178
+ const shouldWait = options.wait !== false;
179
+ if (!silent) {
180
+ console.log(`\nCreating new Pen from ${textFiles.length + binaryFiles.length} local file(s)…`);
181
+ }
182
+ const created = await client.createPen({
183
+ ...(title ? { title } : {}),
184
+ ...(options.description ? { description: options.description } : {}),
185
+ ...(options.tags && options.tags.length > 0 ? { tags: options.tags } : {}),
186
+ access,
187
+ ...(password ? { password } : {}),
188
+ ...(options.template ? { template: true } : {}),
189
+ files: textFiles,
190
+ wait: shouldWait ? 45 : 0,
191
+ }, binaryFiles);
192
+ let finalBuild = created.build ?? null;
193
+ if (finalBuild && shouldWait) {
194
+ finalBuild = await client.settleBuild(finalBuild);
195
+ if (!silent) {
196
+ printBuildSummary(finalBuild);
197
+ }
198
+ }
199
+ await fs.mkdir(targetDir, { recursive: true });
200
+ const finalVersionId = finalBuild?.version_id ?? created.saved_version?.id ?? null;
201
+ const remoteFiles = finalVersionId
202
+ ? (await client.getVersion(finalVersionId)).files ?? (await client.getPenFiles(created.id))
203
+ : await client.getPenFiles(created.id);
204
+ const materialized = await syncRemoteFilesToDisk({
205
+ client,
206
+ rootDir: targetDir,
207
+ remoteFiles,
208
+ pruneRemoved: false,
209
+ });
210
+ const config = {
211
+ url: created.urls.editor,
212
+ pen_id: created.id,
213
+ ...(auth.profile ? { profile: auth.profile } : {}),
214
+ last_synced_version_id: finalVersionId,
215
+ editor: created.editor,
216
+ files: buildSyncedFileMap(remoteFiles, materialized.localSha256ByPath),
217
+ };
218
+ const configPath = await writeProjectConfig(targetDir, config);
219
+ if (finalBuild?.status === 'Failed') {
220
+ if (!silent) {
221
+ console.log(`\n${fmt.yellow('!')} Created Pen ${fmt.bold(created.title || 'Untitled')} ${fmt.dim(`(${created.id})`)}, but the initial build failed.`);
222
+ }
223
+ process.exitCode = 1;
224
+ }
225
+ else if (!silent) {
226
+ console.log(`\n${fmt.green('✓')} Created Pen ${fmt.bold(created.title || 'Untitled')} ${fmt.dim(`(${created.id})`)}`);
227
+ }
228
+ if (!silent) {
229
+ if (auth.profile) {
230
+ console.log(` Profile: ${fmt.cyan(auth.profile)}`);
231
+ }
232
+ console.log(` Visibility: ${created.access}`);
233
+ console.log(` Folder: ${fmt.cyan(folderDisplay)}`);
234
+ console.log(` Editor: ${fmt.cyan(created.urls.editor)}`);
235
+ console.log(` Preview: ${fmt.cyan(created.urls.preview)}`);
236
+ console.log(` Version: ${fmt.dim(shortId(finalVersionId))}`);
237
+ }
238
+ return {
239
+ pen: created,
240
+ versionId: finalVersionId,
241
+ build: finalBuild,
242
+ auth,
243
+ project: {
244
+ rootDir: targetDir,
245
+ configPath,
246
+ config,
247
+ },
248
+ };
249
+ }
@@ -0,0 +1,98 @@
1
+ import fs from 'node:fs/promises';
2
+ import { CodePenClient } from '../api/client.js';
3
+ import { PROJECT_CONFIG_FILENAME, requireProjectInDir, } from '../config/project.js';
4
+ import { fmt } from '../utils/format.js';
5
+ import { CliError, printJsonResponse } from '../utils/json.js';
6
+ import { isInteractive, promptConfirm, promptSelect, } from '../utils/prompts.js';
7
+ import { getGlobalProfileOption, resolveCommandAuth } from './auth-context.js';
8
+ export const CODEPEN_DELETED_ITEMS_URL = 'https://codepen.io/your-work?item_type=DELETED_ITEMS';
9
+ /**
10
+ * Deletes the online Pen linked to `.cdpn.json` directly inside `options.cwd`
11
+ * (moves it to CodePen Deleted Items, restorable for 3 days) and removes `.cdpn.json`
12
+ * only after the remote deletion succeeds. Local project files are kept untouched.
13
+ *
14
+ * Returns `null` if the user cancels at the confirmation prompt.
15
+ */
16
+ export async function deletePenCommand(options = {}) {
17
+ const cwd = options.cwd ?? process.cwd();
18
+ const interactive = (options.interactive ?? isInteractive()) && !options.json;
19
+ const confirmImpl = options.prompts?.confirm ?? promptConfirm;
20
+ const selectImpl = options.prompts?.select ?? promptSelect;
21
+ // Strictly require `.cdpn.json` directly inside the current folder
22
+ const project = await requireProjectInDir(cwd);
23
+ const auth = await resolveCommandAuth({
24
+ explicitProfile: options.explicitProfile,
25
+ project,
26
+ interactive,
27
+ persistProfileToProject: false,
28
+ env: options.env,
29
+ homeDir: options.homeDir,
30
+ selectProfile: selectImpl,
31
+ });
32
+ const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
33
+ const pen = await client.getPen(project.config.pen_id);
34
+ if (!options.yes) {
35
+ if (!interactive) {
36
+ throw new CliError(400, 'Refusing to delete Pen in non-interactive mode without --yes.');
37
+ }
38
+ console.log(`\n${fmt.yellow('About to delete online Pen:')}`);
39
+ console.log(` Title: ${fmt.bold(pen.title || 'Untitled')} ${fmt.dim(`(${pen.id})`)}`);
40
+ if (auth.profile) {
41
+ console.log(` Profile: ${fmt.cyan(auth.profile)}`);
42
+ }
43
+ console.log(` Editor: ${fmt.cyan(pen.urls.editor)}`);
44
+ if (pen.deployment) {
45
+ console.log(` Live: ${fmt.yellow(pen.deployment.url)} ${fmt.dim('(will also be taken down)')}`);
46
+ }
47
+ console.log(fmt.dim(`\nLocal files will stay untouched; ${PROJECT_CONFIG_FILENAME} will be removed after deletion succeeds.`));
48
+ const ok = await confirmImpl(`Delete this Pen on CodePen (moves to Deleted Items for 3 days) and remove ${PROJECT_CONFIG_FILENAME}?`, false);
49
+ if (!ok) {
50
+ console.log('Aborted.');
51
+ return null;
52
+ }
53
+ }
54
+ await client.deletePen(project.config.pen_id);
55
+ // Remove `.cdpn.json` only after remote deletion succeeded
56
+ await fs.unlink(project.configPath);
57
+ if (options.json) {
58
+ printJsonResponse(200, `Deleted ${pen.title || 'Untitled'} (${pen.id}) on CodePen and removed ${PROJECT_CONFIG_FILENAME}.`, {
59
+ pen_id: pen.id,
60
+ title: pen.title,
61
+ profile: auth.profile,
62
+ editor_url: pen.urls.editor,
63
+ deleted: true,
64
+ config_removed: true,
65
+ restore_url: CODEPEN_DELETED_ITEMS_URL,
66
+ });
67
+ }
68
+ else {
69
+ console.log(`\n${fmt.green('✓')} Deleted ${fmt.bold(pen.title || 'Untitled')} ${fmt.dim(`(${pen.id})`)} on CodePen ${fmt.dim('(moved to Deleted Items; restorable for 3 days)')}`);
70
+ if (auth.profile) {
71
+ console.log(` Profile: ${fmt.cyan(auth.profile)}`);
72
+ }
73
+ console.log(` Removed: ${fmt.cyan(PROJECT_CONFIG_FILENAME)} ${fmt.dim('(local files were kept untouched)')}`);
74
+ console.log(` Restore: ${fmt.dim(CODEPEN_DELETED_ITEMS_URL)}`);
75
+ }
76
+ return {
77
+ pen,
78
+ project,
79
+ auth,
80
+ configRemoved: true,
81
+ };
82
+ }
83
+ export function registerDeleteCommand(program) {
84
+ program
85
+ .command('delete')
86
+ .aliases(['del', 'rm'])
87
+ .allowExcessArguments(false)
88
+ .description(`Delete the online Pen on CodePen (moves to Deleted Items) and remove ${PROJECT_CONFIG_FILENAME}`)
89
+ .option('-y, --yes', 'Skip confirmation prompt')
90
+ .option('--json', 'Output deletion result as JSON')
91
+ .action(async (options, command) => {
92
+ await deletePenCommand({
93
+ yes: options.yes,
94
+ json: options.json,
95
+ explicitProfile: getGlobalProfileOption(command),
96
+ });
97
+ });
98
+ }
@@ -0,0 +1,176 @@
1
+ import { CodePenClient } from '../api/client.js';
2
+ import { findProject, PROJECT_CONFIG_FILENAME, requireProject } from '../config/project.js';
3
+ import { fmt, shortId } from '../utils/format.js';
4
+ import { CliError, printJsonResponse } from '../utils/json.js';
5
+ import { isInteractive, promptConfirm } from '../utils/prompts.js';
6
+ import { getGlobalProfileOption, resolveCommandAuth } from './auth-context.js';
7
+ import { createPenFromDirectory } from './create-pen.js';
8
+ import { executePush } from './push.js';
9
+ export function registerDeployCommands(program) {
10
+ program
11
+ .command('deploy')
12
+ .description('Push local changes and deploy the Pen to CodePen Hosting')
13
+ .option('--no-push', 'Deploy the current remote saved head without pushing local files first')
14
+ .option('--version <version-id>', 'Deploy a specific saved version ID instead of pushing')
15
+ .option('-f, --force', 'Overwrite remote head if moved (or skip missing index.html prompt on first push)')
16
+ .option('-m, --label <label>', 'Label for the saved version created by push')
17
+ .option('-t, --title <title>', 'Title for a new Pen when deploying an unlinked folder for the first time')
18
+ .option('--access <level>', 'Privacy for a new Pen: Public, Private, Protected, or Collaborators')
19
+ .option('--password <password>', 'Password for a new Protected Pen (min 8 chars)')
20
+ .option('--json', 'Output deployment result as JSON')
21
+ .action(async (options, command) => {
22
+ if (options.label && options.label.length > 80) {
23
+ throw new CliError(400, 'Version label must be at most 80 characters.');
24
+ }
25
+ const explicitProfile = getGlobalProfileOption(command);
26
+ let project = await findProject(process.cwd());
27
+ let versionIdToDeploy = options.version;
28
+ let client;
29
+ let activeProfile;
30
+ let createdPen = false;
31
+ let pushedChanges = false;
32
+ if (!project) {
33
+ if (options.push === false || options.version) {
34
+ throw new CliError(404, `No ${PROJECT_CONFIG_FILENAME} found in this directory or any parent directory.\n` +
35
+ 'Run `cdpn clone <url>` to clone a Pen or run `cdpn deploy` without --no-push/--version to create one first.');
36
+ }
37
+ if (!options.json) {
38
+ console.log(fmt.dim(`No ${PROJECT_CONFIG_FILENAME} found — pushing this local folder as a new CodePen 2.0 Pen before deploying.`));
39
+ }
40
+ const created = await createPenFromDirectory({
41
+ targetDir: process.cwd(),
42
+ folderDisplay: '.',
43
+ explicitProfile,
44
+ title: options.title,
45
+ access: options.access,
46
+ password: options.password,
47
+ force: options.force,
48
+ wait: true,
49
+ silent: Boolean(options.json),
50
+ interactive: !options.json && isInteractive(),
51
+ });
52
+ if (!created) {
53
+ return;
54
+ }
55
+ if (created.build?.status === 'Failed') {
56
+ throw new CliError(422, 'Aborting deploy because the build failed. Fix build errors and try again.', {
57
+ pen_id: created.pen.id,
58
+ version_id: created.versionId,
59
+ build: created.build,
60
+ });
61
+ }
62
+ createdPen = true;
63
+ pushedChanges = true;
64
+ project = created.project;
65
+ versionIdToDeploy = created.versionId ?? undefined;
66
+ activeProfile = created.auth.profile;
67
+ client = new CodePenClient({ apiKey: created.auth.apiKey });
68
+ }
69
+ else {
70
+ const auth = await resolveCommandAuth({
71
+ explicitProfile,
72
+ project,
73
+ interactive: !options.json && isInteractive(),
74
+ persistProfileToProject: !options.json,
75
+ });
76
+ activeProfile = auth.profile;
77
+ client = new CodePenClient({ apiKey: auth.apiKey });
78
+ if (!versionIdToDeploy && options.push !== false) {
79
+ const pushResult = await executePush(client, project, {
80
+ force: options.force,
81
+ label: options.label,
82
+ wait: true,
83
+ silent: Boolean(options.json),
84
+ });
85
+ pushedChanges = pushResult.pushed;
86
+ if (pushResult.build?.status === 'Failed') {
87
+ throw new CliError(422, 'Aborting deploy because the build failed. Fix build errors and try again.', {
88
+ pen_id: project.config.pen_id,
89
+ version_id: pushResult.versionId,
90
+ build: pushResult.build,
91
+ });
92
+ }
93
+ if (pushResult.versionId) {
94
+ versionIdToDeploy = pushResult.versionId;
95
+ }
96
+ }
97
+ }
98
+ if (!options.json) {
99
+ console.log(versionIdToDeploy
100
+ ? `\nDeploying version ${fmt.dim(shortId(versionIdToDeploy))}…`
101
+ : '\nDeploying saved head…');
102
+ }
103
+ const deployment = await client.deployPen(project.config.pen_id, versionIdToDeploy);
104
+ if (options.json) {
105
+ printJsonResponse(200, 'Deployed successfully.', {
106
+ pen_id: project.config.pen_id,
107
+ profile: activeProfile,
108
+ created: createdPen,
109
+ pushed: pushedChanges,
110
+ version_id: deployment.version_id,
111
+ deployment,
112
+ });
113
+ return;
114
+ }
115
+ console.log(`${fmt.green('✓')} Deployed successfully!`);
116
+ if (activeProfile) {
117
+ console.log(` Profile: ${fmt.cyan(activeProfile)}`);
118
+ }
119
+ console.log(` URL: ${fmt.cyan(deployment.url)}`);
120
+ console.log(` Version: ${fmt.dim(shortId(deployment.version_id))}`);
121
+ if (deployment.custom_domains.length > 0) {
122
+ console.log(` Domains: ${deployment.custom_domains.map((d) => fmt.cyan(`https://${d}`)).join(', ')}`);
123
+ }
124
+ });
125
+ program
126
+ .command('undeploy')
127
+ .description('Take down the Pen’s live deployment (Pen and versions stay intact)')
128
+ .option('-y, --yes', 'Skip confirmation prompt')
129
+ .option('--json', 'Output undeploy result as JSON')
130
+ .action(async (options, command) => {
131
+ const interactive = isInteractive() && !options.json;
132
+ const project = await requireProject();
133
+ const auth = await resolveCommandAuth({
134
+ explicitProfile: getGlobalProfileOption(command),
135
+ project,
136
+ interactive,
137
+ persistProfileToProject: !options.json,
138
+ });
139
+ const client = new CodePenClient({ apiKey: auth.apiKey });
140
+ const pen = await client.getPen(project.config.pen_id);
141
+ if (!pen.deployment) {
142
+ if (options.json) {
143
+ printJsonResponse(200, 'This Pen is not currently deployed.', {
144
+ pen_id: project.config.pen_id,
145
+ profile: auth.profile,
146
+ undeployed: false,
147
+ previous_deployment: null,
148
+ });
149
+ return;
150
+ }
151
+ console.log(fmt.dim('This Pen is not currently deployed.'));
152
+ return;
153
+ }
154
+ if (!options.yes) {
155
+ if (!interactive) {
156
+ throw new CliError(400, 'Refusing to undeploy in non-interactive mode without --yes.');
157
+ }
158
+ const ok = await promptConfirm(`Take down live deployment at ${fmt.cyan(pen.deployment.url)}?`, false);
159
+ if (!ok) {
160
+ console.log('Aborted.');
161
+ return;
162
+ }
163
+ }
164
+ await client.undeployPen(project.config.pen_id);
165
+ if (options.json) {
166
+ printJsonResponse(200, 'Deployment taken down. Your Pen and saved versions remain intact.', {
167
+ pen_id: project.config.pen_id,
168
+ profile: auth.profile,
169
+ undeployed: true,
170
+ previous_deployment: pen.deployment,
171
+ });
172
+ return;
173
+ }
174
+ console.log(`${fmt.green('✓')} Deployment taken down. Your Pen and saved versions remain intact.`);
175
+ });
176
+ }