codepen-commander 1.1.0 → 1.3.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 +20 -5
- package/commands/clone.js +2 -0
- package/commands/create-pen.js +53 -23
- package/commands/delete.js +68 -20
- package/commands/deploy.js +22 -7
- package/commands/fork.js +2 -0
- package/commands/meta.js +66 -46
- package/commands/new.js +2 -0
- package/commands/privacy.js +5 -1
- package/commands/pull.js +22 -4
- package/commands/push.js +223 -99
- package/commands/status.js +156 -97
- package/commands/versions.js +2 -0
- package/config/project.js +94 -16
- package/package.json +1 -1
- package/sync/info.js +339 -0
package/commands/pull.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { CodePenClient } from '../api/client.js';
|
|
2
|
-
import { buildSyncedFileMap, requireProject, writeProjectConfig, } from '../config/project.js';
|
|
2
|
+
import { buildSyncedFileMap, PROJECT_CONFIG_FILENAME, requireProject, writeProjectConfig, } from '../config/project.js';
|
|
3
3
|
import { detectLocalChangesFromBaseline } from '../sync/diff.js';
|
|
4
4
|
import { scanLocalFiles } from '../sync/fs.js';
|
|
5
|
+
import { analyzeInfoSync, buildPenInfoConfigFields, hasAnyPenInfoFields, isLocalInfoDirty, } from '../sync/info.js';
|
|
5
6
|
import { syncRemoteFilesToDisk } from '../sync/materialize.js';
|
|
6
7
|
import { fmt, shortId } from '../utils/format.js';
|
|
7
8
|
import { CliError, printJsonResponse } from '../utils/json.js';
|
|
8
9
|
import { isInteractive, promptConfirm, promptSelect, } from '../utils/prompts.js';
|
|
9
10
|
import { getGlobalProfileOption, resolveCommandAuth } from './auth-context.js';
|
|
10
11
|
/**
|
|
11
|
-
* Pulls the latest remote files from CodePen into an existing cloned folder
|
|
12
|
+
* Pulls the latest remote files and Pen metadata from CodePen into an existing cloned folder
|
|
13
|
+
* containing `.cdpn.json`.
|
|
12
14
|
* Returns `null` if the user cancels interactively when uncommitted local changes are present.
|
|
13
15
|
*/
|
|
14
16
|
export async function pullPenCommand(options = {}) {
|
|
@@ -36,7 +38,8 @@ export async function pullPenCommand(options = {}) {
|
|
|
36
38
|
const localFiles = await scanLocalFiles(rootDir);
|
|
37
39
|
const localDirty = detectLocalChangesFromBaseline(localFiles, config.files);
|
|
38
40
|
const dirtyCount = localDirty.added.length + localDirty.modified.length + localDirty.deleted.length;
|
|
39
|
-
|
|
41
|
+
const localInfoDirty = isLocalInfoDirty(config.info, config.last_synced_info_hash);
|
|
42
|
+
if ((dirtyCount > 0 || localInfoDirty) && !force) {
|
|
40
43
|
if (!jsonMode) {
|
|
41
44
|
console.log(fmt.yellow('\nWarning: You have uncommitted local changes that will be overwritten:'));
|
|
42
45
|
for (const p of localDirty.added)
|
|
@@ -45,9 +48,15 @@ export async function pullPenCommand(options = {}) {
|
|
|
45
48
|
console.log(` ${fmt.yellow('~')} ${p} ${fmt.dim('(will be overwritten)')}`);
|
|
46
49
|
for (const p of localDirty.deleted)
|
|
47
50
|
console.log(` ${fmt.red('-')} ${p} ${fmt.dim('(will be restored)')}`);
|
|
51
|
+
if (localInfoDirty) {
|
|
52
|
+
console.log(` ${fmt.yellow('~')} ${PROJECT_CONFIG_FILENAME} (info) ${fmt.dim('(will be overwritten)')}`);
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
if (!interactive) {
|
|
50
|
-
throw new CliError(409, 'Local changes detected. Commit/push them first, or re-run with --force.', {
|
|
56
|
+
throw new CliError(409, 'Local changes detected. Commit/push them first, or re-run with --force.', {
|
|
57
|
+
dirty_files: localDirty,
|
|
58
|
+
...(localInfoDirty ? { dirty_info: true } : {}),
|
|
59
|
+
});
|
|
51
60
|
}
|
|
52
61
|
const ok = await confirmImpl('\nOverwrite local changes with remote version?', false);
|
|
53
62
|
if (!ok) {
|
|
@@ -59,6 +68,8 @@ export async function pullPenCommand(options = {}) {
|
|
|
59
68
|
client.getPen(config.pen_id),
|
|
60
69
|
client.getPenFiles(config.pen_id),
|
|
61
70
|
]);
|
|
71
|
+
const hadInfoBefore = hasAnyPenInfoFields(config.info);
|
|
72
|
+
const infoAnalysis = analyzeInfoSync(config.info, config.last_synced_info_hash, pen);
|
|
62
73
|
const result = await syncRemoteFilesToDisk({
|
|
63
74
|
client,
|
|
64
75
|
rootDir,
|
|
@@ -74,6 +85,7 @@ export async function pullPenCommand(options = {}) {
|
|
|
74
85
|
...(profileToPersist ? { profile: profileToPersist } : {}),
|
|
75
86
|
last_synced_version_id: pen.saved_version?.id ?? null,
|
|
76
87
|
editor: pen.editor,
|
|
88
|
+
...buildPenInfoConfigFields(pen),
|
|
77
89
|
files: syncedFiles,
|
|
78
90
|
};
|
|
79
91
|
const configPath = await writeProjectConfig(rootDir, nextConfig);
|
|
@@ -95,6 +107,12 @@ export async function pullPenCommand(options = {}) {
|
|
|
95
107
|
}
|
|
96
108
|
console.log(` Updated: ${result.writtenPaths.length} file(s)` +
|
|
97
109
|
(result.deletedPaths.length > 0 ? `, removed ${result.deletedPaths.length} deleted file(s)` : ''));
|
|
110
|
+
if (!hadInfoBefore) {
|
|
111
|
+
console.log(` Info: ${fmt.dim(`added to ${PROJECT_CONFIG_FILENAME}`)}`);
|
|
112
|
+
}
|
|
113
|
+
else if (infoAnalysis.changes.length > 0) {
|
|
114
|
+
console.log(` Info: ${fmt.dim(`updated ${infoAnalysis.changes.map((c) => c.field).join(', ')} in ${PROJECT_CONFIG_FILENAME}`)}`);
|
|
115
|
+
}
|
|
98
116
|
if (pen.saved_version) {
|
|
99
117
|
console.log(` Version: ${fmt.dim(shortId(pen.saved_version.id))}`);
|
|
100
118
|
}
|
package/commands/push.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { CodePenClient } from '../api/client.js';
|
|
2
|
-
import { buildSyncedFileMap,
|
|
3
|
+
import { buildSyncedFileMap, findNearestConfig, PROJECT_CONFIG_FILENAME, writeProjectConfig, } from '../config/project.js';
|
|
3
4
|
import { getGlobalProfileOption, resolveCommandAuth } from './auth-context.js';
|
|
4
5
|
import { createPenFromDirectory } from './create-pen.js';
|
|
5
6
|
import { computeSyncDiff, hasDiffChanges } from '../sync/diff.js';
|
|
6
7
|
import { scanLocalFiles } from '../sync/fs.js';
|
|
8
|
+
import { analyzeInfoSync, buildInfoUpdatePatch, buildPenInfoConfigFields, formatInfoValue, hashPenInfo, isCompletePenInfo, } from '../sync/info.js';
|
|
7
9
|
import { applyCompilerPatchesToDisk } from '../sync/materialize.js';
|
|
8
10
|
import { fmt, printBuildSummary, shortId } from '../utils/format.js';
|
|
9
11
|
import { CliError, printJsonResponse } from '../utils/json.js';
|
|
@@ -33,9 +35,46 @@ export async function executePush(client, project, options = {}) {
|
|
|
33
35
|
baseline: project.config.files,
|
|
34
36
|
downloadFile: (url) => client.downloadFile(url),
|
|
35
37
|
});
|
|
36
|
-
|
|
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
|
+
}
|
|
37
68
|
if (!silent) {
|
|
38
|
-
|
|
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
|
+
}
|
|
39
78
|
}
|
|
40
79
|
return {
|
|
41
80
|
pushed: false,
|
|
@@ -44,7 +83,9 @@ export async function executePush(client, project, options = {}) {
|
|
|
44
83
|
versionId: remoteHead,
|
|
45
84
|
build: pen.saved_version?.build ?? null,
|
|
46
85
|
changes: { added: [], modified: [], deleted: [] },
|
|
86
|
+
infoChanges: [],
|
|
47
87
|
appliedPatches: [],
|
|
88
|
+
remoteInfoChanged: infoAnalysis.remoteChanged,
|
|
48
89
|
};
|
|
49
90
|
}
|
|
50
91
|
const changes = {
|
|
@@ -60,122 +101,184 @@ export async function executePush(client, project, options = {}) {
|
|
|
60
101
|
console.log(` ${fmt.yellow('~')} ${item.path}`);
|
|
61
102
|
for (const item of diff.deleted)
|
|
62
103
|
console.log(` ${fmt.red('-')} ${item.path}`);
|
|
104
|
+
for (const change of infoChangesToPush) {
|
|
105
|
+
console.log(` ${fmt.yellow('~')} info.${change.field}: ${formatInfoValue(change.field, change.remote)} → ${formatInfoValue(change.field, change.local)}`);
|
|
106
|
+
}
|
|
63
107
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
let finalBuild = pen.saved_version?.build ?? null;
|
|
109
|
+
let finalVersionId = remoteHead;
|
|
110
|
+
let appliedPatches = [];
|
|
111
|
+
let updatedPen = pen;
|
|
112
|
+
let finalRemoteFiles;
|
|
113
|
+
let localShaByPath;
|
|
114
|
+
if (hasFileChanges) {
|
|
115
|
+
const fileChanges = [];
|
|
116
|
+
const binaryUploads = [];
|
|
117
|
+
for (const item of [...diff.added, ...diff.modified]) {
|
|
118
|
+
const local = item.local;
|
|
119
|
+
// Note: CodePen API returns 400 on empty multipart parts, so 0-byte files always go as text JSON
|
|
120
|
+
if (local.isBinary && local.buffer.length > 0) {
|
|
121
|
+
binaryUploads.push({ path: item.path, content: local.buffer });
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
fileChanges.push({
|
|
125
|
+
path: item.path,
|
|
126
|
+
content: local.textContent ?? '',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
71
129
|
}
|
|
72
|
-
|
|
130
|
+
for (const item of diff.deleted) {
|
|
73
131
|
fileChanges.push({
|
|
74
132
|
path: item.path,
|
|
75
|
-
|
|
133
|
+
delete: true,
|
|
76
134
|
});
|
|
77
135
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
lastStatus = key;
|
|
107
|
-
if (b.status === 'Running' || b.status === 'Queued') {
|
|
108
|
-
console.log(fmt.dim(` Build ${shortId(b.id)}: ${b.status}…`));
|
|
109
|
-
}
|
|
110
|
-
else if (b.status === 'Canceled' && b.next_id) {
|
|
111
|
-
console.log(fmt.dim(' Compiler requested patches — waiting for converged rebuild…'));
|
|
136
|
+
const expectedVersionId = options.force ? undefined : (localHead ?? remoteHead ?? undefined);
|
|
137
|
+
const shouldWait = options.wait !== false;
|
|
138
|
+
if (!silent) {
|
|
139
|
+
console.log(shouldWait ? '\nUploading and building on CodePen…' : '\nUploading to CodePen…');
|
|
140
|
+
}
|
|
141
|
+
const writeResult = await client.writePenFiles(pen.id, {
|
|
142
|
+
files: fileChanges,
|
|
143
|
+
...(options.label ? { label: options.label } : {}),
|
|
144
|
+
...(expectedVersionId ? { expected_version_id: expectedVersionId } : {}),
|
|
145
|
+
...(options.dryRun ? { dry_run: true } : {}),
|
|
146
|
+
wait: shouldWait ? 45 : 0,
|
|
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
|
+
}
|
|
112
164
|
}
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (finalBuild && !silent) {
|
|
169
|
+
printBuildSummary(finalBuild);
|
|
170
|
+
}
|
|
171
|
+
finalVersionId = finalBuild?.version_id ?? writeResult.version?.id ?? null;
|
|
172
|
+
appliedPatches = finalBuild?.applied_patches ?? [];
|
|
173
|
+
updatedPen = writeResult.pen ?? pen;
|
|
174
|
+
if (!options.dryRun) {
|
|
175
|
+
// Re-read the converged version's source files so we write back any compiler patches
|
|
176
|
+
let convergedFiles = writeResult.version?.files;
|
|
177
|
+
if (finalVersionId && (appliedPatches.length > 0 || !convergedFiles)) {
|
|
178
|
+
const version = await client.getVersion(finalVersionId);
|
|
179
|
+
convergedFiles = version.files;
|
|
180
|
+
}
|
|
181
|
+
if (finalBuild && appliedPatches.length > 0) {
|
|
182
|
+
await applyCompilerPatchesToDisk({
|
|
183
|
+
client,
|
|
184
|
+
rootDir: project.rootDir,
|
|
185
|
+
patches: appliedPatches,
|
|
186
|
+
convergedFiles,
|
|
187
|
+
});
|
|
188
|
+
if (!silent) {
|
|
189
|
+
console.log(fmt.cyan('✓ Synced compiler patches back to local folder.'));
|
|
113
190
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}
|
|
119
218
|
}
|
|
120
|
-
const finalVersionId = finalBuild?.version_id ?? writeResult.version?.id ?? null;
|
|
121
|
-
const appliedPatches = finalBuild?.applied_patches ?? [];
|
|
122
219
|
if (options.dryRun) {
|
|
123
220
|
if (!silent) {
|
|
124
|
-
console.log(`\n${fmt.cyan('ℹ')} Dry run complete — no changes were saved to CodePen
|
|
125
|
-
(
|
|
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
|
+
: '.'));
|
|
126
225
|
}
|
|
127
226
|
return {
|
|
128
227
|
pushed: false,
|
|
129
228
|
dryRun: true,
|
|
130
|
-
pen:
|
|
131
|
-
versionId: finalVersionId,
|
|
132
|
-
build: finalBuild,
|
|
229
|
+
pen: updatedPen,
|
|
230
|
+
versionId: hasFileChanges ? finalVersionId : remoteHead,
|
|
231
|
+
build: hasFileChanges ? finalBuild : null,
|
|
133
232
|
changes,
|
|
233
|
+
infoChanges: infoChangesToPush,
|
|
134
234
|
appliedPatches,
|
|
135
235
|
};
|
|
136
236
|
}
|
|
137
|
-
|
|
138
|
-
let convergedFiles = writeResult.version?.files;
|
|
139
|
-
if (finalVersionId && (appliedPatches.length > 0 || !convergedFiles)) {
|
|
140
|
-
const version = await client.getVersion(finalVersionId);
|
|
141
|
-
convergedFiles = version.files;
|
|
142
|
-
}
|
|
143
|
-
if (finalBuild && appliedPatches.length > 0) {
|
|
144
|
-
await applyCompilerPatchesToDisk({
|
|
145
|
-
client,
|
|
146
|
-
rootDir: project.rootDir,
|
|
147
|
-
patches: appliedPatches,
|
|
148
|
-
convergedFiles,
|
|
149
|
-
});
|
|
237
|
+
if (shouldPushInfo && infoPatch) {
|
|
150
238
|
if (!silent) {
|
|
151
|
-
console.log(
|
|
239
|
+
console.log('\nUpdating Pen info on CodePen…');
|
|
152
240
|
}
|
|
241
|
+
updatedPen = await client.updatePen(pen.id, infoPatch);
|
|
153
242
|
}
|
|
154
|
-
|
|
155
|
-
const postPushLocalFiles = await scanLocalFiles(project.rootDir);
|
|
156
|
-
const localShaByPath = new Map();
|
|
157
|
-
for (const [p, lf] of postPushLocalFiles) {
|
|
158
|
-
localShaByPath.set(p, lf.sha256);
|
|
159
|
-
}
|
|
160
|
-
const finalRemoteFiles = convergedFiles ?? (await client.getPenFiles(pen.id));
|
|
161
|
-
const updatedPen = writeResult.pen ?? pen;
|
|
162
|
-
await writeProjectConfig(project.rootDir, {
|
|
243
|
+
const nextConfig = {
|
|
163
244
|
url: project.config.url || updatedPen.urls.editor,
|
|
164
245
|
pen_id: updatedPen.id,
|
|
165
246
|
...(project.config.profile ? { profile: project.config.profile } : {}),
|
|
166
|
-
last_synced_version_id: finalVersionId,
|
|
247
|
+
last_synced_version_id: hasFileChanges ? finalVersionId : project.config.last_synced_version_id,
|
|
167
248
|
editor: updatedPen.editor,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
249
|
+
...buildPenInfoConfigFields(updatedPen),
|
|
250
|
+
...(hasFileChanges && finalRemoteFiles && localShaByPath
|
|
251
|
+
? { files: buildSyncedFileMap(finalRemoteFiles, localShaByPath) }
|
|
252
|
+
: project.config.files
|
|
253
|
+
? { files: project.config.files }
|
|
254
|
+
: {}),
|
|
255
|
+
};
|
|
256
|
+
await writeProjectConfig(project.rootDir, nextConfig);
|
|
257
|
+
project.config = nextConfig;
|
|
258
|
+
if (!silent) {
|
|
259
|
+
if (hasFileChanges && !shouldPushInfo && infoAnalysis.remoteChanged) {
|
|
260
|
+
console.log(fmt.cyan(`ℹ Synced remote Pen info into ${PROJECT_CONFIG_FILENAME}.`));
|
|
261
|
+
}
|
|
262
|
+
else if (hasFileChanges && !infoAnalysis.tracked) {
|
|
263
|
+
console.log(fmt.dim(`Added Pen info to ${PROJECT_CONFIG_FILENAME}.`));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (hasFileChanges && finalBuild?.status === 'Failed') {
|
|
171
267
|
if (!silent) {
|
|
172
268
|
console.log(`\n${fmt.yellow('!')} Files were saved as version ${fmt.dim(shortId(finalVersionId))}, but the build failed.`);
|
|
173
269
|
}
|
|
174
270
|
process.exitCode = 1;
|
|
175
271
|
}
|
|
176
272
|
else if (!silent) {
|
|
177
|
-
|
|
178
|
-
|
|
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)}`);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
console.log(`\n${fmt.green('✓')} Updated Pen info successfully.`);
|
|
279
|
+
console.log(` Editor: ${fmt.cyan(updatedPen.urls.editor)}`);
|
|
280
|
+
console.log(` Preview: ${fmt.cyan(updatedPen.urls.preview)}`);
|
|
281
|
+
}
|
|
179
282
|
}
|
|
180
283
|
return {
|
|
181
284
|
pushed: true,
|
|
@@ -184,13 +287,14 @@ export async function executePush(client, project, options = {}) {
|
|
|
184
287
|
versionId: finalVersionId,
|
|
185
288
|
build: finalBuild,
|
|
186
289
|
changes,
|
|
290
|
+
infoChanges: infoChangesToPush,
|
|
187
291
|
appliedPatches,
|
|
188
292
|
};
|
|
189
293
|
}
|
|
190
294
|
export function registerPushCommand(program) {
|
|
191
295
|
program
|
|
192
296
|
.command('push')
|
|
193
|
-
.description('Push local file changes to CodePen (or push an unlinked demo folder as a new Pen)')
|
|
297
|
+
.description('Push local file and Pen info changes to CodePen (or push an unlinked demo folder as a new Pen)')
|
|
194
298
|
.option('-m, --label <label>', 'Label for the saved version (max 80 chars)')
|
|
195
299
|
.option('-f, --force', 'Overwrite remote head if moved (or skip missing index.html prompt on first push)')
|
|
196
300
|
.option('--dry-run', 'Build proposed changes without saving them to the Pen head')
|
|
@@ -204,18 +308,24 @@ export function registerPushCommand(program) {
|
|
|
204
308
|
throw new CliError(400, 'Version label must be at most 80 characters.');
|
|
205
309
|
}
|
|
206
310
|
const explicitProfile = getGlobalProfileOption(command);
|
|
207
|
-
const
|
|
208
|
-
// First-time push: no .cdpn.json found -> push local folder as a brand-new CodePen 2.0 Pen
|
|
209
|
-
if (!
|
|
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) {
|
|
210
314
|
if (options.dryRun) {
|
|
211
|
-
throw new CliError(400,
|
|
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.`);
|
|
212
318
|
}
|
|
319
|
+
const targetDir = nearest ? nearest.rootDir : process.cwd();
|
|
320
|
+
const folderDisplay = path.relative(process.cwd(), targetDir) || '.';
|
|
213
321
|
if (!options.json) {
|
|
214
|
-
console.log(fmt.dim(
|
|
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.`));
|
|
215
325
|
}
|
|
216
326
|
const created = await createPenFromDirectory({
|
|
217
|
-
targetDir
|
|
218
|
-
folderDisplay
|
|
327
|
+
targetDir,
|
|
328
|
+
folderDisplay,
|
|
219
329
|
explicitProfile,
|
|
220
330
|
title: options.title,
|
|
221
331
|
access: options.access,
|
|
@@ -238,7 +348,7 @@ export function registerPushCommand(program) {
|
|
|
238
348
|
dry_run: false,
|
|
239
349
|
pen: created.pen,
|
|
240
350
|
profile: created.auth.profile,
|
|
241
|
-
folder:
|
|
351
|
+
folder: folderDisplay,
|
|
242
352
|
root_dir: created.project.rootDir,
|
|
243
353
|
config_path: created.project.configPath,
|
|
244
354
|
version_id: created.versionId,
|
|
@@ -247,6 +357,11 @@ export function registerPushCommand(program) {
|
|
|
247
357
|
}
|
|
248
358
|
return;
|
|
249
359
|
}
|
|
360
|
+
const project = {
|
|
361
|
+
rootDir: nearest.rootDir,
|
|
362
|
+
configPath: nearest.configPath,
|
|
363
|
+
config: nearest.config,
|
|
364
|
+
};
|
|
250
365
|
const auth = await resolveCommandAuth({
|
|
251
366
|
explicitProfile,
|
|
252
367
|
project,
|
|
@@ -259,7 +374,10 @@ export function registerPushCommand(program) {
|
|
|
259
374
|
silent: Boolean(options.json),
|
|
260
375
|
});
|
|
261
376
|
if (options.json) {
|
|
262
|
-
const
|
|
377
|
+
const hasFileChanges = result.changes.added.length > 0 ||
|
|
378
|
+
result.changes.modified.length > 0 ||
|
|
379
|
+
result.changes.deleted.length > 0;
|
|
380
|
+
const buildFailed = hasFileChanges && result.build?.status === 'Failed';
|
|
263
381
|
const payload = {
|
|
264
382
|
pushed: result.pushed,
|
|
265
383
|
created: false,
|
|
@@ -269,6 +387,7 @@ export function registerPushCommand(program) {
|
|
|
269
387
|
version_id: result.versionId,
|
|
270
388
|
build: result.build,
|
|
271
389
|
changes: result.changes,
|
|
390
|
+
info_changes: result.infoChanges,
|
|
272
391
|
applied_patches: result.appliedPatches,
|
|
273
392
|
};
|
|
274
393
|
if (result.dryRun) {
|
|
@@ -277,15 +396,20 @@ export function registerPushCommand(program) {
|
|
|
277
396
|
}
|
|
278
397
|
printJsonResponse(buildFailed ? 422 : 200, buildFailed
|
|
279
398
|
? 'Dry run completed, but the build failed.'
|
|
280
|
-
: 'Dry run complete — no changes were saved to CodePen
|
|
399
|
+
: 'Dry run complete — no changes were saved to CodePen.', payload);
|
|
281
400
|
}
|
|
282
401
|
else if (!result.pushed) {
|
|
283
|
-
printJsonResponse(200,
|
|
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);
|
|
284
405
|
}
|
|
285
406
|
else if (buildFailed) {
|
|
286
407
|
process.exitCode = 1;
|
|
287
408
|
printJsonResponse(422, `Files were saved as version ${shortId(result.versionId)}, but the build failed.`, payload);
|
|
288
409
|
}
|
|
410
|
+
else if (!hasFileChanges && result.infoChanges.length > 0) {
|
|
411
|
+
printJsonResponse(200, `Updated Pen info (${result.infoChanges.map((c) => c.field).join(', ')}).`, payload);
|
|
412
|
+
}
|
|
289
413
|
else {
|
|
290
414
|
printJsonResponse(200, `Pushed successfully (version ${shortId(result.versionId)}).`, payload);
|
|
291
415
|
}
|