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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { hasProjectConfigInDir } from '../config/project.js';
|
|
4
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
6
|
+
import { fmt } from '../utils/format.js';
|
|
7
|
+
import { defaultOutput } from '../utils/output.js';
|
|
8
|
+
import { promptConfirm, promptSelect } from '../utils/prompts/index.js';
|
|
9
|
+
import { discoverPenDirectories } from './discover-pens.js';
|
|
10
|
+
async function isExistingDirectory(dirPath) {
|
|
11
|
+
try {
|
|
12
|
+
const stat = await fs.stat(dirPath);
|
|
13
|
+
return stat.isDirectory();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Performs a single non-recursive `readdir` on `dirPath` (zero subdirectory traversal)
|
|
21
|
+
* to check whether candidate subdirectories or a direct `index.html` exist.
|
|
22
|
+
*/
|
|
23
|
+
async function inspectDirectChildren(dirPath) {
|
|
24
|
+
let entries;
|
|
25
|
+
try {
|
|
26
|
+
entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return { hasSubdirs: false, hasIndexHtml: false };
|
|
30
|
+
}
|
|
31
|
+
let hasSubdirs = false;
|
|
32
|
+
let hasIndexHtml = false;
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
if (entry.name === 'index.html' && entry.isFile()) {
|
|
35
|
+
hasIndexHtml = true;
|
|
36
|
+
}
|
|
37
|
+
else if (!entry.name.startsWith('.') && entry.name !== 'node_modules' && entry.isDirectory()) {
|
|
38
|
+
hasSubdirs = true;
|
|
39
|
+
}
|
|
40
|
+
if (hasSubdirs && hasIndexHtml) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { hasSubdirs, hasIndexHtml };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the optional `[target]` positional argument shared by batch-capable commands
|
|
48
|
+
* (`status`, `push`, `pull`, `sync`, `delete`, `unlink`):
|
|
49
|
+
*
|
|
50
|
+
* - Omitted -> single-Pen mode on `cwd` (never walks subdirectories automatically).
|
|
51
|
+
* - Bare `"all"` -> batch tree-walk mode on `cwd`; if a directory named `all` also exists
|
|
52
|
+
* in `cwd`, prompts interactively to choose between targeting `./all` vs running on all Pens
|
|
53
|
+
* (or throws `409` in non-interactive mode advising `./all`).
|
|
54
|
+
* - Any other directory path (including `./all`) -> single-Pen mode on that resolved directory.
|
|
55
|
+
*/
|
|
56
|
+
export async function resolveBatchCommandTarget(options) {
|
|
57
|
+
const cwd = path.resolve(options.cwd);
|
|
58
|
+
const rawTarget = options.target?.trim();
|
|
59
|
+
if (!rawTarget) {
|
|
60
|
+
return {
|
|
61
|
+
mode: 'single',
|
|
62
|
+
targetDir: cwd,
|
|
63
|
+
fromExplicitDir: false,
|
|
64
|
+
displayDir: '.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (/^https?:\/\//i.test(rawTarget)) {
|
|
68
|
+
const cloneHint = options.commandName === 'pull'
|
|
69
|
+
? ' To clone a Pen from a URL, run `cdpn clone <url>`.'
|
|
70
|
+
: '';
|
|
71
|
+
throw new CliError(400, `Expected a local directory path or "all", not a URL ("${rawTarget}").${cloneHint}`);
|
|
72
|
+
}
|
|
73
|
+
if (rawTarget === 'all') {
|
|
74
|
+
const allDirPath = path.join(cwd, 'all');
|
|
75
|
+
const hasAllDir = await isExistingDirectory(allDirPath);
|
|
76
|
+
if (hasAllDir) {
|
|
77
|
+
if (!options.interactive) {
|
|
78
|
+
throw new CliError(409, `Ambiguous target "all": a directory named "all" exists in ${cwd}.\n` +
|
|
79
|
+
`Run interactively to choose between the "./all" directory and all Pens, or pass "./all" to target that directory explicitly.`);
|
|
80
|
+
}
|
|
81
|
+
const selectImpl = options.prompts?.select ?? promptSelect;
|
|
82
|
+
const allDirHasConfig = await hasProjectConfigInDir(allDirPath);
|
|
83
|
+
const choice = await selectImpl('A directory named "all" exists here. What would you like to do?', [
|
|
84
|
+
{
|
|
85
|
+
value: 'directory',
|
|
86
|
+
label: `Run \`cdpn ${options.commandName}\` on the "./all" directory`,
|
|
87
|
+
description: allDirHasConfig
|
|
88
|
+
? `target the Pen inside ./all`
|
|
89
|
+
: `target only the ./all directory`,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 'batch',
|
|
93
|
+
label: `Run \`cdpn ${options.commandName} all\` on all Pens in this tree`,
|
|
94
|
+
description: 'walk subdirectories and process every discovered Pen',
|
|
95
|
+
},
|
|
96
|
+
], 0);
|
|
97
|
+
if (choice === 'directory') {
|
|
98
|
+
return {
|
|
99
|
+
mode: 'single',
|
|
100
|
+
targetDir: allDirPath,
|
|
101
|
+
fromExplicitDir: true,
|
|
102
|
+
displayDir: 'all',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const discovered = await discoverPenDirectories(cwd);
|
|
107
|
+
if (discovered.length === 0) {
|
|
108
|
+
const selfIsPen = await hasProjectConfigInDir(cwd);
|
|
109
|
+
const hint = selfIsPen
|
|
110
|
+
? `\nThis directory itself is a Pen — run \`cdpn ${options.commandName}\` without "all".`
|
|
111
|
+
: '';
|
|
112
|
+
throw new CliError(404, `No Pens (${PROJECT_CONFIG_FILENAME}) found in any subdirectory of ${cwd}.${hint}`);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
mode: 'batch',
|
|
116
|
+
rootDir: cwd,
|
|
117
|
+
discovered,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const targetDir = path.resolve(cwd, rawTarget);
|
|
121
|
+
let stat;
|
|
122
|
+
try {
|
|
123
|
+
stat = await fs.stat(targetDir);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error.code === 'ENOENT') {
|
|
127
|
+
throw new CliError(404, `Directory not found: ${rawTarget}`);
|
|
128
|
+
}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
if (!stat.isDirectory()) {
|
|
132
|
+
throw new CliError(400, `Not a directory: ${rawTarget}`);
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
mode: 'single',
|
|
136
|
+
targetDir,
|
|
137
|
+
fromExplicitDir: true,
|
|
138
|
+
displayDir: rawTarget,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Called when a batch-capable command is invoked in a directory that is not a Pen
|
|
143
|
+
* (no `.cdpn.json` in `targetDir` or parents) without the `all` keyword.
|
|
144
|
+
*
|
|
145
|
+
* Performs NO recursive tree prescan so commands return immediately even in large directory trees:
|
|
146
|
+
* - Only inspects direct entries of `targetDir` (single non-recursive `readdir`).
|
|
147
|
+
* - If no subdirectories exist (or for `push`, if `index.html` exists directly for a first-time push),
|
|
148
|
+
* returns `{ action: 'none' }` so the caller preserves its normal non-Pen behavior.
|
|
149
|
+
* - Non-interactively returns early with `404` advising `cdpn <cmd> all` (zero tree traversal).
|
|
150
|
+
* - Interactively offers `cdpn <cmd> all` (yes/No, default No); only walks the directory tree
|
|
151
|
+
* if the user confirms `Yes`.
|
|
152
|
+
*/
|
|
153
|
+
export async function offerBatchAllFallback(options) {
|
|
154
|
+
const { hasSubdirs, hasIndexHtml } = await inspectDirectChildren(options.targetDir);
|
|
155
|
+
if (!hasSubdirs) {
|
|
156
|
+
return { action: 'none' };
|
|
157
|
+
}
|
|
158
|
+
// For `cdpn push`, a folder with a direct `index.html` is a standalone local demo for first-time push
|
|
159
|
+
if (options.commandName === 'push' && hasIndexHtml) {
|
|
160
|
+
return { action: 'none' };
|
|
161
|
+
}
|
|
162
|
+
const output = options.output ?? defaultOutput;
|
|
163
|
+
const dryRunSuffix = options.dryRun ? ' --dry-run' : '';
|
|
164
|
+
const whereSuffix = options.fromExplicitDir ? ` inside ${options.displayDir}` : '';
|
|
165
|
+
if (!options.interactive) {
|
|
166
|
+
const actionHint = options.commandName === 'status'
|
|
167
|
+
? `Run \`cdpn init\` to initialize this folder as a CodePen demo, \`cdpn status all\`${whereSuffix} to check Pens in subdirectories, or \`cdpn status <directory>\` for a specific Pen.`
|
|
168
|
+
: `Run \`cdpn ${options.commandName} all${dryRunSuffix}\`${whereSuffix} to ${options.commandName} Pens in subdirectories, or \`cdpn ${options.commandName} <directory>\` for a specific Pen.`;
|
|
169
|
+
throw new CliError(404, `No ${PROJECT_CONFIG_FILENAME} found in ${options.targetDir}.\n${actionHint}`);
|
|
170
|
+
}
|
|
171
|
+
const confirmImpl = options.prompts?.confirm ?? promptConfirm;
|
|
172
|
+
const dirLabel = options.fromExplicitDir ? `"${options.displayDir}"` : 'this directory';
|
|
173
|
+
output.log(fmt.dim(`No ${PROJECT_CONFIG_FILENAME} found in ${dirLabel}.`));
|
|
174
|
+
const ok = await confirmImpl(`Run \`cdpn ${options.commandName} all${dryRunSuffix}\`${whereSuffix} across subdirectories instead?`, false);
|
|
175
|
+
if (!ok) {
|
|
176
|
+
output.log('Aborted.');
|
|
177
|
+
return { action: 'canceled' };
|
|
178
|
+
}
|
|
179
|
+
const discovered = await discoverPenDirectories(options.targetDir);
|
|
180
|
+
if (discovered.length === 0) {
|
|
181
|
+
throw new CliError(404, `No Pens (${PROJECT_CONFIG_FILENAME}) found in any subdirectory of ${options.targetDir}.`);
|
|
182
|
+
}
|
|
183
|
+
return { action: 'batch', discovered };
|
|
184
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { CodePenClient } from '../api/client.js';
|
|
2
|
+
import { CodePenApiError } from '../api/errors.js';
|
|
3
|
+
import { DEFAULT_PROFILE_NAME, findMatchingProfile } from '../config/auth.js';
|
|
4
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
6
|
+
import { openBrowser, validateBrowserUrl } from '../utils/browser.js';
|
|
7
|
+
import { extractCodePenOwnerFromUrl, normalizePenReference } from '../utils/codepen-url.js';
|
|
8
|
+
import { fmt } from '../utils/format.js';
|
|
9
|
+
import { defaultOutput } from '../utils/output.js';
|
|
10
|
+
import { resolveCommandAuth } from './auth-context.js';
|
|
11
|
+
function validateEditorBrowserUrl(rawUrl) {
|
|
12
|
+
let candidate = rawUrl.trim();
|
|
13
|
+
try {
|
|
14
|
+
const parsed = new URL(candidate);
|
|
15
|
+
if (parsed.protocol === 'http:') {
|
|
16
|
+
parsed.protocol = 'https:';
|
|
17
|
+
}
|
|
18
|
+
candidate = parsed.toString();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Let validateBrowserUrl throw a clean validation error
|
|
22
|
+
}
|
|
23
|
+
const safeUrl = validateBrowserUrl(candidate);
|
|
24
|
+
const host = new URL(safeUrl).hostname.toLowerCase();
|
|
25
|
+
const isCodePenHost = host === 'codepen.io' || host.endsWith('.codepen.io');
|
|
26
|
+
if (!isCodePenHost) {
|
|
27
|
+
throw new CliError(400, `Refusing to open non-CodePen URL in browser: ${host}`);
|
|
28
|
+
}
|
|
29
|
+
return safeUrl;
|
|
30
|
+
}
|
|
31
|
+
async function promptClassicRetryChoice(selectImpl) {
|
|
32
|
+
return selectImpl('How would you like to proceed?', [
|
|
33
|
+
{
|
|
34
|
+
value: 'retry',
|
|
35
|
+
label: 'Check again / paste 2.0 Pen URL',
|
|
36
|
+
description: 're-fetch after converting or enter the new URL',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
value: 'clone-unlinked',
|
|
40
|
+
label: 'Just clone without linking',
|
|
41
|
+
description: `download files without ${PROJECT_CONFIG_FILENAME}`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
value: 'cancel',
|
|
45
|
+
label: 'Cancel',
|
|
46
|
+
description: 'abort clone',
|
|
47
|
+
},
|
|
48
|
+
], 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the authenticated CodePen username for ownership comparisons during clone.
|
|
52
|
+
*/
|
|
53
|
+
export async function resolveCurrentUsername(client, auth, penOwner) {
|
|
54
|
+
// Fast path: named profile already matches the Pen owner
|
|
55
|
+
if (auth.profile &&
|
|
56
|
+
auth.profile !== DEFAULT_PROFILE_NAME &&
|
|
57
|
+
auth.profile.toLowerCase() === penOwner.toLowerCase()) {
|
|
58
|
+
return auth.profile;
|
|
59
|
+
}
|
|
60
|
+
// Inspect one Pen owned by this API key to discover the actual CodePen account username
|
|
61
|
+
// (handles CODEPEN_API_KEY env var, "default" profile, and custom profile aliases)
|
|
62
|
+
try {
|
|
63
|
+
const samplePen = await client.verifyAuth();
|
|
64
|
+
const detected = samplePen?.urls?.editor
|
|
65
|
+
? extractCodePenOwnerFromUrl(samplePen.urls.editor)
|
|
66
|
+
: null;
|
|
67
|
+
if (detected) {
|
|
68
|
+
return detected;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Fall back to profile name if the account has no Pens or listing fails
|
|
73
|
+
}
|
|
74
|
+
if (auth.profile && auth.profile !== DEFAULT_PROFILE_NAME) {
|
|
75
|
+
return auth.profile;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Interactive workflow when cloning a Classic (v1) Pen: offers to open it in the browser
|
|
81
|
+
* so the user can convert it to CodePen 2.0 and immediately re-fetch, or clone it unlinked.
|
|
82
|
+
*/
|
|
83
|
+
export async function handleClassicPenClone(params) {
|
|
84
|
+
const { pen, apiIdentifier, effectiveUrl, selectImpl, textImpl } = params;
|
|
85
|
+
const output = params.output ?? defaultOutput;
|
|
86
|
+
let currentAuth = params.auth;
|
|
87
|
+
let currentClient = params.client;
|
|
88
|
+
let fallbackPen = pen;
|
|
89
|
+
const makeFallbackResult = (action) => ({
|
|
90
|
+
action,
|
|
91
|
+
pen: fallbackPen,
|
|
92
|
+
effectiveUrl,
|
|
93
|
+
auth: currentAuth,
|
|
94
|
+
client: currentClient,
|
|
95
|
+
isOwnedByAnotherUser: false,
|
|
96
|
+
penOwner: null,
|
|
97
|
+
currentUsername: null,
|
|
98
|
+
});
|
|
99
|
+
output.log(`\n${fmt.yellow('This is a Classic (v1) Pen, which is read-only through CodePen API v2 and cannot be synced.')}`);
|
|
100
|
+
output.log('You can convert it to a CodePen 2.0 Pen in the browser using the dropdown on the Save button.\n');
|
|
101
|
+
const initialChoice = await selectImpl('How would you like to proceed?', [
|
|
102
|
+
{
|
|
103
|
+
value: 'convert',
|
|
104
|
+
label: 'Open the Pen to convert it first',
|
|
105
|
+
description: 'open in browser, then clone linked',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
value: 'clone-unlinked',
|
|
109
|
+
label: 'Just clone without linking',
|
|
110
|
+
description: `download files without ${PROJECT_CONFIG_FILENAME}`,
|
|
111
|
+
},
|
|
112
|
+
], 0);
|
|
113
|
+
if (initialChoice === 'clone-unlinked') {
|
|
114
|
+
return makeFallbackResult('clone-unlinked');
|
|
115
|
+
}
|
|
116
|
+
const editorUrl = validateEditorBrowserUrl(pen.urls.editor || effectiveUrl);
|
|
117
|
+
const openImpl = params.openBrowserImpl ?? openBrowser;
|
|
118
|
+
const opened = await openImpl(editorUrl);
|
|
119
|
+
if (opened) {
|
|
120
|
+
output.log(`\n${fmt.green('✓')} Opened ${fmt.cyan(editorUrl)} in your browser.`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
output.log(`\n${fmt.yellow('!')} Could not launch a browser automatically. Open this URL manually:\n ${fmt.cyan(editorUrl)}`);
|
|
124
|
+
}
|
|
125
|
+
output.log(fmt.dim('In CodePen, use the dropdown on the Save button to convert this Pen to CodePen 2.0.'));
|
|
126
|
+
for (;;) {
|
|
127
|
+
output.log('');
|
|
128
|
+
const pasted = (await textImpl('Press Enter once converted to re-fetch & clone (or paste the new 2.0 Pen URL)')).trim();
|
|
129
|
+
let targetApiId = apiIdentifier;
|
|
130
|
+
let pastedOriginalUrl;
|
|
131
|
+
if (pasted) {
|
|
132
|
+
try {
|
|
133
|
+
const normalized = normalizePenReference(pasted);
|
|
134
|
+
targetApiId = normalized.apiIdentifier;
|
|
135
|
+
pastedOriginalUrl = normalized.originalUrl;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
139
|
+
output.log(`\n${fmt.yellow('!')} ${msg}\n`);
|
|
140
|
+
const nextAction = await promptClassicRetryChoice(selectImpl);
|
|
141
|
+
if (nextAction === 'retry')
|
|
142
|
+
continue;
|
|
143
|
+
if (nextAction === 'clone-unlinked')
|
|
144
|
+
return makeFallbackResult('clone-unlinked');
|
|
145
|
+
output.log('Aborted.');
|
|
146
|
+
return makeFallbackResult('cancel');
|
|
147
|
+
}
|
|
148
|
+
if (!params.explicitProfile && currentAuth.source === 'file' && pastedOriginalUrl) {
|
|
149
|
+
const matchedProfile = findMatchingProfile(currentAuth.availableProfiles, pastedOriginalUrl);
|
|
150
|
+
if (matchedProfile && matchedProfile !== currentAuth.profile) {
|
|
151
|
+
currentAuth = await resolveCommandAuth({
|
|
152
|
+
explicitProfile: matchedProfile,
|
|
153
|
+
interactive: true,
|
|
154
|
+
output,
|
|
155
|
+
env: params.env,
|
|
156
|
+
homeDir: params.homeDir,
|
|
157
|
+
});
|
|
158
|
+
currentClient = new CodePenClient({ apiKey: currentAuth.apiKey, baseUrl: params.baseUrl });
|
|
159
|
+
output.log(fmt.dim(`Using profile "${matchedProfile}" (matches Pen owner).`));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
output.log(`Fetching Pen ${fmt.cyan(targetApiId)}…`);
|
|
164
|
+
let refetched;
|
|
165
|
+
try {
|
|
166
|
+
refetched = await currentClient.getPen(targetApiId);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
const msg = error instanceof CodePenApiError
|
|
170
|
+
? error.formatForUser()
|
|
171
|
+
: error instanceof Error
|
|
172
|
+
? error.message
|
|
173
|
+
: String(error);
|
|
174
|
+
output.log(`\n${fmt.yellow('!')} Could not fetch Pen ${targetApiId}: ${msg}\n`);
|
|
175
|
+
const nextAction = await promptClassicRetryChoice(selectImpl);
|
|
176
|
+
if (nextAction === 'retry')
|
|
177
|
+
continue;
|
|
178
|
+
if (nextAction === 'clone-unlinked')
|
|
179
|
+
return makeFallbackResult('clone-unlinked');
|
|
180
|
+
output.log('Aborted.');
|
|
181
|
+
return makeFallbackResult('cancel');
|
|
182
|
+
}
|
|
183
|
+
const refetchedOwner = extractCodePenOwnerFromUrl(refetched.urls.editor) ??
|
|
184
|
+
(pastedOriginalUrl ? extractCodePenOwnerFromUrl(pastedOriginalUrl) : null);
|
|
185
|
+
if (refetchedOwner &&
|
|
186
|
+
!params.explicitProfile &&
|
|
187
|
+
currentAuth.source === 'file' &&
|
|
188
|
+
currentAuth.profile?.toLowerCase() !== refetchedOwner.toLowerCase()) {
|
|
189
|
+
const matchedStoredProfile = findMatchingProfile(currentAuth.availableProfiles, refetched.urls.editor);
|
|
190
|
+
if (matchedStoredProfile && matchedStoredProfile !== currentAuth.profile) {
|
|
191
|
+
currentAuth = await resolveCommandAuth({
|
|
192
|
+
explicitProfile: matchedStoredProfile,
|
|
193
|
+
interactive: true,
|
|
194
|
+
output,
|
|
195
|
+
env: params.env,
|
|
196
|
+
homeDir: params.homeDir,
|
|
197
|
+
});
|
|
198
|
+
currentClient = new CodePenClient({ apiKey: currentAuth.apiKey, baseUrl: params.baseUrl });
|
|
199
|
+
output.log(fmt.dim(`Using profile "${matchedStoredProfile}" (matches Pen owner).`));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (refetched.editor !== 'Classic') {
|
|
203
|
+
const detectedUsername = refetchedOwner
|
|
204
|
+
? await resolveCurrentUsername(currentClient, currentAuth, refetchedOwner)
|
|
205
|
+
: null;
|
|
206
|
+
const ownedByOther = Boolean(refetchedOwner &&
|
|
207
|
+
detectedUsername &&
|
|
208
|
+
refetchedOwner.toLowerCase() !== detectedUsername.toLowerCase());
|
|
209
|
+
const resolvedUrl = pasted
|
|
210
|
+
? (pastedOriginalUrl ?? refetched.urls.editor)
|
|
211
|
+
: (refetched.urls.editor || effectiveUrl);
|
|
212
|
+
if (!ownedByOther) {
|
|
213
|
+
output.log(`\n${fmt.green('✓')} Pen is now CodePen 2.0 ${fmt.dim(`(${refetched.id})`)} — continuing linked clone.`);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
action: ownedByOther ? 'clone-unlinked' : 'clone-linked',
|
|
217
|
+
pen: refetched,
|
|
218
|
+
effectiveUrl: resolvedUrl,
|
|
219
|
+
auth: currentAuth,
|
|
220
|
+
client: currentClient,
|
|
221
|
+
isOwnedByAnotherUser: ownedByOther,
|
|
222
|
+
penOwner: refetchedOwner,
|
|
223
|
+
currentUsername: detectedUsername,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
if (!pasted) {
|
|
227
|
+
fallbackPen = refetched;
|
|
228
|
+
}
|
|
229
|
+
output.log(`\n${fmt.yellow('!')} ${fmt.bold(refetched.title || 'Untitled')} is still a Classic (v1) Pen on CodePen.`);
|
|
230
|
+
output.log(fmt.dim('Make sure you converted it to 2.0 via the Save button dropdown (or paste the new 2.0 Pen URL if CodePen opened a new one).\n'));
|
|
231
|
+
const nextAction = await promptClassicRetryChoice(selectImpl);
|
|
232
|
+
if (nextAction === 'retry') {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (nextAction === 'clone-unlinked') {
|
|
236
|
+
return makeFallbackResult('clone-unlinked');
|
|
237
|
+
}
|
|
238
|
+
output.log('Aborted.');
|
|
239
|
+
return makeFallbackResult('cancel');
|
|
240
|
+
}
|
|
241
|
+
}
|