codepen-commander 1.2.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 +104 -10
- 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 +553 -37
- package/commands/deploy.js +164 -154
- 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 +222 -365
- 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 +179 -240
- 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/workflows/create-pen.js +254 -0
- 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/create-pen.js +0 -251
- package/commands/meta.js +0 -184
- package/utils/prompts.js +0 -316
- /package/{types.js → api/types.js} +0 -0
package/commands/create-pen.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
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 { buildPenInfoConfigFields } from '../sync/info.js';
|
|
7
|
-
import { syncRemoteFilesToDisk } from '../sync/materialize.js';
|
|
8
|
-
import { fmt, printBuildSummary, shortId } from '../utils/format.js';
|
|
9
|
-
import { extractHtmlTitle } from '../utils/html.js';
|
|
10
|
-
import { CliError } from '../utils/json.js';
|
|
11
|
-
import { isInteractive, promptConfirm, promptSecret, promptSelect, promptText, } from '../utils/prompts.js';
|
|
12
|
-
import { resolveCommandAuth } from './auth-context.js';
|
|
13
|
-
const VALID_ACCESS = new Set(['public', 'private', 'protected', 'collaborators']);
|
|
14
|
-
export function normalizeAccess(raw) {
|
|
15
|
-
if (!raw)
|
|
16
|
-
return undefined;
|
|
17
|
-
const lower = raw.trim().toLowerCase();
|
|
18
|
-
if (!VALID_ACCESS.has(lower)) {
|
|
19
|
-
throw new CliError(400, `Invalid access level "${raw}". Use: Public, Private, Protected, or Collaborators.`);
|
|
20
|
-
}
|
|
21
|
-
return (lower[0].toUpperCase() + lower.slice(1));
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Validates or interactively prompts for Pen visibility (`Public` default, `Private`,
|
|
25
|
-
* `Protected`, or `Collaborators`) and password when `Protected` is chosen.
|
|
26
|
-
*/
|
|
27
|
-
export async function resolveVisibilityAndPassword(options) {
|
|
28
|
-
const selectImpl = options.prompts?.select ?? promptSelect;
|
|
29
|
-
const secretImpl = options.prompts?.secret ?? promptSecret;
|
|
30
|
-
let access = normalizeAccess(options.rawAccess);
|
|
31
|
-
if (access === 'Protected' && options.rawPassword !== undefined && options.rawPassword.length < 8) {
|
|
32
|
-
throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
|
|
33
|
-
}
|
|
34
|
-
if (access === 'Protected' && !options.rawPassword && !options.interactive) {
|
|
35
|
-
throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
|
|
36
|
-
}
|
|
37
|
-
if (!access) {
|
|
38
|
-
if (options.interactive) {
|
|
39
|
-
access = await selectImpl('Pen visibility:', [
|
|
40
|
-
{ value: 'Public', label: 'Public', description: 'visible to everyone (default)' },
|
|
41
|
-
{ value: 'Private', label: 'Private', description: 'visible only to you / your team' },
|
|
42
|
-
{
|
|
43
|
-
value: 'Protected',
|
|
44
|
-
label: 'Protected',
|
|
45
|
-
description: 'password-protected (min 8 characters)',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
value: 'Collaborators',
|
|
49
|
-
label: 'Collaborators',
|
|
50
|
-
description: 'visible only to you and collaborators',
|
|
51
|
-
},
|
|
52
|
-
], 0);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
access = 'Public';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
let password = options.rawPassword;
|
|
59
|
-
if (access === 'Protected' && (!password || password.length < 8)) {
|
|
60
|
-
if (!options.interactive) {
|
|
61
|
-
throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
|
|
62
|
-
}
|
|
63
|
-
for (;;) {
|
|
64
|
-
password = await secretImpl('Password for Protected Pen (min 8 characters)');
|
|
65
|
-
if (password.length >= 8)
|
|
66
|
-
break;
|
|
67
|
-
console.log(fmt.yellow('Password must be at least 8 characters.'));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
access,
|
|
72
|
-
...(access === 'Protected' && password ? { password } : {}),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
export function printMissingIndexHtmlWarning(targetDir, fileCount) {
|
|
76
|
-
const headline = ' WARNING: No index.html found in this folder! ';
|
|
77
|
-
const border = '═'.repeat(headline.length);
|
|
78
|
-
console.log('');
|
|
79
|
-
console.log(fmt.yellow(fmt.bold(`╔${border}╗`)));
|
|
80
|
-
console.log(fmt.yellow(fmt.bold(`║${headline}║`)));
|
|
81
|
-
console.log(fmt.yellow(fmt.bold(`╚${border}╝`)));
|
|
82
|
-
console.log(fmt.yellow(`CodePen expects an index.html file at the root of your demo.\n` +
|
|
83
|
-
`Double-check that you are in the right folder before pushing:\n` +
|
|
84
|
-
` Folder: ${targetDir} (${fileCount} file(s) found)`));
|
|
85
|
-
console.log('');
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* First-time Pen creation flow used by `cdpn push` and `cdpn deploy` when invoked inside
|
|
89
|
-
* an unlinked local demo folder:
|
|
90
|
-
*
|
|
91
|
-
* 1. Checks for `/index.html`; if absent, displays a prominent warning and asks for confirmation.
|
|
92
|
-
* 2. Resolves or asks which CodePen account/profile to push to (when multiple keys are in `~/.cdpn`).
|
|
93
|
-
* 3. Asks for a title (pre-filled from `index.html`'s `<title>` when available).
|
|
94
|
-
* 4. Asks for visibility (`Public` default, `Private`, `Protected`, or `Collaborators`).
|
|
95
|
-
*/
|
|
96
|
-
export async function createPenFromDirectory(options) {
|
|
97
|
-
const silent = Boolean(options.silent);
|
|
98
|
-
const interactive = silent ? false : (options.interactive ?? isInteractive());
|
|
99
|
-
const confirmImpl = options.prompts?.confirm ?? promptConfirm;
|
|
100
|
-
const textImpl = options.prompts?.text ?? promptText;
|
|
101
|
-
const selectImpl = options.prompts?.select ?? promptSelect;
|
|
102
|
-
// Validate --access / --password early before prompting or scanning
|
|
103
|
-
const prevalidatedAccess = normalizeAccess(options.access);
|
|
104
|
-
if (prevalidatedAccess === 'Protected' && options.password !== undefined && options.password.length < 8) {
|
|
105
|
-
throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
|
|
106
|
-
}
|
|
107
|
-
if (prevalidatedAccess === 'Protected' && !options.password && !interactive) {
|
|
108
|
-
throw new CliError(400, 'Protected Pens require --password with at least 8 characters.');
|
|
109
|
-
}
|
|
110
|
-
const targetDir = path.resolve(options.targetDir);
|
|
111
|
-
const folderDisplay = options.folderDisplay;
|
|
112
|
-
if (await hasProjectConfigInDir(targetDir)) {
|
|
113
|
-
throw new CliError(409, `${targetDir} already contains ${PROJECT_CONFIG_FILENAME}. Use \`cdpn push\` to update the existing Pen.`);
|
|
114
|
-
}
|
|
115
|
-
const scanned = await scanLocalFiles(targetDir);
|
|
116
|
-
if (scanned.size === 0) {
|
|
117
|
-
throw new CliError(400, `No ${PROJECT_CONFIG_FILENAME} found and no syncable files in ${targetDir}.\n` +
|
|
118
|
-
'Run `cdpn clone <url>` to clone an existing Pen or `cdpn new` to scaffold a brand-new Pen.');
|
|
119
|
-
}
|
|
120
|
-
const indexFile = scanned.get('/index.html');
|
|
121
|
-
// 1. Check for index.html before pushing a local demo for the first time
|
|
122
|
-
if (!indexFile) {
|
|
123
|
-
if (!silent) {
|
|
124
|
-
printMissingIndexHtmlWarning(targetDir, scanned.size);
|
|
125
|
-
}
|
|
126
|
-
if (!options.force) {
|
|
127
|
-
if (!interactive) {
|
|
128
|
-
throw new CliError(400, `No index.html found in ${targetDir}. Pass --force to push this folder without an index.html.`);
|
|
129
|
-
}
|
|
130
|
-
const ok = await confirmImpl('Are you sure you want to push this folder without an index.html?', false);
|
|
131
|
-
if (!ok) {
|
|
132
|
-
console.log('Aborted.');
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// 2. Ask which account/profile to push to (only prompts if multiple keys exist in ~/.cdpn)
|
|
138
|
-
const auth = await resolveCommandAuth({
|
|
139
|
-
explicitProfile: options.explicitProfile,
|
|
140
|
-
promptMessage: 'Which CodePen account/profile would you like to push to?',
|
|
141
|
-
interactive,
|
|
142
|
-
env: options.env,
|
|
143
|
-
homeDir: options.homeDir,
|
|
144
|
-
selectProfile: selectImpl,
|
|
145
|
-
});
|
|
146
|
-
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
147
|
-
// 3. Determine title (defaulting to index.html's <title> when present)
|
|
148
|
-
const htmlTitle = indexFile && !indexFile.isBinary && indexFile.textContent
|
|
149
|
-
? extractHtmlTitle(indexFile.textContent)
|
|
150
|
-
: null;
|
|
151
|
-
const fallbackTitle = path.basename(targetDir) || 'Untitled';
|
|
152
|
-
const defaultTitle = htmlTitle ?? fallbackTitle;
|
|
153
|
-
let title = options.title?.trim();
|
|
154
|
-
if (!title) {
|
|
155
|
-
if (interactive) {
|
|
156
|
-
title = (await textImpl('Pen title', defaultTitle)).trim() || defaultTitle;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
title = defaultTitle;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// 4. Ask for visibility (Public by default, Private, Protected, or Collaborators)
|
|
163
|
-
const { access, password } = await resolveVisibilityAndPassword({
|
|
164
|
-
rawAccess: options.access,
|
|
165
|
-
rawPassword: options.password,
|
|
166
|
-
interactive,
|
|
167
|
-
prompts: options.prompts,
|
|
168
|
-
});
|
|
169
|
-
const textFiles = [];
|
|
170
|
-
const binaryFiles = [];
|
|
171
|
-
for (const [filePath, lf] of scanned) {
|
|
172
|
-
if (lf.isBinary && lf.buffer.length > 0) {
|
|
173
|
-
binaryFiles.push({ path: filePath, content: lf.buffer });
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
textFiles.push({ path: filePath, content: lf.textContent ?? '' });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const shouldWait = options.wait !== false;
|
|
180
|
-
if (!silent) {
|
|
181
|
-
console.log(`\nCreating new Pen from ${textFiles.length + binaryFiles.length} local file(s)…`);
|
|
182
|
-
}
|
|
183
|
-
const created = await client.createPen({
|
|
184
|
-
...(title ? { title } : {}),
|
|
185
|
-
...(options.description ? { description: options.description } : {}),
|
|
186
|
-
...(options.tags && options.tags.length > 0 ? { tags: options.tags } : {}),
|
|
187
|
-
access,
|
|
188
|
-
...(password ? { password } : {}),
|
|
189
|
-
...(options.template ? { template: true } : {}),
|
|
190
|
-
files: textFiles,
|
|
191
|
-
wait: shouldWait ? 45 : 0,
|
|
192
|
-
}, binaryFiles);
|
|
193
|
-
let finalBuild = created.build ?? null;
|
|
194
|
-
if (finalBuild && shouldWait) {
|
|
195
|
-
finalBuild = await client.settleBuild(finalBuild);
|
|
196
|
-
if (!silent) {
|
|
197
|
-
printBuildSummary(finalBuild);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
201
|
-
const finalVersionId = finalBuild?.version_id ?? created.saved_version?.id ?? null;
|
|
202
|
-
const remoteFiles = finalVersionId
|
|
203
|
-
? (await client.getVersion(finalVersionId)).files ?? (await client.getPenFiles(created.id))
|
|
204
|
-
: await client.getPenFiles(created.id);
|
|
205
|
-
const materialized = await syncRemoteFilesToDisk({
|
|
206
|
-
client,
|
|
207
|
-
rootDir: targetDir,
|
|
208
|
-
remoteFiles,
|
|
209
|
-
pruneRemoved: false,
|
|
210
|
-
});
|
|
211
|
-
const config = {
|
|
212
|
-
url: created.urls.editor,
|
|
213
|
-
pen_id: created.id,
|
|
214
|
-
...(auth.profile ? { profile: auth.profile } : {}),
|
|
215
|
-
last_synced_version_id: finalVersionId,
|
|
216
|
-
editor: created.editor,
|
|
217
|
-
...buildPenInfoConfigFields(created),
|
|
218
|
-
files: buildSyncedFileMap(remoteFiles, materialized.localSha256ByPath),
|
|
219
|
-
};
|
|
220
|
-
const configPath = await writeProjectConfig(targetDir, config);
|
|
221
|
-
if (finalBuild?.status === 'Failed') {
|
|
222
|
-
if (!silent) {
|
|
223
|
-
console.log(`\n${fmt.yellow('!')} Created Pen ${fmt.bold(created.title || 'Untitled')} ${fmt.dim(`(${created.id})`)}, but the initial build failed.`);
|
|
224
|
-
}
|
|
225
|
-
process.exitCode = 1;
|
|
226
|
-
}
|
|
227
|
-
else if (!silent) {
|
|
228
|
-
console.log(`\n${fmt.green('✓')} Created Pen ${fmt.bold(created.title || 'Untitled')} ${fmt.dim(`(${created.id})`)}`);
|
|
229
|
-
}
|
|
230
|
-
if (!silent) {
|
|
231
|
-
if (auth.profile) {
|
|
232
|
-
console.log(` Profile: ${fmt.cyan(auth.profile)}`);
|
|
233
|
-
}
|
|
234
|
-
console.log(` Visibility: ${created.access}`);
|
|
235
|
-
console.log(` Folder: ${fmt.cyan(folderDisplay)}`);
|
|
236
|
-
console.log(` Editor: ${fmt.cyan(created.urls.editor)}`);
|
|
237
|
-
console.log(` Preview: ${fmt.cyan(created.urls.preview)}`);
|
|
238
|
-
console.log(` Version: ${fmt.dim(shortId(finalVersionId))}`);
|
|
239
|
-
}
|
|
240
|
-
return {
|
|
241
|
-
pen: created,
|
|
242
|
-
versionId: finalVersionId,
|
|
243
|
-
build: finalBuild,
|
|
244
|
-
auth,
|
|
245
|
-
project: {
|
|
246
|
-
rootDir: targetDir,
|
|
247
|
-
configPath,
|
|
248
|
-
config,
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
}
|
package/commands/meta.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { CodePenClient } from '../api/client.js';
|
|
2
|
-
import { requireProject, writeProjectConfig } from '../config/project.js';
|
|
3
|
-
import { mergeUpdatedPenInfoIntoConfig } from '../sync/info.js';
|
|
4
|
-
import { fmt, formatDate, shortId } from '../utils/format.js';
|
|
5
|
-
import { CliError, printJsonResponse } from '../utils/json.js';
|
|
6
|
-
import { getGlobalProfileOption, resolveCommandAuth } from './auth-context.js';
|
|
7
|
-
const VALID_ACCESS = new Set(['public', 'private', 'protected', 'collaborators']);
|
|
8
|
-
function parseBooleanOption(raw, flagName) {
|
|
9
|
-
const lower = raw.trim().toLowerCase();
|
|
10
|
-
if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on')
|
|
11
|
-
return true;
|
|
12
|
-
if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off')
|
|
13
|
-
return false;
|
|
14
|
-
throw new CliError(400, `Invalid boolean value "${raw}" for ${flagName}. Use true or false.`);
|
|
15
|
-
}
|
|
16
|
-
function renderPenInfo(pen, profile) {
|
|
17
|
-
console.log(`${fmt.bold(pen.title || 'Untitled')} ${fmt.dim(`(${pen.id})`)}`);
|
|
18
|
-
if (profile) {
|
|
19
|
-
console.log(`Profile: ${fmt.cyan(profile)}`);
|
|
20
|
-
}
|
|
21
|
-
if (pen.description) {
|
|
22
|
-
console.log(`Description: ${pen.description}`);
|
|
23
|
-
}
|
|
24
|
-
console.log(`Editor: ${pen.editor}`);
|
|
25
|
-
console.log(`Access: ${pen.access}${pen.template ? fmt.dim(' · Template') : ''}`);
|
|
26
|
-
console.log(`Tags: ${pen.tags.length > 0 ? pen.tags.join(', ') : fmt.dim('none')}`);
|
|
27
|
-
console.log(`Stats: ${pen.views_count} views · ${pen.loves_count} loves`);
|
|
28
|
-
console.log(`Editor URL: ${fmt.cyan(pen.urls.editor)}`);
|
|
29
|
-
console.log(`Preview URL: ${fmt.cyan(pen.urls.preview)}`);
|
|
30
|
-
if (pen.deployment) {
|
|
31
|
-
console.log(`Deployed: ${fmt.cyan(pen.deployment.url)} ${fmt.dim(`(v ${shortId(pen.deployment.version_id)})`)}`);
|
|
32
|
-
if (pen.deployment.custom_domains.length > 0) {
|
|
33
|
-
console.log(`Domains: ${pen.deployment.custom_domains.join(', ')}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.log(`Deployed: ${fmt.dim('not deployed')}`);
|
|
38
|
-
}
|
|
39
|
-
console.log(`Created: ${fmt.dim(formatDate(pen.created_at))}`);
|
|
40
|
-
console.log(`Updated: ${fmt.dim(formatDate(pen.updated_at))}`);
|
|
41
|
-
}
|
|
42
|
-
function renderPenSettings(settings) {
|
|
43
|
-
const boolText = (b) => (b ? fmt.green('true') : fmt.dim('false'));
|
|
44
|
-
console.log(`auto_deploy: ${boolText(settings.auto_deploy)}`);
|
|
45
|
-
console.log(`auto_run: ${boolText(settings.auto_run)}`);
|
|
46
|
-
console.log(`auto_save: ${boolText(settings.auto_save)}`);
|
|
47
|
-
console.log(`indent_with: ${fmt.cyan(settings.indent_with)}`);
|
|
48
|
-
console.log(`tab_size: ${fmt.cyan(String(settings.tab_size))}`);
|
|
49
|
-
}
|
|
50
|
-
export async function infoPenCommand(options = {}) {
|
|
51
|
-
const project = await requireProject(options.cwd ?? process.cwd());
|
|
52
|
-
const auth = await resolveCommandAuth({
|
|
53
|
-
explicitProfile: options.explicitProfile,
|
|
54
|
-
project,
|
|
55
|
-
interactive: options.json ? false : options.interactive,
|
|
56
|
-
persistProfileToProject: !options.json,
|
|
57
|
-
env: options.env,
|
|
58
|
-
homeDir: options.homeDir,
|
|
59
|
-
selectProfile: options.selectProfile,
|
|
60
|
-
});
|
|
61
|
-
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
62
|
-
const patch = {};
|
|
63
|
-
if (options.title !== undefined)
|
|
64
|
-
patch.title = options.title;
|
|
65
|
-
if (options.description !== undefined)
|
|
66
|
-
patch.description = options.description;
|
|
67
|
-
if (options.tags !== undefined) {
|
|
68
|
-
const parsedTags = options.tags
|
|
69
|
-
.split(',')
|
|
70
|
-
.map((t) => t.trim())
|
|
71
|
-
.filter(Boolean);
|
|
72
|
-
if (parsedTags.length > 5) {
|
|
73
|
-
throw new CliError(400, 'CodePen allows at most 5 tags per Pen.');
|
|
74
|
-
}
|
|
75
|
-
patch.tags = parsedTags;
|
|
76
|
-
}
|
|
77
|
-
if (options.access !== undefined) {
|
|
78
|
-
const lower = options.access.trim().toLowerCase();
|
|
79
|
-
if (!VALID_ACCESS.has(lower)) {
|
|
80
|
-
throw new CliError(400, `Invalid --access "${options.access}". Use: Public, Private, Protected, or Collaborators.`);
|
|
81
|
-
}
|
|
82
|
-
patch.access = (lower[0].toUpperCase() + lower.slice(1));
|
|
83
|
-
}
|
|
84
|
-
if (options.password !== undefined) {
|
|
85
|
-
if (options.password.length < 8) {
|
|
86
|
-
throw new CliError(400, 'Password must be at least 8 characters.');
|
|
87
|
-
}
|
|
88
|
-
patch.password = options.password;
|
|
89
|
-
}
|
|
90
|
-
if (options.template !== undefined) {
|
|
91
|
-
patch.template = parseBooleanOption(options.template, '--template');
|
|
92
|
-
}
|
|
93
|
-
const hasUpdates = Object.keys(patch).length > 0;
|
|
94
|
-
const pen = hasUpdates
|
|
95
|
-
? await client.updatePen(project.config.pen_id, patch)
|
|
96
|
-
: await client.getPen(project.config.pen_id);
|
|
97
|
-
if (hasUpdates) {
|
|
98
|
-
const nextConfig = mergeUpdatedPenInfoIntoConfig(project.config, pen, patch);
|
|
99
|
-
await writeProjectConfig(project.rootDir, nextConfig);
|
|
100
|
-
project.config = nextConfig;
|
|
101
|
-
}
|
|
102
|
-
if (options.json) {
|
|
103
|
-
printJsonResponse(200, hasUpdates ? 'Updated Pen metadata.' : 'Fetched Pen metadata.', pen);
|
|
104
|
-
return { pen, updated: hasUpdates, auth, project };
|
|
105
|
-
}
|
|
106
|
-
if (hasUpdates) {
|
|
107
|
-
console.log(`${fmt.green('✓')} Updated Pen metadata.\n`);
|
|
108
|
-
}
|
|
109
|
-
renderPenInfo(pen, auth.profile);
|
|
110
|
-
return { pen, updated: hasUpdates, auth, project };
|
|
111
|
-
}
|
|
112
|
-
export function registerMetaCommands(program) {
|
|
113
|
-
program
|
|
114
|
-
.command('info')
|
|
115
|
-
.description('Show or update Pen metadata (title, description, tags, access, template)')
|
|
116
|
-
.option('-t, --title <title>', 'Update Pen title')
|
|
117
|
-
.option('-d, --description <text>', 'Update Pen description')
|
|
118
|
-
.option('--tags <tags>', 'Replace tags with comma-separated list (pass "" to clear)')
|
|
119
|
-
.option('--access <level>', 'Update access: Public, Private, Protected, or Collaborators')
|
|
120
|
-
.option('--password <password>', 'Set/replace password (min 8 chars; for Protected Pens)')
|
|
121
|
-
.option('--template <bool>', 'Set template flag (true/false)')
|
|
122
|
-
.option('--json', 'Output Pen metadata as JSON')
|
|
123
|
-
.action(async (options, command) => {
|
|
124
|
-
await infoPenCommand({
|
|
125
|
-
...options,
|
|
126
|
-
explicitProfile: getGlobalProfileOption(command),
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
program
|
|
130
|
-
.command('settings')
|
|
131
|
-
.description('View or update Pen editor & deploy settings')
|
|
132
|
-
.option('--auto-deploy <bool>', 'Auto-deploy on save (true/false)')
|
|
133
|
-
.option('--auto-run <bool>', 'Auto-run preview (true/false)')
|
|
134
|
-
.option('--auto-save <bool>', 'Auto-save in editor (true/false)')
|
|
135
|
-
.option('--indent-with <mode>', 'Indentation style: tabs or spaces')
|
|
136
|
-
.option('--tab-size <n>', 'Tab size (integer between 1 and 6)')
|
|
137
|
-
.option('--json', 'Output settings as JSON')
|
|
138
|
-
.action(async (options, command) => {
|
|
139
|
-
const project = await requireProject();
|
|
140
|
-
const auth = await resolveCommandAuth({
|
|
141
|
-
explicitProfile: getGlobalProfileOption(command),
|
|
142
|
-
project,
|
|
143
|
-
interactive: options.json ? false : undefined,
|
|
144
|
-
persistProfileToProject: !options.json,
|
|
145
|
-
});
|
|
146
|
-
const client = new CodePenClient({ apiKey: auth.apiKey });
|
|
147
|
-
const patch = {};
|
|
148
|
-
if (options.autoDeploy !== undefined) {
|
|
149
|
-
patch.auto_deploy = parseBooleanOption(options.autoDeploy, '--auto-deploy');
|
|
150
|
-
}
|
|
151
|
-
if (options.autoRun !== undefined) {
|
|
152
|
-
patch.auto_run = parseBooleanOption(options.autoRun, '--auto-run');
|
|
153
|
-
}
|
|
154
|
-
if (options.autoSave !== undefined) {
|
|
155
|
-
patch.auto_save = parseBooleanOption(options.autoSave, '--auto-save');
|
|
156
|
-
}
|
|
157
|
-
if (options.indentWith !== undefined) {
|
|
158
|
-
const lower = options.indentWith.trim().toLowerCase();
|
|
159
|
-
if (lower !== 'tabs' && lower !== 'spaces') {
|
|
160
|
-
throw new CliError(400, 'Invalid --indent-with value. Use "tabs" or "spaces".');
|
|
161
|
-
}
|
|
162
|
-
patch.indent_with = lower;
|
|
163
|
-
}
|
|
164
|
-
if (options.tabSize !== undefined) {
|
|
165
|
-
const parsed = Number.parseInt(options.tabSize, 10);
|
|
166
|
-
if (Number.isNaN(parsed) || parsed < 1 || parsed > 6) {
|
|
167
|
-
throw new CliError(400, '--tab-size must be an integer between 1 and 6.');
|
|
168
|
-
}
|
|
169
|
-
patch.tab_size = parsed;
|
|
170
|
-
}
|
|
171
|
-
const hasUpdates = Object.keys(patch).length > 0;
|
|
172
|
-
const settings = hasUpdates
|
|
173
|
-
? await client.updateSettings(project.config.pen_id, patch)
|
|
174
|
-
: (await client.getPen(project.config.pen_id)).settings;
|
|
175
|
-
if (options.json) {
|
|
176
|
-
printJsonResponse(200, hasUpdates ? 'Updated Pen settings.' : 'Fetched Pen settings.', settings);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (hasUpdates) {
|
|
180
|
-
console.log(`${fmt.green('✓')} Updated Pen settings.\n`);
|
|
181
|
-
}
|
|
182
|
-
renderPenSettings(settings);
|
|
183
|
-
});
|
|
184
|
-
}
|