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/shell/scripts.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
const directoryEl = document.getElementById('demo-directory');
|
|
2
|
+
const cardTemplate = document.getElementById('demo-card-template');
|
|
3
|
+
const emptyStateTemplate = document.getElementById('empty-state-template');
|
|
4
|
+
const missingDemoWarningTemplate = document.getElementById('missing-demo-warning-template');
|
|
5
|
+
|
|
6
|
+
function toSafeLocalHref(rawHref) {
|
|
7
|
+
if (typeof rawHref !== 'string' || !rawHref.startsWith('./')) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const resolved = new URL(rawHref, window.location.href);
|
|
12
|
+
if (
|
|
13
|
+
resolved.origin !== window.location.origin ||
|
|
14
|
+
(resolved.protocol !== 'http:' && resolved.protocol !== 'https:')
|
|
15
|
+
) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return rawHref;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function toSafeCodePenUrl(rawUrl) {
|
|
25
|
+
if (typeof rawUrl !== 'string') {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const parsed = new URL(rawUrl);
|
|
30
|
+
if (parsed.protocol !== 'https:') {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (parsed.hostname !== 'codepen.io' && !parsed.hostname.endsWith('.codepen.io')) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return parsed.href;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function createHeading(level, className) {
|
|
43
|
+
const clamped = Math.min(Math.max(level, 2), 6);
|
|
44
|
+
const heading = document.createElement(`h${clamped}`);
|
|
45
|
+
heading.className = className;
|
|
46
|
+
return heading;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createDemoCard(demo, headingLevel) {
|
|
50
|
+
const safeHref = toSafeLocalHref(demo?.href);
|
|
51
|
+
if (!safeHref) return null;
|
|
52
|
+
|
|
53
|
+
const title = typeof demo?.title === 'string' && demo.title.trim() ? demo.title.trim() : demo.path;
|
|
54
|
+
const pathText = typeof demo?.path === 'string' ? demo.path : safeHref.replace(/^\.\//, '');
|
|
55
|
+
const fragment = cardTemplate.content.cloneNode(true);
|
|
56
|
+
|
|
57
|
+
const pathWrapperEl = fragment.querySelector('.demo-path');
|
|
58
|
+
const pathTextEl = fragment.querySelector('.demo-path-text');
|
|
59
|
+
pathTextEl.textContent = pathText;
|
|
60
|
+
pathWrapperEl.setAttribute('title', pathText);
|
|
61
|
+
|
|
62
|
+
const headingEl = createHeading(headingLevel, 'demo-card-title');
|
|
63
|
+
headingEl.textContent = title;
|
|
64
|
+
pathWrapperEl.after(headingEl);
|
|
65
|
+
|
|
66
|
+
const bodyEl = fragment.querySelector('.demo-body');
|
|
67
|
+
const descriptionEl = fragment.querySelector('.demo-description');
|
|
68
|
+
if (typeof demo?.description === 'string' && demo.description.trim()) {
|
|
69
|
+
descriptionEl.textContent = demo.description.trim();
|
|
70
|
+
} else {
|
|
71
|
+
descriptionEl.remove();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const tagsEl = fragment.querySelector('.demo-tags');
|
|
75
|
+
const rawTags = Array.isArray(demo?.tags) ? demo.tags : [];
|
|
76
|
+
const tagItems = [];
|
|
77
|
+
for (const rawTag of rawTags) {
|
|
78
|
+
if (typeof rawTag !== 'string') continue;
|
|
79
|
+
const cleaned = rawTag.trim();
|
|
80
|
+
if (!cleaned) continue;
|
|
81
|
+
const li = document.createElement('li');
|
|
82
|
+
li.className = 'demo-tag';
|
|
83
|
+
li.textContent = cleaned;
|
|
84
|
+
tagItems.push(li);
|
|
85
|
+
}
|
|
86
|
+
if (tagItems.length > 0) {
|
|
87
|
+
tagsEl.replaceChildren(...tagItems);
|
|
88
|
+
} else {
|
|
89
|
+
tagsEl.remove();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (bodyEl.childElementCount === 0) {
|
|
93
|
+
bodyEl.classList.add('is-empty');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const openEl = fragment.querySelector('.demo-open');
|
|
97
|
+
openEl.setAttribute('href', safeHref);
|
|
98
|
+
openEl.setAttribute('aria-label', `Open Demo: ${title}`);
|
|
99
|
+
|
|
100
|
+
const codepenEl = fragment.querySelector('.demo-codepen');
|
|
101
|
+
const safeCodePenUrl = toSafeCodePenUrl(demo?.codepenUrl);
|
|
102
|
+
if (safeCodePenUrl) {
|
|
103
|
+
codepenEl.setAttribute('href', safeCodePenUrl);
|
|
104
|
+
codepenEl.setAttribute('aria-label', `Edit ${title} on CodePen`);
|
|
105
|
+
} else {
|
|
106
|
+
codepenEl.removeAttribute('href');
|
|
107
|
+
codepenEl.removeAttribute('target');
|
|
108
|
+
codepenEl.removeAttribute('rel');
|
|
109
|
+
codepenEl.setAttribute('aria-disabled', 'true');
|
|
110
|
+
codepenEl.setAttribute('title', 'Not linked to CodePen');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return fragment;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const SUPPORTS_SCROLL_TIMELINE =
|
|
117
|
+
typeof CSS !== 'undefined' &&
|
|
118
|
+
typeof CSS.supports === 'function' &&
|
|
119
|
+
CSS.supports('animation-timeline: scroll(self inline)');
|
|
120
|
+
|
|
121
|
+
let pathResizeObserver = null;
|
|
122
|
+
|
|
123
|
+
function syncPathOverflowFallback() {
|
|
124
|
+
if (SUPPORTS_SCROLL_TIMELINE) return;
|
|
125
|
+
|
|
126
|
+
const updateEl = (el) => {
|
|
127
|
+
const overflows = el.scrollWidth > el.clientWidth + 1;
|
|
128
|
+
el.toggleAttribute('data-overflows', overflows);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const paths = directoryEl.querySelectorAll('.demo-path');
|
|
132
|
+
if (pathResizeObserver) {
|
|
133
|
+
pathResizeObserver.disconnect();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (typeof ResizeObserver === 'function') {
|
|
137
|
+
pathResizeObserver = new ResizeObserver((entries) => {
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
updateEl(entry.target);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
for (const el of paths) {
|
|
143
|
+
updateEl(el);
|
|
144
|
+
pathResizeObserver.observe(el);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
for (const el of paths) {
|
|
148
|
+
updateEl(el);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function createGroupSection(headingText, demos, subgroups = [], headingLevel = 2) {
|
|
154
|
+
const cards = (Array.isArray(demos) ? demos : [])
|
|
155
|
+
.map((demo) => createDemoCard(demo, headingLevel + 1))
|
|
156
|
+
.filter(Boolean);
|
|
157
|
+
|
|
158
|
+
const childSections = (Array.isArray(subgroups) ? subgroups : [])
|
|
159
|
+
.map((subgroup) => {
|
|
160
|
+
const subHeading =
|
|
161
|
+
typeof subgroup?.title === 'string' && subgroup.title.trim()
|
|
162
|
+
? subgroup.title.trim()
|
|
163
|
+
: String(subgroup?.id ?? 'Demos');
|
|
164
|
+
return createGroupSection(subHeading, subgroup?.demos, subgroup?.groups, headingLevel + 1);
|
|
165
|
+
})
|
|
166
|
+
.filter(Boolean);
|
|
167
|
+
|
|
168
|
+
if (cards.length === 0 && childSections.length === 0) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const section = document.createElement('section');
|
|
173
|
+
section.className = 'demo-group';
|
|
174
|
+
|
|
175
|
+
const headingEl = createHeading(headingLevel, 'demo-group-title');
|
|
176
|
+
headingEl.textContent = headingText;
|
|
177
|
+
section.append(headingEl);
|
|
178
|
+
|
|
179
|
+
if (cards.length > 0) {
|
|
180
|
+
const gridEl = document.createElement('ul');
|
|
181
|
+
gridEl.className = 'demo-grid';
|
|
182
|
+
gridEl.setAttribute('role', 'list');
|
|
183
|
+
gridEl.replaceChildren(...cards);
|
|
184
|
+
section.append(gridEl);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (childSections.length > 0) {
|
|
188
|
+
const subgroupsEl = document.createElement('div');
|
|
189
|
+
subgroupsEl.className = 'demo-subgroups';
|
|
190
|
+
subgroupsEl.replaceChildren(...childSections);
|
|
191
|
+
section.append(subgroupsEl);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return section;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function createCode(text) {
|
|
198
|
+
const code = document.createElement('code');
|
|
199
|
+
code.textContent = text;
|
|
200
|
+
return code;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function createErrorState() {
|
|
204
|
+
const section = document.createElement('section');
|
|
205
|
+
section.className = 'empty-state';
|
|
206
|
+
|
|
207
|
+
const heading = document.createElement('h2');
|
|
208
|
+
heading.textContent = 'Unable to load demos';
|
|
209
|
+
|
|
210
|
+
const paragraph = document.createElement('p');
|
|
211
|
+
paragraph.append(
|
|
212
|
+
'Run ',
|
|
213
|
+
createCode('cdpn build'),
|
|
214
|
+
' to generate ',
|
|
215
|
+
createCode('demos.json'),
|
|
216
|
+
', or start the dev server with ',
|
|
217
|
+
createCode('cdpn serve'),
|
|
218
|
+
' to generate and watch it automatically.',
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
section.append(heading, paragraph);
|
|
222
|
+
return section;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function loadDemos() {
|
|
226
|
+
try {
|
|
227
|
+
const response = await fetch('./demos.json', {
|
|
228
|
+
cache: 'no-store',
|
|
229
|
+
signal: AbortSignal.timeout(5_000),
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
throw new Error(`HTTP ${response.status}`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const data = await response.json();
|
|
237
|
+
const groups = Array.isArray(data?.groups) ? data.groups : [];
|
|
238
|
+
const standalone = Array.isArray(data?.standalone) ? data.standalone : [];
|
|
239
|
+
|
|
240
|
+
const sections = [];
|
|
241
|
+
|
|
242
|
+
for (const group of groups) {
|
|
243
|
+
const heading =
|
|
244
|
+
typeof group?.title === 'string' && group.title.trim()
|
|
245
|
+
? group.title.trim()
|
|
246
|
+
: String(group?.id ?? 'Demos');
|
|
247
|
+
const section = createGroupSection(heading, group?.demos, group?.groups, 2);
|
|
248
|
+
if (section) sections.push(section);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (standalone.length > 0) {
|
|
252
|
+
const standaloneHeading = sections.length > 0 ? 'Standalone Demos' : 'Demos';
|
|
253
|
+
const section = createGroupSection(standaloneHeading, standalone, [], 2);
|
|
254
|
+
if (section) sections.push(section);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (sections.length === 0) {
|
|
258
|
+
const emptyNodes = [emptyStateTemplate.content.cloneNode(true)];
|
|
259
|
+
if (missingDemoWarningTemplate) {
|
|
260
|
+
emptyNodes.push(missingDemoWarningTemplate.content.cloneNode(true));
|
|
261
|
+
}
|
|
262
|
+
directoryEl.replaceChildren(...emptyNodes);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (missingDemoWarningTemplate) {
|
|
267
|
+
sections.push(missingDemoWarningTemplate.content.cloneNode(true));
|
|
268
|
+
}
|
|
269
|
+
directoryEl.replaceChildren(...sections);
|
|
270
|
+
syncPathOverflowFallback();
|
|
271
|
+
} catch {
|
|
272
|
+
directoryEl.replaceChildren(createErrorState());
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
loadDemos();
|