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
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { API_KEY_FILENAME } from '../config/auth.js';
|
|
4
|
+
import { clearConfiguredShellDir, getConfiguredShellDir, setConfiguredShellDir, } from '../config/user-store.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
6
|
+
import { expandHomePath, exportBuiltinShell, listShellAssetFiles, resolveBuiltinShellDir, validateShellDir, } from '../site/shell.js';
|
|
7
|
+
import { isDirectoryNonEmpty } from '../sync/fs.js';
|
|
8
|
+
import { resolveInheritedJsonOption } from '../utils/cli-options.js';
|
|
9
|
+
import { fmt } from '../utils/format.js';
|
|
10
|
+
import { printJsonResponse } from '../utils/json.js';
|
|
11
|
+
import { defaultOutput } from '../utils/output.js';
|
|
12
|
+
import { isInteractive, promptConfirm, promptValidatedTextWithIO, } from '../utils/prompts/index.js';
|
|
13
|
+
import { hasControlChars } from '../utils/strings.js';
|
|
14
|
+
export const DEFAULT_SHELL_EXPORT_DIR = 'cdpn-shell';
|
|
15
|
+
export async function runShellShowCommand(options = {}) {
|
|
16
|
+
const output = options.output ?? defaultOutput;
|
|
17
|
+
const jsonMode = Boolean(options.json);
|
|
18
|
+
const builtin = await resolveBuiltinShellDir();
|
|
19
|
+
const configuredDir = await getConfiguredShellDir({ homeDir: options.homeDir });
|
|
20
|
+
let source = 'builtin';
|
|
21
|
+
let activeDir = builtin.dir;
|
|
22
|
+
let exists = true;
|
|
23
|
+
let files = [];
|
|
24
|
+
let warning = null;
|
|
25
|
+
if (configuredDir) {
|
|
26
|
+
source = 'config';
|
|
27
|
+
activeDir = configuredDir;
|
|
28
|
+
try {
|
|
29
|
+
const validated = await validateShellDir(configuredDir, {
|
|
30
|
+
cwd: options.homeDir,
|
|
31
|
+
homeDir: options.homeDir,
|
|
32
|
+
sourceLabel: 'config',
|
|
33
|
+
});
|
|
34
|
+
activeDir = validated.dir;
|
|
35
|
+
files = validated.files;
|
|
36
|
+
exists = true;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
exists = false;
|
|
40
|
+
warning = error instanceof Error ? error.message : String(error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
files = await listShellAssetFiles(builtin.realpath);
|
|
45
|
+
}
|
|
46
|
+
const result = {
|
|
47
|
+
source,
|
|
48
|
+
configuredDir,
|
|
49
|
+
activeDir,
|
|
50
|
+
exists,
|
|
51
|
+
files,
|
|
52
|
+
warning,
|
|
53
|
+
...(!exists ? { exitCode: 1 } : {}),
|
|
54
|
+
};
|
|
55
|
+
if (jsonMode) {
|
|
56
|
+
const code = exists ? 200 : 404;
|
|
57
|
+
const message = source === 'builtin'
|
|
58
|
+
? 'Using built-in demo index shell.'
|
|
59
|
+
: exists
|
|
60
|
+
? `Using custom shell from ~/${API_KEY_FILENAME}: ${activeDir}`
|
|
61
|
+
: warning ?? `Configured shell directory not found: ${activeDir}`;
|
|
62
|
+
printJsonResponse(code, message, {
|
|
63
|
+
source: result.source,
|
|
64
|
+
configured_dir: result.configuredDir,
|
|
65
|
+
active_dir: result.activeDir,
|
|
66
|
+
exists: result.exists,
|
|
67
|
+
files: result.files,
|
|
68
|
+
warning: result.warning,
|
|
69
|
+
}, output);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
if (source === 'builtin') {
|
|
73
|
+
output.log(`${fmt.boldGreen('✓')} Active shell: ${fmt.boldCyan('built-in')} ${fmt.dim(`(${builtin.dir})`)}`);
|
|
74
|
+
output.log(` ${fmt.dim('Files:')} ${files.join(', ')}`);
|
|
75
|
+
output.log(fmt.dim('\n Tip: Run `cdpn shell export <dir>` to copy and customize the built-in shell.'));
|
|
76
|
+
}
|
|
77
|
+
else if (exists) {
|
|
78
|
+
output.log(`${fmt.boldGreen('✓')} Active shell: ${fmt.magenta(activeDir)} ${fmt.dim(`(configured in ~/${API_KEY_FILENAME})`)}`);
|
|
79
|
+
output.log(` ${fmt.dim('Files:')} ${files.join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
output.log(`${fmt.boldRed('✗')} Configured shell in ~/${API_KEY_FILENAME} is invalid or missing: ${fmt.magenta(activeDir)}`);
|
|
83
|
+
if (warning) {
|
|
84
|
+
output.log(` ${fmt.yellow(warning)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export async function runShellExportCommand(options = {}) {
|
|
90
|
+
const output = options.output ?? defaultOutput;
|
|
91
|
+
const jsonMode = Boolean(options.json);
|
|
92
|
+
const interactive = !jsonMode && (options.interactive ?? isInteractive());
|
|
93
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
94
|
+
const confirmImpl = options.prompts?.confirm ?? promptConfirm;
|
|
95
|
+
const askDirImpl = options.prompts?.askDir ??
|
|
96
|
+
((question, defaultValue, validate) => promptValidatedTextWithIO(question, {
|
|
97
|
+
defaultValue,
|
|
98
|
+
validate,
|
|
99
|
+
}));
|
|
100
|
+
let rawDir = options.dirArg?.trim();
|
|
101
|
+
if (!rawDir) {
|
|
102
|
+
if (interactive) {
|
|
103
|
+
output.log('');
|
|
104
|
+
rawDir = await askDirImpl('Where would you like to export the built-in shell?', DEFAULT_SHELL_EXPORT_DIR, (raw) => {
|
|
105
|
+
const candidate = raw.trim() || DEFAULT_SHELL_EXPORT_DIR;
|
|
106
|
+
if (hasControlChars(candidate)) {
|
|
107
|
+
return { ok: false, error: 'Directory cannot contain control characters.' };
|
|
108
|
+
}
|
|
109
|
+
return { ok: true, value: candidate, displayValue: candidate };
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
rawDir = DEFAULT_SHELL_EXPORT_DIR;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!rawDir || hasControlChars(rawDir)) {
|
|
117
|
+
throw new CliError(400, 'Export directory path cannot be empty or contain control characters.');
|
|
118
|
+
}
|
|
119
|
+
const expanded = expandHomePath(rawDir, options.homeDir);
|
|
120
|
+
const resolvedTarget = path.resolve(cwd, expanded);
|
|
121
|
+
// Check if path exists as a non-directory or symlink, or non-empty directory
|
|
122
|
+
let nonEmpty = false;
|
|
123
|
+
try {
|
|
124
|
+
const lstat = await fs.lstat(resolvedTarget);
|
|
125
|
+
if (lstat.isSymbolicLink()) {
|
|
126
|
+
throw new CliError(400, `"${rawDir}" is a symbolic link. Please choose a regular directory.`);
|
|
127
|
+
}
|
|
128
|
+
if (!lstat.isDirectory()) {
|
|
129
|
+
throw new CliError(400, `"${rawDir}" already exists and is not a directory.`);
|
|
130
|
+
}
|
|
131
|
+
nonEmpty = await isDirectoryNonEmpty(resolvedTarget);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error.code !== 'ENOENT') {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const autoConfirm = Boolean(options.yes || options.force);
|
|
139
|
+
if (nonEmpty && !autoConfirm) {
|
|
140
|
+
if (!interactive) {
|
|
141
|
+
throw new CliError(409, `Directory "${rawDir}" already exists and is not empty. Pass --yes (or --force) to overwrite shell files.`, { target_dir: resolvedTarget });
|
|
142
|
+
}
|
|
143
|
+
output.log('');
|
|
144
|
+
const overwrite = await confirmImpl(`Directory "${rawDir}" is not empty. Overwrite existing shell files?`, false);
|
|
145
|
+
if (!overwrite) {
|
|
146
|
+
output.log(fmt.dim('Export aborted.'));
|
|
147
|
+
return {
|
|
148
|
+
exported: false,
|
|
149
|
+
aborted: true,
|
|
150
|
+
targetDir: resolvedTarget,
|
|
151
|
+
copiedFiles: [],
|
|
152
|
+
configuredGlobally: false,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const exported = await exportBuiltinShell(resolvedTarget);
|
|
157
|
+
let configuredGlobally = false;
|
|
158
|
+
if (options.set) {
|
|
159
|
+
await setConfiguredShellDir(exported.targetDir, { homeDir: options.homeDir });
|
|
160
|
+
configuredGlobally = true;
|
|
161
|
+
}
|
|
162
|
+
else if (interactive) {
|
|
163
|
+
output.log('');
|
|
164
|
+
const shouldSet = await confirmImpl(`Set "${rawDir}" as your default global shell in ~/${API_KEY_FILENAME}?`, true);
|
|
165
|
+
if (shouldSet) {
|
|
166
|
+
await setConfiguredShellDir(exported.targetDir, { homeDir: options.homeDir });
|
|
167
|
+
configuredGlobally = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (jsonMode) {
|
|
171
|
+
printJsonResponse(201, `Exported built-in shell to ${exported.targetDir}.`, {
|
|
172
|
+
target_dir: exported.targetDir,
|
|
173
|
+
copied_files: exported.copiedFiles,
|
|
174
|
+
configured_globally: configuredGlobally,
|
|
175
|
+
}, output);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
output.log('');
|
|
179
|
+
output.log(`${fmt.boldGreen('✓')} ${fmt.bold('Exported built-in shell to')} ${fmt.magenta(exported.targetDir)}`);
|
|
180
|
+
for (const file of exported.copiedFiles) {
|
|
181
|
+
output.log(` ${fmt.boldGreen('+')} ${file}`);
|
|
182
|
+
}
|
|
183
|
+
if (configuredGlobally) {
|
|
184
|
+
output.log(`\n${fmt.boldGreen('✓')} Saved as default global shell in ${fmt.bold(`~/${API_KEY_FILENAME}`)}.`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
output.log(fmt.dim(`\nUse it with \`cdpn serve --shell ${rawDir}\` or set it globally with \`cdpn shell set ${rawDir}\`.`));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
exported: true,
|
|
192
|
+
aborted: false,
|
|
193
|
+
targetDir: exported.targetDir,
|
|
194
|
+
copiedFiles: exported.copiedFiles,
|
|
195
|
+
configuredGlobally,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
export async function runShellSetCommand(options) {
|
|
199
|
+
const output = options.output ?? defaultOutput;
|
|
200
|
+
const jsonMode = Boolean(options.json);
|
|
201
|
+
const validated = await validateShellDir(options.dirArg, {
|
|
202
|
+
cwd: options.cwd,
|
|
203
|
+
homeDir: options.homeDir,
|
|
204
|
+
sourceLabel: 'flag',
|
|
205
|
+
});
|
|
206
|
+
const saved = await setConfiguredShellDir(validated.dir, { homeDir: options.homeDir });
|
|
207
|
+
if (jsonMode) {
|
|
208
|
+
printJsonResponse(200, `Default global shell set to ${saved.shellDir}.`, {
|
|
209
|
+
file_path: saved.filePath,
|
|
210
|
+
shell_dir: saved.shellDir,
|
|
211
|
+
files: validated.files,
|
|
212
|
+
}, output);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
output.log(`${fmt.boldGreen('✓')} Default global shell set to ${fmt.magenta(saved.shellDir)} ${fmt.dim(`(in ~/${API_KEY_FILENAME})`)}`);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
filePath: saved.filePath,
|
|
219
|
+
shellDir: saved.shellDir,
|
|
220
|
+
files: validated.files,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export async function runShellResetCommand(options = {}) {
|
|
224
|
+
const output = options.output ?? defaultOutput;
|
|
225
|
+
const jsonMode = Boolean(options.json);
|
|
226
|
+
const result = await clearConfiguredShellDir({ homeDir: options.homeDir });
|
|
227
|
+
if (jsonMode) {
|
|
228
|
+
const message = result.cleared
|
|
229
|
+
? `Reset default shell to built-in (updated ~/${API_KEY_FILENAME}).`
|
|
230
|
+
: 'Already using the built-in shell.';
|
|
231
|
+
printJsonResponse(200, message, {
|
|
232
|
+
file_path: result.filePath,
|
|
233
|
+
cleared: result.cleared,
|
|
234
|
+
file_deleted: result.fileDeleted,
|
|
235
|
+
}, output);
|
|
236
|
+
}
|
|
237
|
+
else if (result.cleared) {
|
|
238
|
+
output.log(`${fmt.boldGreen('✓')} Reset default shell to ${fmt.boldCyan('built-in')} ${fmt.dim(`(updated ~/${API_KEY_FILENAME})`)}.`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
output.log(fmt.dim('Already using the built-in shell.'));
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
export function registerShellCommand(program) {
|
|
246
|
+
const shellCmd = program
|
|
247
|
+
.command('shell')
|
|
248
|
+
.description('Manage the demo index shell used by `cdpn serve` and `cdpn build`')
|
|
249
|
+
.option('--json', 'Output shell configuration as JSON')
|
|
250
|
+
.action(async (options) => {
|
|
251
|
+
const result = await runShellShowCommand({ json: options.json });
|
|
252
|
+
if (result.exitCode !== undefined) {
|
|
253
|
+
process.exitCode = result.exitCode;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
shellCmd
|
|
257
|
+
.command('show')
|
|
258
|
+
.description('Show the active demo index shell (custom ~/.cdpn path or built-in)')
|
|
259
|
+
.option('--json', 'Output shell configuration as JSON')
|
|
260
|
+
.action(async (options, command) => {
|
|
261
|
+
const result = await runShellShowCommand({
|
|
262
|
+
json: resolveInheritedJsonOption(options, command),
|
|
263
|
+
});
|
|
264
|
+
if (result.exitCode !== undefined) {
|
|
265
|
+
process.exitCode = result.exitCode;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
shellCmd
|
|
269
|
+
.command('export [dir]')
|
|
270
|
+
.aliases(['eject', 'init'])
|
|
271
|
+
.description('Copy the built-in shell files into a local directory so you can customize them')
|
|
272
|
+
.option('-y, --yes', 'Overwrite existing files in a non-empty directory without confirmation')
|
|
273
|
+
.option('-f, --force', 'Alias for --yes')
|
|
274
|
+
.option('--set', `Also set the exported directory as the default global shell in ~/${API_KEY_FILENAME}`)
|
|
275
|
+
.option('--json', 'Output export result as JSON')
|
|
276
|
+
.action(async (dirArg, options, command) => {
|
|
277
|
+
await runShellExportCommand({
|
|
278
|
+
dirArg,
|
|
279
|
+
yes: options.yes,
|
|
280
|
+
force: options.force,
|
|
281
|
+
set: options.set,
|
|
282
|
+
json: resolveInheritedJsonOption(options, command),
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
shellCmd
|
|
286
|
+
.command('set <dir>')
|
|
287
|
+
.description(`Set a custom default shell directory in ~/${API_KEY_FILENAME}`)
|
|
288
|
+
.option('--json', 'Output result as JSON')
|
|
289
|
+
.action(async (dirArg, options, command) => {
|
|
290
|
+
await runShellSetCommand({
|
|
291
|
+
dirArg,
|
|
292
|
+
json: resolveInheritedJsonOption(options, command),
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
shellCmd
|
|
296
|
+
.command('reset')
|
|
297
|
+
.aliases(['unset', 'clear'])
|
|
298
|
+
.description(`Reset the global shell in ~/${API_KEY_FILENAME} back to the built-in shell`)
|
|
299
|
+
.option('--json', 'Output result as JSON')
|
|
300
|
+
.action(async (options, command) => {
|
|
301
|
+
await runShellResetCommand({
|
|
302
|
+
json: resolveInheritedJsonOption(options, command),
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
package/commands/status.js
CHANGED
|
@@ -1,27 +1,115 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { CodePenClient } from '../api/client.js';
|
|
2
3
|
import { API_KEY_ENV_VAR } from '../config/auth.js';
|
|
3
|
-
import {
|
|
4
|
+
import { createUnlinkedProjectError, findNearestConfig, } from '../config/project.js';
|
|
5
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
6
|
+
import { CliError } from '../errors.js';
|
|
4
7
|
import { computeSyncDiff, detectLocalChangesFromBaseline, hasDiffChanges, } from '../sync/diff.js';
|
|
5
|
-
import { scanLocalFiles } from '../sync/fs.js';
|
|
8
|
+
import { isDirectoryNonEmpty, scanLocalFiles } from '../sync/fs.js';
|
|
6
9
|
import { analyzeInfoSync, formatInfoValue } from '../sync/info.js';
|
|
7
10
|
import { fmt, shortId } from '../utils/format.js';
|
|
8
11
|
import { printJsonResponse } from '../utils/json.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
import { defaultOutput } from '../utils/output.js';
|
|
13
|
+
import { isInteractive } from '../utils/prompts/index.js';
|
|
14
|
+
import { getGlobalProfileOption, resolveCommandAuth } from '../workflows/auth-context.js';
|
|
15
|
+
import { runBatchStatus } from '../workflows/batch-pens.js';
|
|
16
|
+
import { offerBatchAllFallback, resolveBatchCommandTarget, } from '../workflows/batch-target.js';
|
|
17
|
+
import { fetchLinkedPenOrHandleMissing, } from '../workflows/missing-pen.js';
|
|
18
|
+
export async function runStatusCommand(options = {}) {
|
|
19
|
+
const output = options.output ?? defaultOutput;
|
|
20
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
21
|
+
const interactive = (options.interactive ?? isInteractive()) && !options.json;
|
|
22
|
+
const combinedPrompts = {
|
|
23
|
+
confirm: options.prompts?.confirm,
|
|
24
|
+
select: options.prompts?.select ?? options.selectProfile,
|
|
25
|
+
};
|
|
26
|
+
const executeBatch = async (rootDir, discovered) => {
|
|
27
|
+
const batch = await runBatchStatus({
|
|
28
|
+
rootDir,
|
|
29
|
+
discovered,
|
|
30
|
+
json: options.json,
|
|
31
|
+
interactive,
|
|
32
|
+
explicitProfile: options.explicitProfile,
|
|
33
|
+
baseUrl: options.baseUrl,
|
|
34
|
+
env: options.env,
|
|
35
|
+
homeDir: options.homeDir,
|
|
36
|
+
output,
|
|
37
|
+
prompts: combinedPrompts,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
remoteMoved: batch.remoteMoved,
|
|
41
|
+
upToDate: batch.upToDate,
|
|
42
|
+
batch,
|
|
43
|
+
...(batch.exitCode !== undefined ? { exitCode: batch.exitCode } : {}),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const resolvedTarget = await resolveBatchCommandTarget({
|
|
47
|
+
commandName: 'status',
|
|
48
|
+
cwd,
|
|
49
|
+
target: options.target,
|
|
50
|
+
interactive,
|
|
51
|
+
output,
|
|
52
|
+
prompts: combinedPrompts,
|
|
53
|
+
});
|
|
54
|
+
if (resolvedTarget.mode === 'batch') {
|
|
55
|
+
return executeBatch(resolvedTarget.rootDir, resolvedTarget.discovered);
|
|
56
|
+
}
|
|
57
|
+
const nearest = await findNearestConfig(resolvedTarget.targetDir);
|
|
58
|
+
if (!nearest) {
|
|
59
|
+
const fallback = await offerBatchAllFallback({
|
|
60
|
+
commandName: 'status',
|
|
61
|
+
targetDir: resolvedTarget.targetDir,
|
|
62
|
+
fromExplicitDir: resolvedTarget.fromExplicitDir,
|
|
63
|
+
displayDir: resolvedTarget.displayDir,
|
|
64
|
+
interactive,
|
|
65
|
+
output,
|
|
66
|
+
prompts: combinedPrompts,
|
|
67
|
+
});
|
|
68
|
+
if (fallback.action === 'batch') {
|
|
69
|
+
return executeBatch(resolvedTarget.targetDir, fallback.discovered);
|
|
70
|
+
}
|
|
71
|
+
if (fallback.action === 'canceled') {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const hint = (await isDirectoryNonEmpty(resolvedTarget.targetDir))
|
|
75
|
+
? 'Run `cdpn init` to initialize this folder as a CodePen demo.'
|
|
76
|
+
: 'Run `cdpn clone <url>` to clone a Pen or `cdpn new` to create one.';
|
|
77
|
+
throw new CliError(404, `No ${PROJECT_CONFIG_FILENAME} found in this directory or any parent directory.\n${hint}`);
|
|
78
|
+
}
|
|
79
|
+
if (!nearest.linked) {
|
|
80
|
+
throw createUnlinkedProjectError(nearest.rootDir);
|
|
81
|
+
}
|
|
82
|
+
const project = {
|
|
83
|
+
rootDir: nearest.rootDir,
|
|
84
|
+
configPath: nearest.configPath,
|
|
85
|
+
config: nearest.config,
|
|
86
|
+
};
|
|
13
87
|
const auth = await resolveCommandAuth({
|
|
14
88
|
explicitProfile: options.explicitProfile,
|
|
15
89
|
project,
|
|
16
|
-
interactive
|
|
90
|
+
interactive,
|
|
17
91
|
persistProfileToProject: !options.json,
|
|
92
|
+
output,
|
|
18
93
|
env: options.env,
|
|
19
94
|
homeDir: options.homeDir,
|
|
20
95
|
selectProfile: options.selectProfile,
|
|
21
96
|
});
|
|
22
97
|
const client = new CodePenClient({ apiKey: auth.apiKey, baseUrl: options.baseUrl });
|
|
23
|
-
const
|
|
24
|
-
client
|
|
98
|
+
const penLookup = await fetchLinkedPenOrHandleMissing({
|
|
99
|
+
client,
|
|
100
|
+
project,
|
|
101
|
+
auth,
|
|
102
|
+
commandName: 'status',
|
|
103
|
+
interactive,
|
|
104
|
+
json: options.json,
|
|
105
|
+
output,
|
|
106
|
+
prompts: options.prompts,
|
|
107
|
+
});
|
|
108
|
+
if (!penLookup.found) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const pen = penLookup.pen;
|
|
112
|
+
const [remoteFiles, localFiles] = await Promise.all([
|
|
25
113
|
client.getPenFiles(project.config.pen_id),
|
|
26
114
|
scanLocalFiles(project.rootDir),
|
|
27
115
|
]);
|
|
@@ -79,14 +167,14 @@ export async function statusPenCommand(options = {}) {
|
|
|
79
167
|
info_local_changed: infoAnalysis.localChanged,
|
|
80
168
|
info_remote_changed: infoAnalysis.remoteChanged,
|
|
81
169
|
info_changes: infoAnalysis.changes,
|
|
82
|
-
});
|
|
170
|
+
}, output);
|
|
83
171
|
return { pen, auth, project, diff, infoAnalysis, remoteMoved, upToDate };
|
|
84
172
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
173
|
+
output.log(`${fmt.bold(pen.title || 'Untitled')} ${fmt.dim(`(${pen.id}, ${pen.editor})`)}`);
|
|
174
|
+
output.log(`Profile: ${auth.profile ? fmt.cyan(auth.profile) : fmt.dim(`env (${API_KEY_ENV_VAR})`)}`);
|
|
175
|
+
output.log(`URL: ${fmt.cyan(project.config.url)}`);
|
|
176
|
+
output.log(`Synced: ${fmt.dim(shortId(localHead))}`);
|
|
177
|
+
output.log(`Remote: ${fmt.dim(shortId(remoteHead))}` +
|
|
90
178
|
(remoteMoved ? ` ${fmt.yellow('(remote head has moved since last sync!)')}` : ''));
|
|
91
179
|
const buildStatus = pen.saved_version?.build?.status;
|
|
92
180
|
if (buildStatus) {
|
|
@@ -95,33 +183,33 @@ export async function statusPenCommand(options = {}) {
|
|
|
95
183
|
: buildStatus === 'Failed'
|
|
96
184
|
? fmt.red(buildStatus)
|
|
97
185
|
: fmt.yellow(buildStatus);
|
|
98
|
-
|
|
186
|
+
output.log(`Build: ${colored}`);
|
|
99
187
|
}
|
|
100
188
|
if (pen.deployment) {
|
|
101
189
|
const deployedIsHead = pen.deployment.version_id === remoteHead;
|
|
102
190
|
const deployNote = deployedIsHead
|
|
103
191
|
? fmt.green('up to date')
|
|
104
192
|
: fmt.yellow(`older version ${shortId(pen.deployment.version_id)}`);
|
|
105
|
-
|
|
193
|
+
output.log(`Deployed: ${fmt.cyan(pen.deployment.url)} ${fmt.dim(`(${deployNote})`)}`);
|
|
106
194
|
if (pen.deployment.custom_domains.length > 0) {
|
|
107
|
-
|
|
195
|
+
output.log(`Domains: ${pen.deployment.custom_domains.join(', ')}`);
|
|
108
196
|
}
|
|
109
197
|
}
|
|
110
198
|
else {
|
|
111
|
-
|
|
199
|
+
output.log(`Deployed: ${fmt.dim('not deployed')}`);
|
|
112
200
|
}
|
|
113
|
-
|
|
201
|
+
output.log('');
|
|
114
202
|
const hasFileChanges = hasDiffChanges(diff);
|
|
115
203
|
const hasInfoChanges = infoAnalysis.changes.length > 0;
|
|
116
204
|
if (!hasFileChanges && !hasInfoChanges) {
|
|
117
205
|
if (remoteMoved) {
|
|
118
|
-
|
|
206
|
+
output.log(`${fmt.yellow('!')} Local files match remote content, but version metadata is behind. Run \`cdpn pull\` to update ${fmt.dim(PROJECT_CONFIG_FILENAME)}.`);
|
|
119
207
|
}
|
|
120
208
|
else {
|
|
121
|
-
|
|
209
|
+
output.log(`${fmt.green('✓')} Up to date with CodePen (${diff.unchanged.length} file(s)).`);
|
|
122
210
|
}
|
|
123
211
|
if (!infoAnalysis.tracked) {
|
|
124
|
-
|
|
212
|
+
output.log(fmt.dim(`Note: ${PROJECT_CONFIG_FILENAME} does not include Pen info yet. Run \`cdpn pull\` or \`cdpn push\` to add it.`));
|
|
125
213
|
}
|
|
126
214
|
return { pen, auth, project, diff, infoAnalysis, remoteMoved, upToDate };
|
|
127
215
|
}
|
|
@@ -131,60 +219,66 @@ export async function statusPenCommand(options = {}) {
|
|
|
131
219
|
...localBaselineChanges.modified,
|
|
132
220
|
...localBaselineChanges.deleted,
|
|
133
221
|
]);
|
|
134
|
-
|
|
222
|
+
output.log('Differences between local folder and remote head:');
|
|
135
223
|
for (const item of diff.added) {
|
|
136
224
|
const hint = remoteMoved && !localModifiedSet.has(item.path) ? fmt.dim(' (deleted remotely)') : '';
|
|
137
|
-
|
|
225
|
+
output.log(` ${fmt.green('+')} ${item.path}${hint}`);
|
|
138
226
|
}
|
|
139
227
|
for (const item of diff.modified) {
|
|
140
228
|
const hint = remoteMoved && !localModifiedSet.has(item.path) ? fmt.dim(' (changed remotely)') : '';
|
|
141
|
-
|
|
229
|
+
output.log(` ${fmt.yellow('~')} ${item.path}${hint}`);
|
|
142
230
|
}
|
|
143
231
|
for (const item of diff.deleted) {
|
|
144
232
|
const hint = remoteMoved && !localModifiedSet.has(item.path) ? fmt.dim(' (added remotely)') : '';
|
|
145
|
-
|
|
233
|
+
output.log(` ${fmt.red('-')} ${item.path}${hint}`);
|
|
146
234
|
}
|
|
147
235
|
}
|
|
148
236
|
if (hasInfoChanges) {
|
|
149
237
|
if (hasFileChanges) {
|
|
150
|
-
|
|
238
|
+
output.log('');
|
|
151
239
|
}
|
|
152
|
-
|
|
240
|
+
output.log(`Differences in Pen info (${PROJECT_CONFIG_FILENAME}):`);
|
|
153
241
|
for (const change of infoAnalysis.changes) {
|
|
154
242
|
const localVal = formatInfoValue(change.field, change.local);
|
|
155
243
|
const remoteVal = formatInfoValue(change.field, change.remote);
|
|
156
244
|
if (infoAnalysis.localChanged && infoAnalysis.remoteChanged) {
|
|
157
|
-
|
|
245
|
+
output.log(` ${fmt.yellow('~')} info.${change.field}: local ${localVal} vs remote ${remoteVal}${fmt.yellow(' (conflict)')}`);
|
|
158
246
|
}
|
|
159
247
|
else if (!infoAnalysis.localChanged && infoAnalysis.remoteChanged) {
|
|
160
|
-
|
|
248
|
+
output.log(` ${fmt.yellow('~')} info.${change.field}: ${localVal} → ${remoteVal}${fmt.dim(' (changed remotely)')}`);
|
|
161
249
|
}
|
|
162
250
|
else {
|
|
163
|
-
|
|
251
|
+
output.log(` ${fmt.yellow('~')} info.${change.field}: ${remoteVal} → ${localVal}`);
|
|
164
252
|
}
|
|
165
253
|
}
|
|
166
254
|
}
|
|
167
|
-
|
|
255
|
+
output.log('');
|
|
168
256
|
if (remoteMoved || (infoAnalysis.localChanged && infoAnalysis.remoteChanged)) {
|
|
169
|
-
|
|
257
|
+
output.log(fmt.yellow('Remote has newer changes. Run `cdpn pull` to sync remote changes, or `cdpn push --force` to overwrite remote with local.'));
|
|
170
258
|
}
|
|
171
259
|
else if (!hasFileChanges && !infoAnalysis.localChanged && infoAnalysis.remoteChanged) {
|
|
172
|
-
|
|
260
|
+
output.log(fmt.yellow(`Remote Pen info has changed. Run \`cdpn pull\` to update ${PROJECT_CONFIG_FILENAME}, or \`cdpn push --force\` to overwrite remote with local.`));
|
|
173
261
|
}
|
|
174
262
|
else {
|
|
175
|
-
|
|
263
|
+
output.log(fmt.dim('Run `cdpn push` to upload these changes, or `cdpn pull` to discard local changes.'));
|
|
176
264
|
}
|
|
177
265
|
return { pen, auth, project, diff, infoAnalysis, remoteMoved, upToDate };
|
|
178
266
|
}
|
|
179
267
|
export function registerStatusCommand(program) {
|
|
180
268
|
program
|
|
181
269
|
.command('status')
|
|
182
|
-
.
|
|
270
|
+
.argument('[target]', 'Directory path to inspect, or "all" to check all Pens in subdirectories')
|
|
271
|
+
.allowExcessArguments(false)
|
|
272
|
+
.description('Compare local files and Pen info with the online version on CodePen (or pass "all" to walk subdirectories)')
|
|
183
273
|
.option('--json', 'Output status as JSON')
|
|
184
|
-
.action(async (options, command) => {
|
|
185
|
-
await
|
|
274
|
+
.action(async (target, options, command) => {
|
|
275
|
+
const result = await runStatusCommand({
|
|
276
|
+
target,
|
|
186
277
|
json: options.json,
|
|
187
278
|
explicitProfile: getGlobalProfileOption(command),
|
|
188
279
|
});
|
|
280
|
+
if (result?.exitCode !== undefined) {
|
|
281
|
+
process.exitCode = result.exitCode;
|
|
282
|
+
}
|
|
189
283
|
});
|
|
190
284
|
}
|