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,227 @@
|
|
|
1
|
+
import { writeProjectConfig } from '../config/project.js';
|
|
2
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
3
|
+
import { CliError } from '../errors.js';
|
|
4
|
+
import { computeSyncDiff, detectLocalChangesFromBaseline, hasDiffChanges, } from '../sync/diff.js';
|
|
5
|
+
import { scanLocalFiles } from '../sync/fs.js';
|
|
6
|
+
import { analyzeInfoSync, buildPenInfoConfigFields, hashPenInfo, isCompletePenInfo, } from '../sync/info.js';
|
|
7
|
+
import { fmt, shortId } from '../utils/format.js';
|
|
8
|
+
import { defaultOutput } from '../utils/output.js';
|
|
9
|
+
import { executePull } from './pull-pen.js';
|
|
10
|
+
import { executePush } from './push-pen.js';
|
|
11
|
+
/**
|
|
12
|
+
* Performs a 3-way sync comparison between local files / `.cdpn.json` metadata,
|
|
13
|
+
* the last synced baseline, and the current remote Pen on CodePen.
|
|
14
|
+
*/
|
|
15
|
+
export async function inspectLinkedPenSyncState(client, project, options = {}) {
|
|
16
|
+
const pen = options.prefetchedPen ?? (await client.getPen(project.config.pen_id));
|
|
17
|
+
const [remoteFiles, localFiles] = await Promise.all([
|
|
18
|
+
options.prefetchedRemoteFiles
|
|
19
|
+
? Promise.resolve(options.prefetchedRemoteFiles)
|
|
20
|
+
: client.getPenFiles(project.config.pen_id),
|
|
21
|
+
options.prefetchedLocalFiles
|
|
22
|
+
? Promise.resolve(options.prefetchedLocalFiles)
|
|
23
|
+
: scanLocalFiles(project.rootDir),
|
|
24
|
+
]);
|
|
25
|
+
const diff = await computeSyncDiff({
|
|
26
|
+
localFiles,
|
|
27
|
+
remoteFiles,
|
|
28
|
+
baseline: project.config.files,
|
|
29
|
+
downloadFile: (url) => client.downloadFile(url),
|
|
30
|
+
});
|
|
31
|
+
const diffCount = diff.added.length + diff.modified.length + diff.deleted.length;
|
|
32
|
+
const hasFileDiffs = hasDiffChanges(diff);
|
|
33
|
+
const localHead = project.config.last_synced_version_id;
|
|
34
|
+
const remoteHead = pen.saved_version?.id ?? null;
|
|
35
|
+
const remoteVersionChanged = Boolean(remoteHead && localHead && remoteHead !== localHead);
|
|
36
|
+
const hasFileBaseline = project.config.files !== undefined;
|
|
37
|
+
const localFileBaseline = detectLocalChangesFromBaseline(localFiles, project.config.files);
|
|
38
|
+
const localFilesDirty = hasFileBaseline &&
|
|
39
|
+
(localFileBaseline.added.length > 0 ||
|
|
40
|
+
localFileBaseline.modified.length > 0 ||
|
|
41
|
+
localFileBaseline.deleted.length > 0);
|
|
42
|
+
const infoAnalysis = analyzeInfoSync(project.config.info, project.config.last_synced_info_hash, pen);
|
|
43
|
+
const hasInfoDiffs = infoAnalysis.changes.length > 0;
|
|
44
|
+
const localInfoDirty = infoAnalysis.localChanged;
|
|
45
|
+
const remoteInfoChanged = infoAnalysis.remoteChanged;
|
|
46
|
+
const fileConflict = remoteVersionChanged && hasFileDiffs && (localFilesDirty || !hasFileBaseline);
|
|
47
|
+
const infoConflict = localInfoDirty && remoteInfoChanged;
|
|
48
|
+
const crossConflict = localInfoDirty && remoteVersionChanged;
|
|
49
|
+
let state;
|
|
50
|
+
if (!hasFileDiffs && !hasInfoDiffs && !remoteVersionChanged) {
|
|
51
|
+
state = 'up-to-date';
|
|
52
|
+
}
|
|
53
|
+
else if (fileConflict || infoConflict || crossConflict) {
|
|
54
|
+
state = 'conflict';
|
|
55
|
+
}
|
|
56
|
+
else if (remoteVersionChanged || (remoteInfoChanged && !localFilesDirty && !localInfoDirty)) {
|
|
57
|
+
state = !hasFileDiffs && !hasInfoDiffs ? 'remote-metadata-ahead' : 'remote-ahead';
|
|
58
|
+
}
|
|
59
|
+
else if (hasFileDiffs || hasInfoDiffs) {
|
|
60
|
+
state = 'local-ahead';
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
state = 'up-to-date';
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
state,
|
|
67
|
+
pen,
|
|
68
|
+
remoteFiles,
|
|
69
|
+
localFiles,
|
|
70
|
+
diff,
|
|
71
|
+
diffCount,
|
|
72
|
+
localHead,
|
|
73
|
+
remoteHead,
|
|
74
|
+
remoteVersionChanged,
|
|
75
|
+
hasFileBaseline,
|
|
76
|
+
localFileBaseline,
|
|
77
|
+
localFilesDirty,
|
|
78
|
+
infoAnalysis,
|
|
79
|
+
classicReadOnly: pen.editor === 'Classic',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Formats a concise one-line summary of file and info changes (e.g. `2 file(s), info: title, tags`).
|
|
84
|
+
*/
|
|
85
|
+
export function formatSyncChangeSummary(diffCount, infoChanges, fallback = 'metadata behind') {
|
|
86
|
+
const parts = [];
|
|
87
|
+
if (diffCount > 0) {
|
|
88
|
+
parts.push(`${diffCount} file(s)`);
|
|
89
|
+
}
|
|
90
|
+
if (infoChanges.length > 0) {
|
|
91
|
+
parts.push(`info: ${infoChanges.map((c) => c.field).join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
return parts.length > 0 ? parts.join(', ') : fallback;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Formats file diff lines (`+`, `~`, `-`) for push or pull direction display.
|
|
97
|
+
*/
|
|
98
|
+
export function formatFileDiffLines(diff, direction, indent = ' ') {
|
|
99
|
+
const lines = [];
|
|
100
|
+
if (direction === 'push') {
|
|
101
|
+
for (const item of diff.added)
|
|
102
|
+
lines.push(`${indent}${fmt.green('+')} ${item.path}`);
|
|
103
|
+
for (const item of diff.modified)
|
|
104
|
+
lines.push(`${indent}${fmt.yellow('~')} ${item.path}`);
|
|
105
|
+
for (const item of diff.deleted)
|
|
106
|
+
lines.push(`${indent}${fmt.red('-')} ${item.path}`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (const item of diff.deleted)
|
|
110
|
+
lines.push(`${indent}${fmt.green('+')} ${item.path}`);
|
|
111
|
+
for (const item of diff.modified)
|
|
112
|
+
lines.push(`${indent}${fmt.yellow('~')} ${item.path}`);
|
|
113
|
+
for (const item of diff.added)
|
|
114
|
+
lines.push(`${indent}${fmt.red('-')} ${item.path}`);
|
|
115
|
+
}
|
|
116
|
+
return lines;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Synchronizes a single linked Pen in whichever direction is ahead (local -> push, remote -> pull),
|
|
120
|
+
* leaving up-to-date Pens untouched and failing safely with `409 Conflict` if both sides diverged.
|
|
121
|
+
*/
|
|
122
|
+
export async function executeSync(client, project, auth, options = {}) {
|
|
123
|
+
const output = options.output ?? defaultOutput;
|
|
124
|
+
const silent = Boolean(options.silent);
|
|
125
|
+
const dryRun = Boolean(options.dryRun);
|
|
126
|
+
const inspection = await inspectLinkedPenSyncState(client, project, {
|
|
127
|
+
prefetchedPen: options.prefetchedPen,
|
|
128
|
+
});
|
|
129
|
+
if (inspection.state === 'up-to-date') {
|
|
130
|
+
if (!dryRun && inspection.infoAnalysis.changes.length === 0) {
|
|
131
|
+
const remoteHash = hashPenInfo(inspection.infoAnalysis.remoteInfo);
|
|
132
|
+
const needsInfoUpgrade = !inspection.infoAnalysis.tracked ||
|
|
133
|
+
!isCompletePenInfo(project.config.info) ||
|
|
134
|
+
project.config.last_synced_info_hash !== remoteHash;
|
|
135
|
+
if (needsInfoUpgrade) {
|
|
136
|
+
const nextConfig = {
|
|
137
|
+
...project.config,
|
|
138
|
+
...buildPenInfoConfigFields(inspection.pen),
|
|
139
|
+
};
|
|
140
|
+
await writeProjectConfig(project.rootDir, nextConfig);
|
|
141
|
+
project.config = nextConfig;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!silent) {
|
|
145
|
+
output.log(`${fmt.green('✓')} Everything is up to date — nothing to sync.`);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
action: 'up-to-date',
|
|
149
|
+
state: 'up-to-date',
|
|
150
|
+
dryRun,
|
|
151
|
+
pen: inspection.pen,
|
|
152
|
+
inspection,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (inspection.state === 'conflict') {
|
|
156
|
+
const infoFields = inspection.infoAnalysis.changes.map((c) => c.field);
|
|
157
|
+
const details = [];
|
|
158
|
+
if (inspection.remoteVersionChanged) {
|
|
159
|
+
details.push(`Synced version ${shortId(inspection.localHead)} differs from remote head ${shortId(inspection.remoteHead)}`);
|
|
160
|
+
}
|
|
161
|
+
if (inspection.diffCount > 0) {
|
|
162
|
+
details.push(`${inspection.diffCount} file difference(s)`);
|
|
163
|
+
}
|
|
164
|
+
if (infoFields.length > 0) {
|
|
165
|
+
details.push(`Pen info differences (${infoFields.join(', ')})`);
|
|
166
|
+
}
|
|
167
|
+
throw new CliError(409, `Sync conflict detected for ${inspection.pen.title || 'Untitled'} (${inspection.pen.id}): both local and remote have changed` +
|
|
168
|
+
(details.length > 0 ? ` (${details.join('; ')})` : '') +
|
|
169
|
+
'.\nRun `cdpn status` to inspect differences, then `cdpn push --force` to keep local or `cdpn pull --force` to keep remote.', {
|
|
170
|
+
pen_id: inspection.pen.id,
|
|
171
|
+
url: inspection.pen.urls.editor,
|
|
172
|
+
local_head: inspection.localHead,
|
|
173
|
+
remote_head: inspection.remoteHead,
|
|
174
|
+
local_file_changes: inspection.localFileBaseline,
|
|
175
|
+
diff: {
|
|
176
|
+
added: inspection.diff.added.map((i) => i.path),
|
|
177
|
+
modified: inspection.diff.modified.map((i) => i.path),
|
|
178
|
+
deleted: inspection.diff.deleted.map((i) => i.path),
|
|
179
|
+
},
|
|
180
|
+
info_changes: inspection.infoAnalysis.changes,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (inspection.state === 'local-ahead') {
|
|
184
|
+
const pushResult = await executePush(client, project, {
|
|
185
|
+
label: options.label,
|
|
186
|
+
dryRun,
|
|
187
|
+
wait: options.wait,
|
|
188
|
+
json: options.json,
|
|
189
|
+
silent,
|
|
190
|
+
output,
|
|
191
|
+
prefetchedPen: inspection.pen,
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
action: 'pushed',
|
|
195
|
+
state: 'local-ahead',
|
|
196
|
+
dryRun,
|
|
197
|
+
pen: pushResult.pen,
|
|
198
|
+
inspection,
|
|
199
|
+
pushResult,
|
|
200
|
+
...(pushResult.exitCode !== undefined ? { exitCode: pushResult.exitCode } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// remote-ahead or remote-metadata-ahead -> pull
|
|
204
|
+
const pullResult = await executePull(client, project, auth, {
|
|
205
|
+
force: inspection.state === 'remote-metadata-ahead',
|
|
206
|
+
dryRun,
|
|
207
|
+
silent,
|
|
208
|
+
interactive: false,
|
|
209
|
+
json: options.json,
|
|
210
|
+
output,
|
|
211
|
+
prefetchedPen: inspection.pen,
|
|
212
|
+
prefetchedRemoteFiles: inspection.remoteFiles,
|
|
213
|
+
prefetchedLocalFiles: inspection.localFiles,
|
|
214
|
+
handleMissingPen: false,
|
|
215
|
+
});
|
|
216
|
+
if (!pullResult) {
|
|
217
|
+
throw new CliError(500, 'Pull aborted unexpectedly during sync.');
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
action: 'pulled',
|
|
221
|
+
state: inspection.state,
|
|
222
|
+
dryRun,
|
|
223
|
+
pen: pullResult.pen,
|
|
224
|
+
inspection,
|
|
225
|
+
pullResult,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { API_KEY_ENV_VAR, DEFAULT_PROFILE_NAME, findMatchingProfile,
|
|
2
|
-
import {
|
|
1
|
+
import { API_KEY_ENV_VAR, DEFAULT_PROFILE_NAME, findMatchingProfile, } from '../config/auth.js';
|
|
2
|
+
import { readAuthStore } from '../config/user-store.js';
|
|
3
|
+
import { CliError } from '../errors.js';
|
|
3
4
|
import { openBrowser } from '../utils/browser.js';
|
|
5
|
+
import { extractCodePenOwnerFromUrl } from '../utils/codepen-url.js';
|
|
4
6
|
import { fmt } from '../utils/format.js';
|
|
5
|
-
import {
|
|
7
|
+
import { defaultOutput } from '../utils/output.js';
|
|
6
8
|
/**
|
|
7
9
|
* Checks before interactive profile prompting or network calls whether a Pen URL clearly
|
|
8
10
|
* belongs to an account not present among the user's named stored profiles in `~/.cdpn`.
|
|
@@ -55,11 +57,12 @@ function toHttpsUrl(rawUrl) {
|
|
|
55
57
|
* forked URL back to clone immediately.
|
|
56
58
|
*
|
|
57
59
|
* Returns the pasted forked Pen URL/ID if the user provides one, or `null` if they exit.
|
|
58
|
-
* In non-interactive mode (or when `allowBrowserFallback` is false), throws a clear
|
|
60
|
+
* In non-interactive mode (or when `allowBrowserFallback` is false), throws a clear CliError.
|
|
59
61
|
*/
|
|
60
62
|
export async function handleUnownedPenAccess(options) {
|
|
61
63
|
const safeUrl = toHttpsUrl(options.penUrl);
|
|
62
64
|
const { action, urlOwner, availableProfiles, currentProfile, interactive } = options;
|
|
65
|
+
const output = options.output ?? defaultOutput;
|
|
63
66
|
const allowBrowserFallback = options.allowBrowserFallback !== false;
|
|
64
67
|
const profileLine = availableProfiles && availableProfiles.length > 0
|
|
65
68
|
? `Stored profiles: ${availableProfiles.join(', ')} (pass --profile <name> if one of them is an alias for ${urlOwner}).`
|
|
@@ -80,28 +83,28 @@ export async function handleUnownedPenAccess(options) {
|
|
|
80
83
|
...(currentProfile ? { current_profile: currentProfile } : {}),
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
output.log(`\n${fmt.yellow(`Cannot ${action} ${fmt.bold(urlOwner)}’s Pen via CodePen API v2.`)}`);
|
|
87
|
+
output.log('CodePen API v2 keys can only access and fork Pens owned by the key’s account — other users’ Pens return 404, even when public.');
|
|
85
88
|
if (profileLine) {
|
|
86
|
-
|
|
89
|
+
output.log(fmt.dim(` ${profileLine}`));
|
|
87
90
|
}
|
|
88
|
-
|
|
91
|
+
output.log('\nWorkaround: fork this Pen in your browser on codepen.io, then clone your fork locally.');
|
|
89
92
|
const shouldOpen = await options.confirmImpl(`Open ${safeUrl} in your browser to fork it?`, true);
|
|
90
93
|
if (!shouldOpen) {
|
|
91
|
-
|
|
94
|
+
output.log(fmt.dim('Run `cdpn clone <your-fork-url>` once you have forked it on CodePen.'));
|
|
92
95
|
return null;
|
|
93
96
|
}
|
|
94
97
|
const openImpl = options.openBrowserImpl ?? openBrowser;
|
|
95
98
|
const opened = await openImpl(safeUrl);
|
|
96
99
|
if (opened) {
|
|
97
|
-
|
|
100
|
+
output.log(`\n${fmt.green('✓')} Opened ${fmt.cyan(safeUrl)} in your browser.`);
|
|
98
101
|
}
|
|
99
102
|
else {
|
|
100
|
-
|
|
103
|
+
output.log(`\n${fmt.yellow('!')} Could not launch a browser automatically. Open this URL manually:\n ${fmt.cyan(safeUrl)}`);
|
|
101
104
|
}
|
|
102
105
|
const pasted = (await options.textImpl('Paste your forked Pen URL to clone it now (or press Enter to exit)')).trim();
|
|
103
106
|
if (!pasted) {
|
|
104
|
-
|
|
107
|
+
output.log(fmt.dim('Run `cdpn clone <your-fork-url>` whenever you are ready to clone your fork.'));
|
|
105
108
|
return null;
|
|
106
109
|
}
|
|
107
110
|
return pasted;
|
|
@@ -141,6 +144,7 @@ export async function handlePenNotFoundOnFetch(options) {
|
|
|
141
144
|
currentProfile: auth.profile,
|
|
142
145
|
interactive: options.interactive,
|
|
143
146
|
allowBrowserFallback: options.allowBrowserFallback,
|
|
147
|
+
output: options.output,
|
|
144
148
|
confirmImpl: options.confirmImpl,
|
|
145
149
|
textImpl: options.textImpl,
|
|
146
150
|
openBrowserImpl: options.openBrowserImpl,
|