codepen-commander 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -10
- package/api/client.js +129 -106
- package/cli.js +34 -29
- package/commands/auth/default.js +40 -0
- package/commands/auth/index.js +83 -0
- package/commands/auth/list.js +78 -0
- package/commands/auth/login.js +136 -0
- package/commands/auth/logout.js +186 -0
- package/commands/auth/status.js +212 -0
- package/commands/build.js +256 -0
- package/commands/clone.js +13 -581
- package/commands/delete.js +553 -37
- package/commands/deploy.js +164 -154
- package/commands/domains.js +83 -39
- package/commands/fork.js +13 -317
- package/commands/info.js +152 -0
- package/commands/init.js +375 -0
- package/commands/list.js +95 -78
- package/commands/new.js +155 -83
- package/commands/open.js +29 -19
- package/commands/privacy.js +52 -36
- package/commands/pull.js +123 -110
- package/commands/push.js +222 -365
- package/commands/restore.js +251 -0
- package/commands/rollback.js +141 -0
- package/commands/serve.js +119 -0
- package/commands/settings.js +126 -0
- package/commands/shell.js +305 -0
- package/commands/status.js +133 -39
- package/commands/sync.js +330 -0
- package/commands/undeploy.js +102 -0
- package/commands/unlink.js +191 -0
- package/commands/versions.js +100 -163
- package/config/auth.js +4 -374
- package/config/pen-blocks.js +166 -0
- package/config/project.js +179 -240
- package/config/user-store.js +364 -0
- package/constants.js +42 -0
- package/errors.js +17 -0
- package/package.json +1 -1
- package/shell/index.html +79 -0
- package/shell/scripts.js +276 -0
- package/shell/styles.css +492 -0
- package/site/blocks/classic.js +270 -0
- package/site/blocks/context.js +63 -0
- package/site/blocks/index.js +4 -0
- package/site/blocks/packages.js +242 -0
- package/site/blocks/unsupported-page.js +328 -0
- package/site/builder.js +475 -0
- package/site/detect.js +65 -0
- package/site/ignore-files.js +90 -0
- package/site/manifest.js +227 -0
- package/site/server.js +483 -0
- package/site/shell.js +363 -0
- package/sync/fs.js +19 -17
- package/sync/info.js +6 -81
- package/utils/browser.js +17 -10
- package/utils/cli-options.js +79 -0
- package/utils/codepen-url.js +183 -0
- package/utils/format.js +39 -30
- package/utils/fs-safe.js +95 -0
- package/utils/html.js +40 -1
- package/utils/json.js +4 -19
- package/utils/output.js +37 -0
- package/utils/package-paths.js +51 -0
- package/utils/prompts/index.js +5 -0
- package/utils/prompts/multi-select.js +185 -0
- package/utils/prompts/secret.js +65 -0
- package/utils/prompts/select.js +141 -0
- package/utils/prompts/text.js +99 -0
- package/utils/prompts/tty-list.js +165 -0
- package/utils/prompts/types.js +35 -0
- package/utils/strings.js +98 -0
- package/utils/watcher.js +82 -0
- package/{commands → workflows}/auth-context.js +13 -7
- package/workflows/batch-pens.js +1647 -0
- package/workflows/batch-target.js +184 -0
- package/workflows/classic-convert.js +241 -0
- package/workflows/clone-pen.js +381 -0
- package/workflows/create-pen.js +254 -0
- package/workflows/discover-pens.js +91 -0
- package/workflows/fork-pen.js +314 -0
- package/workflows/missing-pen.js +212 -0
- package/workflows/pull-pen.js +204 -0
- package/workflows/push-pen.js +318 -0
- package/{commands → workflows}/scaffold.js +4 -3
- package/workflows/sync-pen.js +227 -0
- package/{commands → workflows}/unowned-pen.js +16 -12
- package/commands/auth.js +0 -593
- package/commands/create-pen.js +0 -251
- package/commands/meta.js +0 -184
- package/utils/prompts.js +0 -316
- /package/{types.js → api/types.js} +0 -0
package/commands/privacy.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { CodePenClient } from '../api/client.js';
|
|
2
2
|
import { requireProjectInDir, writeProjectConfig } from '../config/project.js';
|
|
3
|
+
import { MIN_PROTECTED_PASSWORD_LENGTH, PEN_ACCESS_CHOICES } from '../constants.js';
|
|
4
|
+
import { CliError } from '../errors.js';
|
|
3
5
|
import { mergeUpdatedPenInfoIntoConfig } from '../sync/info.js';
|
|
6
|
+
import { normalizeAccess } from '../utils/cli-options.js';
|
|
4
7
|
import { fmt } from '../utils/format.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{ value: 'Private', label: 'Private', description: 'unlisted; anyone with the link can view it' },
|
|
12
|
-
{ value: 'Protected', label: 'Protected', description: 'private and password-protected (min 8 chars)' },
|
|
13
|
-
{ value: 'Collaborators', label: 'Collaborators', description: 'private; visible only to you and collaborators' },
|
|
14
|
-
];
|
|
15
|
-
async function promptForProtectedPassword(secretImpl, promptLabel) {
|
|
8
|
+
import { printJsonResponse } from '../utils/json.js';
|
|
9
|
+
import { defaultOutput } from '../utils/output.js';
|
|
10
|
+
import { isInteractive, promptConfirm, promptSecret, promptSelect, } from '../utils/prompts/index.js';
|
|
11
|
+
import { getGlobalProfileOption, resolveCommandAuth } from '../workflows/auth-context.js';
|
|
12
|
+
import { fetchLinkedPenOrHandleMissing } from '../workflows/missing-pen.js';
|
|
13
|
+
async function promptForProtectedPassword(secretImpl, promptLabel, output) {
|
|
16
14
|
for (;;) {
|
|
17
15
|
const pw = await secretImpl(promptLabel);
|
|
18
|
-
if (pw.length >=
|
|
16
|
+
if (pw.length >= MIN_PROTECTED_PASSWORD_LENGTH)
|
|
19
17
|
return pw;
|
|
20
|
-
|
|
18
|
+
output.log(fmt.yellow(`Password must be at least ${MIN_PROTECTED_PASSWORD_LENGTH} characters.`));
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
/**
|
|
24
22
|
* Inspects or updates the privacy/access permissions of the Pen linked by `.cdpn.json`
|
|
25
23
|
* directly inside `options.cwd` (does not walk up to parent folders).
|
|
26
24
|
*/
|
|
27
|
-
export async function
|
|
25
|
+
export async function runPrivacyCommand(options = {}) {
|
|
26
|
+
const output = options.output ?? defaultOutput;
|
|
28
27
|
const cwd = options.cwd ?? process.cwd();
|
|
29
28
|
const interactive = (options.interactive ?? isInteractive()) && !options.json;
|
|
30
29
|
const selectImpl = options.prompts?.select ?? promptSelect;
|
|
@@ -34,8 +33,8 @@ export async function managePenPrivacy(options = {}) {
|
|
|
34
33
|
const project = await requireProjectInDir(cwd);
|
|
35
34
|
const requestedAccess = normalizeAccess(options.levelArg);
|
|
36
35
|
if (options.password !== undefined) {
|
|
37
|
-
if (options.password.length <
|
|
38
|
-
throw new CliError(400,
|
|
36
|
+
if (options.password.length < MIN_PROTECTED_PASSWORD_LENGTH) {
|
|
37
|
+
throw new CliError(400, `Password must be at least ${MIN_PROTECTED_PASSWORD_LENGTH} characters.`);
|
|
39
38
|
}
|
|
40
39
|
if (requestedAccess && requestedAccess !== 'Protected') {
|
|
41
40
|
throw new CliError(400, '--password can only be used with Protected privacy.');
|
|
@@ -49,12 +48,29 @@ export async function managePenPrivacy(options = {}) {
|
|
|
49
48
|
project,
|
|
50
49
|
interactive,
|
|
51
50
|
persistProfileToProject: !options.json,
|
|
51
|
+
output,
|
|
52
52
|
env: options.env,
|
|
53
53
|
homeDir: options.homeDir,
|
|
54
54
|
selectProfile: selectImpl,
|
|
55
55
|
});
|
|
56
56
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
57
|
-
const
|
|
57
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
58
|
+
client,
|
|
59
|
+
project,
|
|
60
|
+
auth,
|
|
61
|
+
commandName: 'privacy',
|
|
62
|
+
interactive,
|
|
63
|
+
json: options.json,
|
|
64
|
+
output,
|
|
65
|
+
prompts: {
|
|
66
|
+
select: selectImpl,
|
|
67
|
+
confirm: confirmImpl,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
if (!penLookup.found) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const currentPen = penLookup.pen;
|
|
58
74
|
const previousAccess = currentPen.access;
|
|
59
75
|
// Read-only mode: `--show`, or no level/password in non-interactive / `--json` mode
|
|
60
76
|
if (options.show || (!requestedAccess && options.password === undefined && !interactive)) {
|
|
@@ -66,14 +82,14 @@ export async function managePenPrivacy(options = {}) {
|
|
|
66
82
|
editor: currentPen.editor,
|
|
67
83
|
profile: auth.profile ?? project.config.profile ?? null,
|
|
68
84
|
updated: false,
|
|
69
|
-
});
|
|
85
|
+
}, output);
|
|
70
86
|
}
|
|
71
87
|
else {
|
|
72
|
-
|
|
88
|
+
output.log(`${fmt.bold(currentPen.title || 'Untitled')} ${fmt.dim(`(${currentPen.id})`)}`);
|
|
73
89
|
if (auth.profile) {
|
|
74
|
-
|
|
90
|
+
output.log(` Profile: ${fmt.cyan(auth.profile)}`);
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
output.log(` Privacy: ${fmt.cyan(currentPen.access)}`);
|
|
77
93
|
}
|
|
78
94
|
return {
|
|
79
95
|
pen: currentPen,
|
|
@@ -98,9 +114,9 @@ export async function managePenPrivacy(options = {}) {
|
|
|
98
114
|
}
|
|
99
115
|
else {
|
|
100
116
|
// Interactive picker with current privacy pre-selected
|
|
101
|
-
|
|
102
|
-
const defaultIndex = Math.max(0,
|
|
103
|
-
const selectOptions =
|
|
117
|
+
output.log(`Current privacy for ${fmt.bold(currentPen.title || 'Untitled')} ${fmt.dim(`(${currentPen.id})`)}: ${fmt.cyan(previousAccess)}\n`);
|
|
118
|
+
const defaultIndex = Math.max(0, PEN_ACCESS_CHOICES.findIndex((c) => c.value === previousAccess));
|
|
119
|
+
const selectOptions = PEN_ACCESS_CHOICES.map((choice) => ({
|
|
104
120
|
value: choice.value,
|
|
105
121
|
label: choice.label,
|
|
106
122
|
description: choice.value === previousAccess ? `${choice.description} (current)` : choice.description,
|
|
@@ -119,7 +135,7 @@ export async function managePenPrivacy(options = {}) {
|
|
|
119
135
|
if (!requestedAccess) {
|
|
120
136
|
const rotate = await confirmImpl('Pen is already Protected. Replace its password?', false);
|
|
121
137
|
if (!rotate) {
|
|
122
|
-
|
|
138
|
+
output.log(`Privacy unchanged (${fmt.cyan('Protected')}).`);
|
|
123
139
|
return {
|
|
124
140
|
pen: currentPen,
|
|
125
141
|
previousAccess,
|
|
@@ -130,7 +146,7 @@ export async function managePenPrivacy(options = {}) {
|
|
|
130
146
|
};
|
|
131
147
|
}
|
|
132
148
|
}
|
|
133
|
-
password = await promptForProtectedPassword(secretImpl,
|
|
149
|
+
password = await promptForProtectedPassword(secretImpl, `New password for Protected Pen (min ${MIN_PROTECTED_PASSWORD_LENGTH} characters)`, output);
|
|
134
150
|
}
|
|
135
151
|
patch.password = password;
|
|
136
152
|
passwordUpdated = true;
|
|
@@ -139,9 +155,9 @@ export async function managePenPrivacy(options = {}) {
|
|
|
139
155
|
// Changing to Protected -> password is required by CodePen API
|
|
140
156
|
if (!password) {
|
|
141
157
|
if (!interactive) {
|
|
142
|
-
throw new CliError(400,
|
|
158
|
+
throw new CliError(400, `Changing privacy to Protected requires --password with at least ${MIN_PROTECTED_PASSWORD_LENGTH} characters.`);
|
|
143
159
|
}
|
|
144
|
-
password = await promptForProtectedPassword(secretImpl,
|
|
160
|
+
password = await promptForProtectedPassword(secretImpl, `Password for Protected Pen (min ${MIN_PROTECTED_PASSWORD_LENGTH} characters)`, output);
|
|
145
161
|
}
|
|
146
162
|
patch.access = 'Protected';
|
|
147
163
|
patch.password = password;
|
|
@@ -163,10 +179,10 @@ export async function managePenPrivacy(options = {}) {
|
|
|
163
179
|
profile: auth.profile ?? project.config.profile ?? null,
|
|
164
180
|
password_updated: false,
|
|
165
181
|
updated: false,
|
|
166
|
-
});
|
|
182
|
+
}, output);
|
|
167
183
|
}
|
|
168
184
|
else {
|
|
169
|
-
|
|
185
|
+
output.log(`Privacy is already ${fmt.cyan(currentPen.access)} — no changes made.`);
|
|
170
186
|
}
|
|
171
187
|
return {
|
|
172
188
|
pen: currentPen,
|
|
@@ -195,19 +211,19 @@ export async function managePenPrivacy(options = {}) {
|
|
|
195
211
|
password_updated: passwordUpdated,
|
|
196
212
|
updated: true,
|
|
197
213
|
url: updatedPen.urls.editor,
|
|
198
|
-
});
|
|
214
|
+
}, output);
|
|
199
215
|
}
|
|
200
216
|
else if (previousAccess === updatedPen.access && passwordUpdated) {
|
|
201
|
-
|
|
217
|
+
output.log(`\n${fmt.green('✓')} Updated password for Protected Pen ${fmt.bold(updatedPen.title || 'Untitled')} ${fmt.dim(`(${updatedPen.id})`)}`);
|
|
202
218
|
}
|
|
203
219
|
else {
|
|
204
|
-
|
|
220
|
+
output.log(`\n${fmt.green('✓')} Updated privacy for ${fmt.bold(updatedPen.title || 'Untitled')} ${fmt.dim(`(${updatedPen.id})`)}: ${fmt.dim(previousAccess)} → ${fmt.cyan(updatedPen.access)}`);
|
|
205
221
|
}
|
|
206
222
|
if (!options.json) {
|
|
207
223
|
if (auth.profile) {
|
|
208
|
-
|
|
224
|
+
output.log(` Profile: ${fmt.cyan(auth.profile)}`);
|
|
209
225
|
}
|
|
210
|
-
|
|
226
|
+
output.log(` Editor: ${fmt.cyan(updatedPen.urls.editor)}`);
|
|
211
227
|
}
|
|
212
228
|
return {
|
|
213
229
|
pen: updatedPen,
|
|
@@ -227,7 +243,7 @@ export function registerPrivacyCommand(program) {
|
|
|
227
243
|
.option('--show', 'Show the current privacy level without prompting')
|
|
228
244
|
.option('--json', 'Output privacy status/result as JSON')
|
|
229
245
|
.action(async (levelArg, options, command) => {
|
|
230
|
-
await
|
|
246
|
+
await runPrivacyCommand({
|
|
231
247
|
levelArg,
|
|
232
248
|
password: options.password,
|
|
233
249
|
show: options.show,
|
package/commands/pull.js
CHANGED
|
@@ -1,146 +1,159 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { CodePenClient } from '../api/client.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { createUnlinkedProjectError, findNearestConfig, } from '../config/project.js';
|
|
4
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
6
|
+
import { printJsonResponse } from '../utils/json.js';
|
|
7
|
+
import { defaultOutput } from '../utils/output.js';
|
|
8
|
+
import { isInteractive, promptSelect } from '../utils/prompts/index.js';
|
|
9
|
+
import { getGlobalProfileOption, resolveCommandAuth } from '../workflows/auth-context.js';
|
|
10
|
+
import { runBatchPull } from '../workflows/batch-pens.js';
|
|
11
|
+
import { offerBatchAllFallback, resolveBatchCommandTarget, } from '../workflows/batch-target.js';
|
|
12
|
+
import { executePull } from '../workflows/pull-pen.js';
|
|
11
13
|
/**
|
|
12
14
|
* Pulls the latest remote files and Pen metadata from CodePen into an existing cloned folder
|
|
13
|
-
* containing `.cdpn.json
|
|
14
|
-
*
|
|
15
|
+
* containing `.cdpn.json` (in `cwd` or an explicit directory `[target]`), or walks subdirectories
|
|
16
|
+
* in batch mode when `[target]` is `"all"`.
|
|
17
|
+
* Returns `null` if the user cancels interactively.
|
|
15
18
|
*/
|
|
16
|
-
export async function
|
|
17
|
-
const
|
|
19
|
+
export async function runPullCommand(options = {}) {
|
|
20
|
+
const output = options.output ?? defaultOutput;
|
|
21
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
18
22
|
const jsonMode = Boolean(options.json);
|
|
23
|
+
const dryRun = Boolean(options.dryRun);
|
|
19
24
|
const interactive = (options.interactive ?? isInteractive()) && !jsonMode;
|
|
20
25
|
const force = Boolean(options.force);
|
|
21
|
-
const confirmImpl = options.prompts?.confirm ?? promptConfirm;
|
|
22
26
|
const selectImpl = options.prompts?.select ?? promptSelect;
|
|
23
|
-
const
|
|
27
|
+
const executeBatch = async (rootDir, discovered) => {
|
|
28
|
+
const batch = await runBatchPull({
|
|
29
|
+
rootDir,
|
|
30
|
+
discovered,
|
|
31
|
+
force,
|
|
32
|
+
dryRun,
|
|
33
|
+
json: jsonMode,
|
|
34
|
+
interactive,
|
|
35
|
+
explicitProfile: options.explicitProfile,
|
|
36
|
+
baseUrl: options.baseUrl,
|
|
37
|
+
env: options.env,
|
|
38
|
+
homeDir: options.homeDir,
|
|
39
|
+
output,
|
|
40
|
+
prompts: options.prompts,
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
writtenPaths: [],
|
|
44
|
+
deletedPaths: [],
|
|
45
|
+
dryRun,
|
|
46
|
+
batch,
|
|
47
|
+
...(batch.exitCode !== undefined ? { exitCode: batch.exitCode } : {}),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const resolvedTarget = await resolveBatchCommandTarget({
|
|
51
|
+
commandName: 'pull',
|
|
52
|
+
cwd,
|
|
53
|
+
target: options.target,
|
|
54
|
+
interactive,
|
|
55
|
+
output,
|
|
56
|
+
prompts: options.prompts,
|
|
57
|
+
});
|
|
58
|
+
if (resolvedTarget.mode === 'batch') {
|
|
59
|
+
return executeBatch(resolvedTarget.rootDir, resolvedTarget.discovered);
|
|
60
|
+
}
|
|
61
|
+
const nearest = await findNearestConfig(resolvedTarget.targetDir);
|
|
62
|
+
if (!nearest) {
|
|
63
|
+
const fallback = await offerBatchAllFallback({
|
|
64
|
+
commandName: 'pull',
|
|
65
|
+
targetDir: resolvedTarget.targetDir,
|
|
66
|
+
fromExplicitDir: resolvedTarget.fromExplicitDir,
|
|
67
|
+
displayDir: resolvedTarget.displayDir,
|
|
68
|
+
dryRun,
|
|
69
|
+
interactive,
|
|
70
|
+
output,
|
|
71
|
+
prompts: options.prompts,
|
|
72
|
+
});
|
|
73
|
+
if (fallback.action === 'batch') {
|
|
74
|
+
return executeBatch(resolvedTarget.targetDir, fallback.discovered);
|
|
75
|
+
}
|
|
76
|
+
if (fallback.action === 'canceled') {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
throw new CliError(404, `No ${PROJECT_CONFIG_FILENAME} found in this directory or any parent directory.\nRun \`cdpn clone <url>\` to clone a Pen or \`cdpn new\` to create one.`);
|
|
80
|
+
}
|
|
81
|
+
if (!nearest.linked) {
|
|
82
|
+
throw createUnlinkedProjectError(nearest.rootDir);
|
|
83
|
+
}
|
|
84
|
+
const project = {
|
|
85
|
+
rootDir: nearest.rootDir,
|
|
86
|
+
configPath: nearest.configPath,
|
|
87
|
+
config: nearest.config,
|
|
88
|
+
};
|
|
24
89
|
const auth = await resolveCommandAuth({
|
|
25
90
|
explicitProfile: options.explicitProfile,
|
|
26
91
|
project,
|
|
27
92
|
interactive,
|
|
28
|
-
persistProfileToProject: !jsonMode,
|
|
93
|
+
persistProfileToProject: !jsonMode && !dryRun,
|
|
94
|
+
output,
|
|
29
95
|
env: options.env,
|
|
30
96
|
homeDir: options.homeDir,
|
|
31
97
|
selectProfile: selectImpl,
|
|
32
98
|
});
|
|
33
99
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if ((dirtyCount > 0 || localInfoDirty) && !force) {
|
|
43
|
-
if (!jsonMode) {
|
|
44
|
-
console.log(fmt.yellow('\nWarning: You have uncommitted local changes that will be overwritten:'));
|
|
45
|
-
for (const p of localDirty.added)
|
|
46
|
-
console.log(` ${fmt.green('+')} ${p} ${fmt.dim('(will be removed)')}`);
|
|
47
|
-
for (const p of localDirty.modified)
|
|
48
|
-
console.log(` ${fmt.yellow('~')} ${p} ${fmt.dim('(will be overwritten)')}`);
|
|
49
|
-
for (const p of localDirty.deleted)
|
|
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
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (!interactive) {
|
|
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
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const ok = await confirmImpl('\nOverwrite local changes with remote version?', false);
|
|
62
|
-
if (!ok) {
|
|
63
|
-
console.log('Aborted.');
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const [pen, remoteFiles] = await Promise.all([
|
|
68
|
-
client.getPen(config.pen_id),
|
|
69
|
-
client.getPenFiles(config.pen_id),
|
|
70
|
-
]);
|
|
71
|
-
const hadInfoBefore = hasAnyPenInfoFields(config.info);
|
|
72
|
-
const infoAnalysis = analyzeInfoSync(config.info, config.last_synced_info_hash, pen);
|
|
73
|
-
const result = await syncRemoteFilesToDisk({
|
|
74
|
-
client,
|
|
75
|
-
rootDir,
|
|
76
|
-
remoteFiles,
|
|
77
|
-
existingLocalPaths: localFiles.keys(),
|
|
78
|
-
pruneRemoved: true,
|
|
100
|
+
const pulled = await executePull(client, project, auth, {
|
|
101
|
+
force,
|
|
102
|
+
dryRun,
|
|
103
|
+
silent: jsonMode,
|
|
104
|
+
interactive,
|
|
105
|
+
json: jsonMode,
|
|
106
|
+
output,
|
|
107
|
+
prompts: options.prompts,
|
|
79
108
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const nextConfig = {
|
|
83
|
-
url: config.url || pen.urls.editor,
|
|
84
|
-
pen_id: pen.id,
|
|
85
|
-
...(profileToPersist ? { profile: profileToPersist } : {}),
|
|
86
|
-
last_synced_version_id: pen.saved_version?.id ?? null,
|
|
87
|
-
editor: pen.editor,
|
|
88
|
-
...buildPenInfoConfigFields(pen),
|
|
89
|
-
files: syncedFiles,
|
|
90
|
-
};
|
|
91
|
-
const configPath = await writeProjectConfig(rootDir, nextConfig);
|
|
92
|
-
if (jsonMode) {
|
|
93
|
-
printJsonResponse(200, `Synced ${pen.title || 'Untitled'}.`, {
|
|
94
|
-
pen,
|
|
95
|
-
profile: profileToPersist ?? null,
|
|
96
|
-
root_dir: rootDir,
|
|
97
|
-
config_path: configPath,
|
|
98
|
-
version_id: pen.saved_version?.id ?? null,
|
|
99
|
-
written_paths: result.writtenPaths,
|
|
100
|
-
deleted_paths: result.deletedPaths,
|
|
101
|
-
});
|
|
109
|
+
if (!pulled) {
|
|
110
|
+
return null;
|
|
102
111
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
112
|
+
if (jsonMode) {
|
|
113
|
+
const profileToReport = pulled.project.config.profile ?? auth.profile ?? null;
|
|
114
|
+
printJsonResponse(200, dryRun
|
|
115
|
+
? `Dry run complete — previewed remote changes for ${pulled.pen.title || 'Untitled'}.`
|
|
116
|
+
: `Synced ${pulled.pen.title || 'Untitled'}.`, {
|
|
117
|
+
pen: pulled.pen,
|
|
118
|
+
profile: profileToReport,
|
|
119
|
+
root_dir: pulled.project.rootDir,
|
|
120
|
+
config_path: pulled.project.configPath,
|
|
121
|
+
version_id: pulled.pen.saved_version?.id ?? null,
|
|
122
|
+
dry_run: dryRun,
|
|
123
|
+
...(dryRun ? { has_local_changes: pulled.hasLocalChanges } : {}),
|
|
124
|
+
written_paths: pulled.writtenPaths,
|
|
125
|
+
deleted_paths: pulled.deletedPaths,
|
|
126
|
+
...(dryRun ? { info_changes: pulled.infoChanges } : {}),
|
|
127
|
+
}, output);
|
|
119
128
|
}
|
|
120
129
|
return {
|
|
121
|
-
pen,
|
|
122
|
-
writtenPaths:
|
|
123
|
-
deletedPaths:
|
|
130
|
+
pen: pulled.pen,
|
|
131
|
+
writtenPaths: pulled.writtenPaths,
|
|
132
|
+
deletedPaths: pulled.deletedPaths,
|
|
124
133
|
auth,
|
|
125
|
-
project:
|
|
126
|
-
|
|
127
|
-
configPath,
|
|
128
|
-
config: nextConfig,
|
|
129
|
-
},
|
|
134
|
+
project: pulled.project,
|
|
135
|
+
dryRun,
|
|
130
136
|
};
|
|
131
137
|
}
|
|
132
138
|
export function registerPullCommand(program) {
|
|
133
139
|
program
|
|
134
140
|
.command('pull')
|
|
141
|
+
.argument('[target]', 'Directory path to pull, or "all" to pull all Pens in subdirectories')
|
|
135
142
|
.allowExcessArguments(false)
|
|
136
|
-
.description('Pull latest changes from CodePen into
|
|
143
|
+
.description('Pull latest changes from CodePen into a cloned folder (or pass "all" to walk subdirectories)')
|
|
137
144
|
.option('-f, --force', 'Overwrite local changes without prompting')
|
|
145
|
+
.option('--dry-run', 'Preview remote changes without modifying local files')
|
|
138
146
|
.option('--json', 'Output pull result as JSON')
|
|
139
|
-
.action(async (options, command) => {
|
|
140
|
-
await
|
|
147
|
+
.action(async (target, options, command) => {
|
|
148
|
+
const result = await runPullCommand({
|
|
149
|
+
target,
|
|
141
150
|
force: options.force,
|
|
151
|
+
dryRun: options.dryRun,
|
|
142
152
|
json: options.json,
|
|
143
153
|
explicitProfile: getGlobalProfileOption(command),
|
|
144
154
|
});
|
|
155
|
+
if (result?.exitCode !== undefined) {
|
|
156
|
+
process.exitCode = result.exitCode;
|
|
157
|
+
}
|
|
145
158
|
});
|
|
146
159
|
}
|