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/utils/strings.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export const CONTROL_CHAR_PATTERN = /[\x00-\x1f\x7f]/;
|
|
2
|
+
const ACRONYMS = new Map([
|
|
3
|
+
['ai', 'AI'],
|
|
4
|
+
['api', 'API'],
|
|
5
|
+
['apis', 'APIs'],
|
|
6
|
+
['aria', 'ARIA'],
|
|
7
|
+
['cls', 'CLS'],
|
|
8
|
+
['css', 'CSS'],
|
|
9
|
+
['cwv', 'CWV'],
|
|
10
|
+
['dom', 'DOM'],
|
|
11
|
+
['html', 'HTML'],
|
|
12
|
+
['http', 'HTTP'],
|
|
13
|
+
['inp', 'INP'],
|
|
14
|
+
['js', 'JS'],
|
|
15
|
+
['json', 'JSON'],
|
|
16
|
+
['lcp', 'LCP'],
|
|
17
|
+
['mcp', 'MCP'],
|
|
18
|
+
['pwa', 'PWA'],
|
|
19
|
+
['svg', 'SVG'],
|
|
20
|
+
['ui', 'UI'],
|
|
21
|
+
['url', 'URL'],
|
|
22
|
+
['ux', 'UX'],
|
|
23
|
+
['wasm', 'WASM'],
|
|
24
|
+
['webgl', 'WebGL'],
|
|
25
|
+
['webgpu', 'WebGPU'],
|
|
26
|
+
['webmcp', 'WebMCP'],
|
|
27
|
+
]);
|
|
28
|
+
const MINOR_WORDS = new Set([
|
|
29
|
+
'a',
|
|
30
|
+
'an',
|
|
31
|
+
'and',
|
|
32
|
+
'as',
|
|
33
|
+
'at',
|
|
34
|
+
'by',
|
|
35
|
+
'for',
|
|
36
|
+
'from',
|
|
37
|
+
'in',
|
|
38
|
+
'of',
|
|
39
|
+
'on',
|
|
40
|
+
'or',
|
|
41
|
+
'the',
|
|
42
|
+
'to',
|
|
43
|
+
'with',
|
|
44
|
+
]);
|
|
45
|
+
export function hasControlChars(value) {
|
|
46
|
+
return CONTROL_CHAR_PATTERN.test(value);
|
|
47
|
+
}
|
|
48
|
+
export function isPlainObject(value) {
|
|
49
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
export function isLoopbackHost(hostname) {
|
|
52
|
+
return hostname === '127.0.0.1' || hostname === 'localhost' || hostname === '[::1]';
|
|
53
|
+
}
|
|
54
|
+
export function compareNatural(a, b) {
|
|
55
|
+
return a.localeCompare(b, 'en', { numeric: true, sensitivity: 'base' });
|
|
56
|
+
}
|
|
57
|
+
export function normalizePlainText(value, maxLength) {
|
|
58
|
+
const cleaned = String(value).replace(/\s+/g, ' ').trim();
|
|
59
|
+
if (!cleaned)
|
|
60
|
+
return null;
|
|
61
|
+
return cleaned.length > maxLength ? `${cleaned.slice(0, maxLength - 1)}…` : cleaned;
|
|
62
|
+
}
|
|
63
|
+
export function formatFolderTitle(folderName) {
|
|
64
|
+
const words = folderName.split(/[-_]+/).filter(Boolean);
|
|
65
|
+
return words
|
|
66
|
+
.map((word, index) => {
|
|
67
|
+
const lower = word.toLowerCase();
|
|
68
|
+
const acronym = ACRONYMS.get(lower);
|
|
69
|
+
if (acronym) {
|
|
70
|
+
return acronym;
|
|
71
|
+
}
|
|
72
|
+
if (index > 0 && index < words.length - 1 && MINOR_WORDS.has(lower)) {
|
|
73
|
+
return lower;
|
|
74
|
+
}
|
|
75
|
+
return (word[0]?.toUpperCase() ?? '') + word.slice(1);
|
|
76
|
+
})
|
|
77
|
+
.join(' ');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Converts a Pen title into a safe directory-name slug, or returns null for empty / "Untitled".
|
|
81
|
+
*/
|
|
82
|
+
export function slugifyTitle(rawTitle) {
|
|
83
|
+
const title = (rawTitle ?? '').trim();
|
|
84
|
+
if (!title || title.toLowerCase() === 'untitled') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const slug = title
|
|
88
|
+
.normalize('NFKD')
|
|
89
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
90
|
+
.toLowerCase()
|
|
91
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
92
|
+
.replace(/^-+|-+$/g, '')
|
|
93
|
+
.slice(0, 64);
|
|
94
|
+
if (!slug || slug === '.' || slug === '..') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return slug;
|
|
98
|
+
}
|
package/utils/watcher.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function isCommonIgnoredWatchPath(rawFilename) {
|
|
4
|
+
if (typeof rawFilename !== 'string' || !rawFilename)
|
|
5
|
+
return false;
|
|
6
|
+
const normalized = rawFilename.split(path.sep).join('/');
|
|
7
|
+
const segments = normalized.split('/');
|
|
8
|
+
if (segments.at(-1) === '.DS_Store')
|
|
9
|
+
return true;
|
|
10
|
+
if (segments.includes('node_modules') || segments.includes('.git'))
|
|
11
|
+
return true;
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Starts a recursive `fs.watch` with debounced single-flight execution so overlapping
|
|
16
|
+
* filesystem events coalesce cleanly without concurrent handler runs.
|
|
17
|
+
*/
|
|
18
|
+
export function createDebouncedWatcher(options) {
|
|
19
|
+
const { rootDir, debounceMs = 150, shouldIgnore, onChange, onError } = options;
|
|
20
|
+
let timer = null;
|
|
21
|
+
let isRunning = false;
|
|
22
|
+
let pendingRun = false;
|
|
23
|
+
let closed = false;
|
|
24
|
+
async function run() {
|
|
25
|
+
if (closed)
|
|
26
|
+
return;
|
|
27
|
+
if (isRunning) {
|
|
28
|
+
pendingRun = true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
isRunning = true;
|
|
32
|
+
try {
|
|
33
|
+
await onChange();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
isRunning = false;
|
|
40
|
+
if (pendingRun && !closed) {
|
|
41
|
+
pendingRun = false;
|
|
42
|
+
schedule();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function schedule() {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
if (timer)
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
timer = setTimeout(() => {
|
|
52
|
+
timer = null;
|
|
53
|
+
void run();
|
|
54
|
+
}, debounceMs);
|
|
55
|
+
}
|
|
56
|
+
let watcher = null;
|
|
57
|
+
try {
|
|
58
|
+
watcher = watch(rootDir, { recursive: true }, (_eventType, filename) => {
|
|
59
|
+
if (isCommonIgnoredWatchPath(filename))
|
|
60
|
+
return;
|
|
61
|
+
if (shouldIgnore?.(filename))
|
|
62
|
+
return;
|
|
63
|
+
schedule();
|
|
64
|
+
});
|
|
65
|
+
watcher.on('error', (error) => {
|
|
66
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
close() {
|
|
74
|
+
closed = true;
|
|
75
|
+
if (timer) {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
timer = null;
|
|
78
|
+
}
|
|
79
|
+
watcher?.close();
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { API_KEY_ENV_VAR, API_KEY_FILENAME, findMatchingProfile, getKeyType,
|
|
2
|
-
import {
|
|
1
|
+
import { API_KEY_ENV_VAR, API_KEY_FILENAME, findMatchingProfile, getKeyType, validateProfileName, } from '../config/auth.js';
|
|
2
|
+
import { writeProjectConfig } from '../config/project.js';
|
|
3
|
+
import { readAuthStore } from '../config/user-store.js';
|
|
4
|
+
import { PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
5
|
+
import { CliError } from '../errors.js';
|
|
3
6
|
import { fmt } from '../utils/format.js';
|
|
4
|
-
import {
|
|
5
|
-
import { isInteractive, promptSelect } from '../utils/prompts.js';
|
|
7
|
+
import { defaultOutput } from '../utils/output.js';
|
|
8
|
+
import { isInteractive, promptSelect } from '../utils/prompts/index.js';
|
|
6
9
|
/**
|
|
7
10
|
* Extracts the global `--profile <name>` option from any Commander command instance.
|
|
8
11
|
*/
|
|
@@ -25,6 +28,7 @@ export function getGlobalProfileOption(command) {
|
|
|
25
28
|
*/
|
|
26
29
|
export async function resolveCommandAuth(options = {}) {
|
|
27
30
|
const env = options.env ?? process.env;
|
|
31
|
+
const output = options.output ?? defaultOutput;
|
|
28
32
|
const envKey = env[API_KEY_ENV_VAR]?.trim() || '';
|
|
29
33
|
const { store, filePath, insecurePermissions } = await readAuthStore({
|
|
30
34
|
homeDir: options.homeDir,
|
|
@@ -115,7 +119,7 @@ export async function resolveCommandAuth(options = {}) {
|
|
|
115
119
|
});
|
|
116
120
|
const question = options.promptMessage ??
|
|
117
121
|
(options.project
|
|
118
|
-
?
|
|
122
|
+
? 'This Pen is not associated with a profile yet. Which profile should be used?'
|
|
119
123
|
: 'Which CodePen profile should be used?');
|
|
120
124
|
chosenProfile = await selectImpl(question, selectOptions, defaultIndex);
|
|
121
125
|
}
|
|
@@ -128,11 +132,13 @@ export async function resolveCommandAuth(options = {}) {
|
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
// Persist chosen profile into an existing .cdpn.json that didn't have one yet
|
|
131
|
-
if (options.project &&
|
|
135
|
+
if (options.project &&
|
|
136
|
+
!options.project.config.profile &&
|
|
137
|
+
options.persistProfileToProject !== false) {
|
|
132
138
|
options.project.config.profile = chosenProfile;
|
|
133
139
|
await writeProjectConfig(options.project.rootDir, options.project.config);
|
|
134
140
|
if (interactive) {
|
|
135
|
-
|
|
141
|
+
output.log(fmt.dim(`Associated this Pen with profile "${chosenProfile}" in ${PROJECT_CONFIG_FILENAME}.`));
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
return makeFileAuth(chosenProfile);
|