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/push.js
CHANGED
|
@@ -1,418 +1,263 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { CodePenClient } from '../api/client.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'Run `cdpn status` to inspect differences, `cdpn pull` to sync remote changes, or `cdpn push --force` to overwrite.', {
|
|
28
|
-
local_head: localHead,
|
|
29
|
-
remote_head: remoteHead,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const diff = await computeSyncDiff({
|
|
33
|
-
localFiles,
|
|
34
|
-
remoteFiles,
|
|
35
|
-
baseline: project.config.files,
|
|
36
|
-
downloadFile: (url) => client.downloadFile(url),
|
|
37
|
-
});
|
|
38
|
-
const infoAnalysis = analyzeInfoSync(project.config.info, project.config.last_synced_info_hash, pen);
|
|
39
|
-
if (infoAnalysis.localChanged && infoAnalysis.remoteChanged && !options.force) {
|
|
40
|
-
const fields = infoAnalysis.changes.map((c) => c.field).join(', ');
|
|
41
|
-
throw new CliError(409, `Remote Pen info has changed since your last sync, and you also have local info edits in ${PROJECT_CONFIG_FILENAME} (${fields}).\n` +
|
|
42
|
-
'Run `cdpn status` to inspect differences, `cdpn pull` to sync remote changes, or `cdpn push --force` to overwrite.', {
|
|
43
|
-
info_changes: infoAnalysis.changes,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const hasFileChanges = hasDiffChanges(diff);
|
|
47
|
-
const shouldPushInfo = infoAnalysis.changes.length > 0 && (infoAnalysis.localChanged || Boolean(options.force));
|
|
48
|
-
const infoChangesToPush = shouldPushInfo ? infoAnalysis.changes : [];
|
|
49
|
-
// Validate info patch constraints up-front before making any write API calls
|
|
50
|
-
const infoPatch = shouldPushInfo ? buildInfoUpdatePatch(infoChangesToPush) : null;
|
|
51
|
-
if (!hasFileChanges && !shouldPushInfo) {
|
|
52
|
-
let backfilledLegacyInfo = false;
|
|
53
|
-
if (!options.dryRun && infoAnalysis.changes.length === 0) {
|
|
54
|
-
const remoteHash = hashPenInfo(infoAnalysis.remoteInfo);
|
|
55
|
-
const needsInfoUpgrade = !infoAnalysis.tracked ||
|
|
56
|
-
!isCompletePenInfo(project.config.info) ||
|
|
57
|
-
project.config.last_synced_info_hash !== remoteHash;
|
|
58
|
-
if (needsInfoUpgrade) {
|
|
59
|
-
backfilledLegacyInfo = !infoAnalysis.tracked;
|
|
60
|
-
const nextConfig = {
|
|
61
|
-
...project.config,
|
|
62
|
-
...buildPenInfoConfigFields(pen),
|
|
63
|
-
};
|
|
64
|
-
await writeProjectConfig(project.rootDir, nextConfig);
|
|
65
|
-
project.config = nextConfig;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (!silent) {
|
|
69
|
-
if (infoAnalysis.remoteChanged) {
|
|
70
|
-
console.log(`${fmt.cyan('ℹ')} No local changes to push. Remote Pen info has changed on CodePen — run \`cdpn pull\` to update ${PROJECT_CONFIG_FILENAME}, or \`cdpn push --force\` to overwrite.`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.log(`${fmt.green('✓')} Everything is up to date — nothing to push.`);
|
|
74
|
-
if (backfilledLegacyInfo) {
|
|
75
|
-
console.log(fmt.dim(` Added Pen info to ${PROJECT_CONFIG_FILENAME}.`));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
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';
|
|
7
|
+
import { fmt, shortId } from '../utils/format.js';
|
|
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 { runBatchPush } from '../workflows/batch-pens.js';
|
|
13
|
+
import { offerBatchAllFallback, resolveBatchCommandTarget, } from '../workflows/batch-target.js';
|
|
14
|
+
import { createPenFromDirectory } from '../workflows/create-pen.js';
|
|
15
|
+
import { fetchLinkedPenOrHandleMissing } from '../workflows/missing-pen.js';
|
|
16
|
+
import { executePush } from '../workflows/push-pen.js';
|
|
17
|
+
export async function runPushCommand(options = {}) {
|
|
18
|
+
const output = options.output ?? defaultOutput;
|
|
19
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
20
|
+
const jsonMode = Boolean(options.json);
|
|
21
|
+
const interactive = !jsonMode && (options.interactive ?? isInteractive());
|
|
22
|
+
assertValidVersionLabel(options.label);
|
|
23
|
+
const resolvedAccess = resolveAccessOrVisibility(options.access, options.visibility);
|
|
24
|
+
const executeBatch = async (rootDir, discovered) => {
|
|
25
|
+
if (options.title?.trim()) {
|
|
26
|
+
throw new CliError(400, '--title cannot be used when pushing multiple Pens in a directory tree.');
|
|
78
27
|
}
|
|
28
|
+
const batch = await runBatchPush({
|
|
29
|
+
rootDir,
|
|
30
|
+
discovered,
|
|
31
|
+
label: options.label,
|
|
32
|
+
force: options.force,
|
|
33
|
+
dryRun: options.dryRun,
|
|
34
|
+
wait: options.wait,
|
|
35
|
+
access: resolvedAccess,
|
|
36
|
+
password: options.password,
|
|
37
|
+
json: jsonMode,
|
|
38
|
+
interactive,
|
|
39
|
+
explicitProfile: options.explicitProfile,
|
|
40
|
+
baseUrl: options.baseUrl,
|
|
41
|
+
env: options.env,
|
|
42
|
+
homeDir: options.homeDir,
|
|
43
|
+
output,
|
|
44
|
+
prompts: options.prompts,
|
|
45
|
+
});
|
|
79
46
|
return {
|
|
80
|
-
pushed:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
changes: { added: [], modified: [], deleted: [] },
|
|
86
|
-
infoChanges: [],
|
|
87
|
-
appliedPatches: [],
|
|
88
|
-
remoteInfoChanged: infoAnalysis.remoteChanged,
|
|
47
|
+
pushed: !batch.dryRun && (batch.counts.pushed > 0 || batch.counts.created > 0),
|
|
48
|
+
created: !batch.dryRun && batch.counts.created > 0,
|
|
49
|
+
dryRun: batch.dryRun,
|
|
50
|
+
batch,
|
|
51
|
+
...(batch.exitCode !== undefined ? { exitCode: batch.exitCode } : {}),
|
|
89
52
|
};
|
|
90
|
-
}
|
|
91
|
-
const changes = {
|
|
92
|
-
added: diff.added.map((item) => item.path),
|
|
93
|
-
modified: diff.modified.map((item) => item.path),
|
|
94
|
-
deleted: diff.deleted.map((item) => item.path),
|
|
95
53
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
54
|
+
const resolvedTarget = await resolveBatchCommandTarget({
|
|
55
|
+
commandName: 'push',
|
|
56
|
+
cwd,
|
|
57
|
+
target: options.target,
|
|
58
|
+
interactive,
|
|
59
|
+
output,
|
|
60
|
+
prompts: options.prompts,
|
|
61
|
+
});
|
|
62
|
+
if (resolvedTarget.mode === 'batch') {
|
|
63
|
+
return executeBatch(resolvedTarget.rootDir, resolvedTarget.discovered);
|
|
107
64
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
else {
|
|
124
|
-
fileChanges.push({
|
|
125
|
-
path: item.path,
|
|
126
|
-
content: local.textContent ?? '',
|
|
127
|
-
});
|
|
128
|
-
}
|
|
65
|
+
const targetCwd = resolvedTarget.targetDir;
|
|
66
|
+
const nearest = await findNearestConfig(targetCwd);
|
|
67
|
+
if (!nearest) {
|
|
68
|
+
const fallback = await offerBatchAllFallback({
|
|
69
|
+
commandName: 'push',
|
|
70
|
+
targetDir: targetCwd,
|
|
71
|
+
fromExplicitDir: resolvedTarget.fromExplicitDir,
|
|
72
|
+
displayDir: resolvedTarget.displayDir,
|
|
73
|
+
dryRun: options.dryRun,
|
|
74
|
+
interactive,
|
|
75
|
+
output,
|
|
76
|
+
prompts: options.prompts,
|
|
77
|
+
});
|
|
78
|
+
if (fallback.action === 'batch') {
|
|
79
|
+
return executeBatch(targetCwd, fallback.discovered);
|
|
129
80
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
path: item.path,
|
|
133
|
-
delete: true,
|
|
134
|
-
});
|
|
81
|
+
if (fallback.action === 'canceled') {
|
|
82
|
+
return { pushed: false, created: false, dryRun: Boolean(options.dryRun), aborted: true };
|
|
135
83
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
84
|
+
}
|
|
85
|
+
// First-time push: no linked .cdpn.json found -> push local folder as a brand-new CodePen 2.0 Pen
|
|
86
|
+
if (!nearest || !nearest.linked) {
|
|
87
|
+
if (options.dryRun) {
|
|
88
|
+
throw new CliError(400, nearest
|
|
89
|
+
? `${PROJECT_CONFIG_FILENAME} in ${nearest.rootDir} is not linked to an online Pen yet. --dry-run is only supported for an existing synced Pen.`
|
|
90
|
+
: `No ${PROJECT_CONFIG_FILENAME} found. --dry-run is only supported for an existing synced Pen.`);
|
|
140
91
|
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}, binaryUploads);
|
|
148
|
-
finalBuild = writeResult.build;
|
|
149
|
-
if (finalBuild && shouldWait) {
|
|
150
|
-
let lastStatus = `${finalBuild.status}:${finalBuild.id}`;
|
|
151
|
-
finalBuild = await client.settleBuild(finalBuild, {
|
|
152
|
-
onUpdate: (b) => {
|
|
153
|
-
if (silent)
|
|
154
|
-
return;
|
|
155
|
-
const key = `${b.status}:${b.id}`;
|
|
156
|
-
if (key !== lastStatus) {
|
|
157
|
-
lastStatus = key;
|
|
158
|
-
if (b.status === 'Running' || b.status === 'Queued') {
|
|
159
|
-
console.log(fmt.dim(` Build ${shortId(b.id)}: ${b.status}…`));
|
|
160
|
-
}
|
|
161
|
-
else if (b.status === 'Canceled' && b.next_id) {
|
|
162
|
-
console.log(fmt.dim(' Compiler requested patches — waiting for converged rebuild…'));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
});
|
|
92
|
+
const targetDir = nearest ? nearest.rootDir : targetCwd;
|
|
93
|
+
const folderDisplay = path.relative(cwd, targetDir) || '.';
|
|
94
|
+
if (!jsonMode) {
|
|
95
|
+
output.log(fmt.dim(nearest
|
|
96
|
+
? `Found unlinked ${PROJECT_CONFIG_FILENAME} with saved Pen info — pushing this local folder as a new CodePen 2.0 Pen.`
|
|
97
|
+
: `No ${PROJECT_CONFIG_FILENAME} found — pushing this local folder as a new CodePen 2.0 Pen.`));
|
|
167
98
|
}
|
|
168
|
-
|
|
169
|
-
|
|
99
|
+
const created = await createPenFromDirectory({
|
|
100
|
+
targetDir,
|
|
101
|
+
folderDisplay,
|
|
102
|
+
explicitProfile: options.explicitProfile,
|
|
103
|
+
title: options.title,
|
|
104
|
+
access: resolvedAccess,
|
|
105
|
+
password: options.password,
|
|
106
|
+
force: options.force,
|
|
107
|
+
wait: options.wait,
|
|
108
|
+
silent: jsonMode,
|
|
109
|
+
output,
|
|
110
|
+
baseUrl: options.baseUrl,
|
|
111
|
+
interactive,
|
|
112
|
+
env: options.env,
|
|
113
|
+
homeDir: options.homeDir,
|
|
114
|
+
prompts: options.prompts,
|
|
115
|
+
});
|
|
116
|
+
if (!created) {
|
|
117
|
+
return { pushed: false, created: false, dryRun: false, aborted: true };
|
|
170
118
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
});
|
|
188
|
-
if (!silent) {
|
|
189
|
-
console.log(fmt.cyan('✓ Synced compiler patches back to local folder.'));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Re-scan local hashes so .cdpn.json reflects exact post-patch local state
|
|
193
|
-
const postPushLocalFiles = await scanLocalFiles(project.rootDir);
|
|
194
|
-
localShaByPath = new Map();
|
|
195
|
-
for (const [p, lf] of postPushLocalFiles) {
|
|
196
|
-
localShaByPath.set(p, lf.sha256);
|
|
197
|
-
}
|
|
198
|
-
finalRemoteFiles = convergedFiles ?? (await client.getPenFiles(pen.id));
|
|
199
|
-
// If an info PATCH is still pending, persist the synced file manifest now while preserving
|
|
200
|
-
// unpushed local `info` so a subsequent info validation error never leaves version metadata stale.
|
|
201
|
-
if (shouldPushInfo) {
|
|
202
|
-
const intermediateConfig = {
|
|
203
|
-
url: project.config.url || updatedPen.urls.editor,
|
|
204
|
-
pen_id: updatedPen.id,
|
|
205
|
-
...(project.config.profile ? { profile: project.config.profile } : {}),
|
|
206
|
-
last_synced_version_id: finalVersionId,
|
|
207
|
-
...(project.config.last_synced_info_hash
|
|
208
|
-
? { last_synced_info_hash: project.config.last_synced_info_hash }
|
|
209
|
-
: {}),
|
|
210
|
-
editor: updatedPen.editor,
|
|
211
|
-
...(project.config.info !== undefined ? { info: project.config.info } : {}),
|
|
212
|
-
files: buildSyncedFileMap(finalRemoteFiles, localShaByPath),
|
|
213
|
-
};
|
|
214
|
-
await writeProjectConfig(project.rootDir, intermediateConfig);
|
|
215
|
-
project.config = intermediateConfig;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (options.dryRun) {
|
|
220
|
-
if (!silent) {
|
|
221
|
-
console.log(`\n${fmt.cyan('ℹ')} Dry run complete — no changes were saved to CodePen` +
|
|
222
|
-
(hasFileChanges && finalVersionId
|
|
223
|
-
? ` ${fmt.dim(`(ephemeral version ${shortId(finalVersionId)})`)}.`
|
|
224
|
-
: '.'));
|
|
119
|
+
const buildFailed = created.build?.status === 'Failed';
|
|
120
|
+
if (jsonMode) {
|
|
121
|
+
printJsonResponse(buildFailed ? 422 : 201, buildFailed
|
|
122
|
+
? `Created Pen ${created.pen.title || 'Untitled'} (${created.pen.id}), but the initial build failed.`
|
|
123
|
+
: `Created Pen ${created.pen.title || 'Untitled'} (${created.pen.id}).`, {
|
|
124
|
+
pushed: true,
|
|
125
|
+
created: true,
|
|
126
|
+
dry_run: false,
|
|
127
|
+
pen: created.pen,
|
|
128
|
+
profile: created.auth.profile,
|
|
129
|
+
folder: folderDisplay,
|
|
130
|
+
root_dir: created.project.rootDir,
|
|
131
|
+
config_path: created.project.configPath,
|
|
132
|
+
version_id: created.versionId,
|
|
133
|
+
build: created.build,
|
|
134
|
+
}, output);
|
|
225
135
|
}
|
|
226
136
|
return {
|
|
227
|
-
pushed:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
appliedPatches,
|
|
137
|
+
pushed: true,
|
|
138
|
+
created: true,
|
|
139
|
+
dryRun: false,
|
|
140
|
+
pen: created.pen,
|
|
141
|
+
versionId: created.versionId,
|
|
142
|
+
build: created.build,
|
|
143
|
+
...(created.exitCode !== undefined ? { exitCode: created.exitCode } : {}),
|
|
235
144
|
};
|
|
236
145
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
updatedPen = await client.updatePen(pen.id, infoPatch);
|
|
242
|
-
}
|
|
243
|
-
const nextConfig = {
|
|
244
|
-
url: project.config.url || updatedPen.urls.editor,
|
|
245
|
-
pen_id: updatedPen.id,
|
|
246
|
-
...(project.config.profile ? { profile: project.config.profile } : {}),
|
|
247
|
-
last_synced_version_id: hasFileChanges ? finalVersionId : project.config.last_synced_version_id,
|
|
248
|
-
editor: updatedPen.editor,
|
|
249
|
-
...buildPenInfoConfigFields(updatedPen),
|
|
250
|
-
...(hasFileChanges && finalRemoteFiles && localShaByPath
|
|
251
|
-
? { files: buildSyncedFileMap(finalRemoteFiles, localShaByPath) }
|
|
252
|
-
: project.config.files
|
|
253
|
-
? { files: project.config.files }
|
|
254
|
-
: {}),
|
|
146
|
+
const project = {
|
|
147
|
+
rootDir: nearest.rootDir,
|
|
148
|
+
configPath: nearest.configPath,
|
|
149
|
+
config: nearest.config,
|
|
255
150
|
};
|
|
256
|
-
await
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
151
|
+
const auth = await resolveCommandAuth({
|
|
152
|
+
explicitProfile: options.explicitProfile,
|
|
153
|
+
project,
|
|
154
|
+
interactive,
|
|
155
|
+
persistProfileToProject: !jsonMode,
|
|
156
|
+
output,
|
|
157
|
+
env: options.env,
|
|
158
|
+
homeDir: options.homeDir,
|
|
159
|
+
selectProfile: options.prompts?.select,
|
|
160
|
+
});
|
|
161
|
+
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
162
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
163
|
+
client,
|
|
164
|
+
project,
|
|
165
|
+
auth,
|
|
166
|
+
commandName: 'push',
|
|
167
|
+
interactive,
|
|
168
|
+
json: jsonMode,
|
|
169
|
+
output,
|
|
170
|
+
prompts: options.prompts,
|
|
171
|
+
});
|
|
172
|
+
if (!penLookup.found) {
|
|
173
|
+
return { pushed: false, created: false, dryRun: Boolean(options.dryRun), aborted: true };
|
|
174
|
+
}
|
|
175
|
+
const result = await executePush(client, project, {
|
|
176
|
+
label: options.label,
|
|
177
|
+
force: options.force,
|
|
178
|
+
dryRun: options.dryRun,
|
|
179
|
+
wait: options.wait,
|
|
180
|
+
title: options.title,
|
|
181
|
+
access: resolvedAccess,
|
|
182
|
+
password: options.password,
|
|
183
|
+
json: jsonMode,
|
|
184
|
+
prefetchedPen: penLookup.pen,
|
|
185
|
+
silent: jsonMode,
|
|
186
|
+
output,
|
|
187
|
+
});
|
|
188
|
+
const hasFileChanges = result.changes.added.length > 0 ||
|
|
189
|
+
result.changes.modified.length > 0 ||
|
|
190
|
+
result.changes.deleted.length > 0;
|
|
191
|
+
const buildFailed = hasFileChanges && result.build?.status === 'Failed';
|
|
192
|
+
if (jsonMode) {
|
|
193
|
+
const payload = {
|
|
194
|
+
pushed: result.pushed,
|
|
195
|
+
created: false,
|
|
196
|
+
dry_run: result.dryRun,
|
|
197
|
+
pen: result.pen,
|
|
198
|
+
profile: auth.profile,
|
|
199
|
+
version_id: result.versionId,
|
|
200
|
+
build: result.build,
|
|
201
|
+
changes: result.changes,
|
|
202
|
+
info_changes: result.infoChanges,
|
|
203
|
+
applied_patches: result.appliedPatches,
|
|
204
|
+
};
|
|
205
|
+
if (result.dryRun) {
|
|
206
|
+
printJsonResponse(buildFailed ? 422 : 200, buildFailed
|
|
207
|
+
? 'Dry run completed, but the build failed.'
|
|
208
|
+
: 'Dry run complete — no changes were saved to CodePen.', payload, output);
|
|
261
209
|
}
|
|
262
|
-
else if (
|
|
263
|
-
|
|
210
|
+
else if (!result.pushed) {
|
|
211
|
+
printJsonResponse(200, result.remoteInfoChanged
|
|
212
|
+
? `No local changes to push. Remote Pen info has changed on CodePen — run \`cdpn pull\` to update ${PROJECT_CONFIG_FILENAME}, or \`cdpn push --force\` to overwrite.`
|
|
213
|
+
: 'Everything is up to date — nothing to push.', payload, output);
|
|
264
214
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (!silent) {
|
|
268
|
-
console.log(`\n${fmt.yellow('!')} Files were saved as version ${fmt.dim(shortId(finalVersionId))}, but the build failed.`);
|
|
215
|
+
else if (buildFailed) {
|
|
216
|
+
printJsonResponse(422, `Files were saved as version ${shortId(result.versionId)}, but the build failed.`, payload, output);
|
|
269
217
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
else if (!silent) {
|
|
273
|
-
if (hasFileChanges) {
|
|
274
|
-
console.log(`\n${fmt.green('✓')} Pushed successfully ${fmt.dim(`(version ${shortId(finalVersionId)})`)}`);
|
|
275
|
-
console.log(` Preview: ${fmt.cyan(updatedPen.urls.preview)}`);
|
|
218
|
+
else if (!hasFileChanges && result.infoChanges.length > 0) {
|
|
219
|
+
printJsonResponse(200, `Updated Pen info (${result.infoChanges.map((c) => c.field).join(', ')}).`, payload, output);
|
|
276
220
|
}
|
|
277
221
|
else {
|
|
278
|
-
|
|
279
|
-
console.log(` Editor: ${fmt.cyan(updatedPen.urls.editor)}`);
|
|
280
|
-
console.log(` Preview: ${fmt.cyan(updatedPen.urls.preview)}`);
|
|
222
|
+
printJsonResponse(200, `Pushed successfully (version ${shortId(result.versionId)}).`, payload, output);
|
|
281
223
|
}
|
|
282
224
|
}
|
|
283
225
|
return {
|
|
284
|
-
pushed:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
226
|
+
pushed: result.pushed,
|
|
227
|
+
created: false,
|
|
228
|
+
dryRun: result.dryRun,
|
|
229
|
+
pen: result.pen,
|
|
230
|
+
versionId: result.versionId,
|
|
231
|
+
build: result.build,
|
|
232
|
+
changes: result.changes,
|
|
233
|
+
infoChanges: result.infoChanges,
|
|
234
|
+
appliedPatches: result.appliedPatches,
|
|
235
|
+
...(result.exitCode !== undefined ? { exitCode: result.exitCode } : {}),
|
|
292
236
|
};
|
|
293
237
|
}
|
|
294
238
|
export function registerPushCommand(program) {
|
|
295
239
|
program
|
|
296
240
|
.command('push')
|
|
297
|
-
.
|
|
241
|
+
.argument('[target]', 'Directory path to push, or "all" to push all Pens in subdirectories')
|
|
242
|
+
.allowExcessArguments(false)
|
|
243
|
+
.description('Push local file and Pen info changes to CodePen (pass "all" to walk subdirectories, or push an unlinked folder as a new Pen)')
|
|
298
244
|
.option('-m, --label <label>', 'Label for the saved version (max 80 chars)')
|
|
299
245
|
.option('-f, --force', 'Overwrite remote head if moved (or skip missing index.html prompt on first push)')
|
|
300
|
-
.option('--dry-run', '
|
|
246
|
+
.option('--dry-run', 'Preview changes without saving them to CodePen')
|
|
301
247
|
.option('--no-wait', 'Return as soon as files are saved without waiting for the build')
|
|
302
248
|
.option('-t, --title <title>', 'Title for the new Pen when pushing an unlinked folder for the first time')
|
|
303
249
|
.option('--access <level>', 'Privacy for a new Pen: Public, Private, Protected, or Collaborators')
|
|
250
|
+
.option('--visibility <level>', 'Alias for --access')
|
|
304
251
|
.option('--password <password>', 'Password for a new Protected Pen (min 8 chars)')
|
|
305
252
|
.option('--json', 'Output push result as JSON')
|
|
306
|
-
.action(async (options, command) => {
|
|
307
|
-
|
|
308
|
-
throw new CliError(400, 'Version label must be at most 80 characters.');
|
|
309
|
-
}
|
|
310
|
-
const explicitProfile = getGlobalProfileOption(command);
|
|
311
|
-
const nearest = await findNearestConfig(process.cwd());
|
|
312
|
-
// First-time push: no linked .cdpn.json found -> push local folder as a brand-new CodePen 2.0 Pen
|
|
313
|
-
if (!nearest || !nearest.linked) {
|
|
314
|
-
if (options.dryRun) {
|
|
315
|
-
throw new CliError(400, nearest
|
|
316
|
-
? `${PROJECT_CONFIG_FILENAME} in ${nearest.rootDir} is not linked to an online Pen yet. --dry-run is only supported for an existing synced Pen.`
|
|
317
|
-
: `No ${PROJECT_CONFIG_FILENAME} found. --dry-run is only supported for an existing synced Pen.`);
|
|
318
|
-
}
|
|
319
|
-
const targetDir = nearest ? nearest.rootDir : process.cwd();
|
|
320
|
-
const folderDisplay = path.relative(process.cwd(), targetDir) || '.';
|
|
321
|
-
if (!options.json) {
|
|
322
|
-
console.log(fmt.dim(nearest
|
|
323
|
-
? `Found unlinked ${PROJECT_CONFIG_FILENAME} with saved Pen info — pushing this local folder as a new CodePen 2.0 Pen.`
|
|
324
|
-
: `No ${PROJECT_CONFIG_FILENAME} found — pushing this local folder as a new CodePen 2.0 Pen.`));
|
|
325
|
-
}
|
|
326
|
-
const created = await createPenFromDirectory({
|
|
327
|
-
targetDir,
|
|
328
|
-
folderDisplay,
|
|
329
|
-
explicitProfile,
|
|
330
|
-
title: options.title,
|
|
331
|
-
access: options.access,
|
|
332
|
-
password: options.password,
|
|
333
|
-
force: options.force,
|
|
334
|
-
wait: options.wait,
|
|
335
|
-
silent: Boolean(options.json),
|
|
336
|
-
interactive: !options.json && isInteractive(),
|
|
337
|
-
});
|
|
338
|
-
if (created && options.json) {
|
|
339
|
-
const buildFailed = created.build?.status === 'Failed';
|
|
340
|
-
if (buildFailed) {
|
|
341
|
-
process.exitCode = 1;
|
|
342
|
-
}
|
|
343
|
-
printJsonResponse(buildFailed ? 422 : 201, buildFailed
|
|
344
|
-
? `Created Pen ${created.pen.title || 'Untitled'} (${created.pen.id}), but the initial build failed.`
|
|
345
|
-
: `Created Pen ${created.pen.title || 'Untitled'} (${created.pen.id}).`, {
|
|
346
|
-
pushed: true,
|
|
347
|
-
created: true,
|
|
348
|
-
dry_run: false,
|
|
349
|
-
pen: created.pen,
|
|
350
|
-
profile: created.auth.profile,
|
|
351
|
-
folder: folderDisplay,
|
|
352
|
-
root_dir: created.project.rootDir,
|
|
353
|
-
config_path: created.project.configPath,
|
|
354
|
-
version_id: created.versionId,
|
|
355
|
-
build: created.build,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
const project = {
|
|
361
|
-
rootDir: nearest.rootDir,
|
|
362
|
-
configPath: nearest.configPath,
|
|
363
|
-
config: nearest.config,
|
|
364
|
-
};
|
|
365
|
-
const auth = await resolveCommandAuth({
|
|
366
|
-
explicitProfile,
|
|
367
|
-
project,
|
|
368
|
-
interactive: !options.json && isInteractive(),
|
|
369
|
-
persistProfileToProject: !options.json,
|
|
370
|
-
});
|
|
371
|
-
const client = new CodePenClient({ apiKey: auth.apiKey });
|
|
372
|
-
const result = await executePush(client, project, {
|
|
253
|
+
.action(async (target, options, command) => {
|
|
254
|
+
const result = await runPushCommand({
|
|
373
255
|
...options,
|
|
374
|
-
|
|
256
|
+
target,
|
|
257
|
+
explicitProfile: getGlobalProfileOption(command),
|
|
375
258
|
});
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
result.changes.modified.length > 0 ||
|
|
379
|
-
result.changes.deleted.length > 0;
|
|
380
|
-
const buildFailed = hasFileChanges && result.build?.status === 'Failed';
|
|
381
|
-
const payload = {
|
|
382
|
-
pushed: result.pushed,
|
|
383
|
-
created: false,
|
|
384
|
-
dry_run: result.dryRun,
|
|
385
|
-
pen: result.pen,
|
|
386
|
-
profile: auth.profile,
|
|
387
|
-
version_id: result.versionId,
|
|
388
|
-
build: result.build,
|
|
389
|
-
changes: result.changes,
|
|
390
|
-
info_changes: result.infoChanges,
|
|
391
|
-
applied_patches: result.appliedPatches,
|
|
392
|
-
};
|
|
393
|
-
if (result.dryRun) {
|
|
394
|
-
if (buildFailed) {
|
|
395
|
-
process.exitCode = 1;
|
|
396
|
-
}
|
|
397
|
-
printJsonResponse(buildFailed ? 422 : 200, buildFailed
|
|
398
|
-
? 'Dry run completed, but the build failed.'
|
|
399
|
-
: 'Dry run complete — no changes were saved to CodePen.', payload);
|
|
400
|
-
}
|
|
401
|
-
else if (!result.pushed) {
|
|
402
|
-
printJsonResponse(200, result.remoteInfoChanged
|
|
403
|
-
? `No local changes to push. Remote Pen info has changed on CodePen — run \`cdpn pull\` to update ${PROJECT_CONFIG_FILENAME}, or \`cdpn push --force\` to overwrite.`
|
|
404
|
-
: 'Everything is up to date — nothing to push.', payload);
|
|
405
|
-
}
|
|
406
|
-
else if (buildFailed) {
|
|
407
|
-
process.exitCode = 1;
|
|
408
|
-
printJsonResponse(422, `Files were saved as version ${shortId(result.versionId)}, but the build failed.`, payload);
|
|
409
|
-
}
|
|
410
|
-
else if (!hasFileChanges && result.infoChanges.length > 0) {
|
|
411
|
-
printJsonResponse(200, `Updated Pen info (${result.infoChanges.map((c) => c.field).join(', ')}).`, payload);
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
printJsonResponse(200, `Pushed successfully (version ${shortId(result.versionId)}).`, payload);
|
|
415
|
-
}
|
|
259
|
+
if (result.exitCode !== undefined) {
|
|
260
|
+
process.exitCode = result.exitCode;
|
|
416
261
|
}
|
|
417
262
|
});
|
|
418
263
|
}
|