jsrepo 1.0.2 → 1.1.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/dist/index.js +36 -41
- package/package.json +1 -1
- package/src/blocks/utilities/pad.ts +2 -2
- package/src/blocks/utilities/strip-ansi.ts +2 -2
- package/src/commands/add.ts +49 -48
package/dist/index.js
CHANGED
|
@@ -1183,6 +1183,29 @@ var _add = async (blockNames, options) => {
|
|
|
1183
1183
|
const blocksMap = /* @__PURE__ */ new Map();
|
|
1184
1184
|
let repoPaths = config.repos;
|
|
1185
1185
|
if (options.repo) repoPaths = [options.repo];
|
|
1186
|
+
for (const blockSpecifier of blockNames) {
|
|
1187
|
+
if (!blockSpecifier.startsWith("github")) continue;
|
|
1188
|
+
const [providerName, owner, repoName, ...rest] = blockSpecifier.split("/");
|
|
1189
|
+
let repo;
|
|
1190
|
+
if (rest.length > 2) {
|
|
1191
|
+
repo = `${providerName}/${owner}/${repoName}/${rest.join("/")}`;
|
|
1192
|
+
} else {
|
|
1193
|
+
repo = `${providerName}/${owner}/${repoName}`;
|
|
1194
|
+
}
|
|
1195
|
+
if (!repoPaths.find((repoPath) => repoPath === repo)) {
|
|
1196
|
+
if (!options.allow) {
|
|
1197
|
+
const result = await confirm({
|
|
1198
|
+
message: `Allow ${color5.cyan("jsrepo")} to download and run code from ${color5.cyan(repo)}?`,
|
|
1199
|
+
initialValue: true
|
|
1200
|
+
});
|
|
1201
|
+
if (isCancel(result) || !result) {
|
|
1202
|
+
cancel("Canceled!");
|
|
1203
|
+
process.exit(0);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
repoPaths.push(repo);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1186
1209
|
if (!options.allow && options.repo) {
|
|
1187
1210
|
const result = await confirm({
|
|
1188
1211
|
message: `Allow ${color5.cyan("jsrepo")} to download and run code from ${color5.cyan(options.repo)}?`,
|
|
@@ -1259,15 +1282,16 @@ var _add = async (blockNames, options) => {
|
|
|
1259
1282
|
}
|
|
1260
1283
|
verbose(`Installing blocks ${color5.cyan(installingBlockNames.join(", "))}`);
|
|
1261
1284
|
if (options.verbose) console.log("Blocks map: ", blocksMap);
|
|
1262
|
-
const installingBlocks = await getBlocks(installingBlockNames, blocksMap, repoPaths);
|
|
1285
|
+
const installingBlocks = await getBlocks(installingBlockNames, blocksMap, repoPaths, options);
|
|
1263
1286
|
const pm = (await detect({ cwd: process.cwd() }))?.agent ?? "npm";
|
|
1264
1287
|
const tasks = [];
|
|
1265
1288
|
const devDeps = /* @__PURE__ */ new Set();
|
|
1266
1289
|
const deps = /* @__PURE__ */ new Set();
|
|
1267
|
-
for (const {
|
|
1290
|
+
for (const { block } of installingBlocks) {
|
|
1291
|
+
const fullSpecifier = `${block.sourceRepo.url}/${block.category}/${block.name}`;
|
|
1268
1292
|
const watermark = getWatermark(context.package.version, block.sourceRepo.url);
|
|
1269
1293
|
const providerInfo = block.sourceRepo;
|
|
1270
|
-
verbose(`Attempting to add ${
|
|
1294
|
+
verbose(`Attempting to add ${fullSpecifier}`);
|
|
1271
1295
|
const directory = path5.join(config.path, block.category);
|
|
1272
1296
|
verbose(`Creating directory ${color5.bold(directory)}`);
|
|
1273
1297
|
const blockExists = !block.subdirectory && fs6.existsSync(path5.join(directory, block.files[0])) || block.subdirectory && fs6.existsSync(path5.join(directory, block.name));
|
|
@@ -1282,8 +1306,8 @@ var _add = async (blockNames, options) => {
|
|
|
1282
1306
|
}
|
|
1283
1307
|
}
|
|
1284
1308
|
tasks.push({
|
|
1285
|
-
loadingMessage: `Adding ${
|
|
1286
|
-
completedMessage: `Added ${
|
|
1309
|
+
loadingMessage: `Adding ${fullSpecifier}`,
|
|
1310
|
+
completedMessage: `Added ${fullSpecifier}`,
|
|
1287
1311
|
run: async () => {
|
|
1288
1312
|
fs6.mkdirSync(directory, { recursive: true });
|
|
1289
1313
|
const files = [];
|
|
@@ -1292,7 +1316,9 @@ var _add = async (blockNames, options) => {
|
|
|
1292
1316
|
const response = await fetch(rawUrl);
|
|
1293
1317
|
if (!response.ok) {
|
|
1294
1318
|
loading.stop(color5.red(`Error fetching ${color5.bold(rawUrl.href)}`));
|
|
1295
|
-
program2.error(
|
|
1319
|
+
program2.error(
|
|
1320
|
+
color5.red(`There was an error trying to get ${fullSpecifier}`)
|
|
1321
|
+
);
|
|
1296
1322
|
}
|
|
1297
1323
|
return await response.text();
|
|
1298
1324
|
};
|
|
@@ -1414,7 +1440,7 @@ ${content}`;
|
|
|
1414
1440
|
}
|
|
1415
1441
|
outro(color5.green("All done!"));
|
|
1416
1442
|
};
|
|
1417
|
-
var getBlocks = async (blockSpecifiers, blocksMap, repoPaths) => {
|
|
1443
|
+
var getBlocks = async (blockSpecifiers, blocksMap, repoPaths, options) => {
|
|
1418
1444
|
const blocks = /* @__PURE__ */ new Map();
|
|
1419
1445
|
for (const blockSpecifier of blockSpecifiers) {
|
|
1420
1446
|
let block = void 0;
|
|
@@ -1438,38 +1464,6 @@ var getBlocks = async (blockSpecifiers, blocksMap, repoPaths) => {
|
|
|
1438
1464
|
break;
|
|
1439
1465
|
}
|
|
1440
1466
|
} else {
|
|
1441
|
-
if (repoPaths.length === 0) {
|
|
1442
|
-
const [providerName, owner, repoName, ...rest] = blockSpecifier.split("/");
|
|
1443
|
-
let repo;
|
|
1444
|
-
if (rest.length > 2) {
|
|
1445
|
-
repo = `${providerName}/${owner}/${repoName}/${rest.join("/")}`;
|
|
1446
|
-
} else {
|
|
1447
|
-
repo = `${providerName}/${owner}/${repoName}`;
|
|
1448
|
-
}
|
|
1449
|
-
const providerInfo = (await getProviderInfo(repo)).match(
|
|
1450
|
-
(val) => val,
|
|
1451
|
-
(err) => program2.error(color5.red(err))
|
|
1452
|
-
);
|
|
1453
|
-
const manifestUrl = await providerInfo.provider.resolveRaw(
|
|
1454
|
-
providerInfo,
|
|
1455
|
-
OUTPUT_FILE
|
|
1456
|
-
);
|
|
1457
|
-
const categories = (await getManifest(manifestUrl)).match(
|
|
1458
|
-
(val) => val,
|
|
1459
|
-
(err) => program2.error(color5.red(err))
|
|
1460
|
-
);
|
|
1461
|
-
for (const category of categories) {
|
|
1462
|
-
for (const block2 of category.blocks) {
|
|
1463
|
-
blocksMap.set(
|
|
1464
|
-
`${providerInfo.name}/${providerInfo.owner}/${providerInfo.repoName}/${category.name}/${block2.name}`,
|
|
1465
|
-
{
|
|
1466
|
-
...block2,
|
|
1467
|
-
sourceRepo: providerInfo
|
|
1468
|
-
}
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
1467
|
block = blocksMap.get(blockSpecifier);
|
|
1474
1468
|
}
|
|
1475
1469
|
if (!block) {
|
|
@@ -1480,9 +1474,10 @@ var getBlocks = async (blockSpecifiers, blocksMap, repoPaths) => {
|
|
|
1480
1474
|
blocks.set(blockSpecifier, { name: blockSpecifier, subDependency: false, block });
|
|
1481
1475
|
if (block.localDependencies && block.localDependencies.length > 0) {
|
|
1482
1476
|
const subDeps = await getBlocks(
|
|
1483
|
-
block.localDependencies.filter((dep) => blocks.has(dep)),
|
|
1477
|
+
block.localDependencies.filter((dep) => !blocks.has(dep)),
|
|
1484
1478
|
blocksMap,
|
|
1485
|
-
repoPaths
|
|
1479
|
+
repoPaths,
|
|
1480
|
+
options
|
|
1486
1481
|
);
|
|
1487
1482
|
for (const dep of subDeps) {
|
|
1488
1483
|
blocks.set(dep.name, dep);
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -68,6 +68,38 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
68
68
|
// we just want to override all others if supplied via the CLI
|
|
69
69
|
if (options.repo) repoPaths = [options.repo];
|
|
70
70
|
|
|
71
|
+
// resolve repos for blocks
|
|
72
|
+
for (const blockSpecifier of blockNames) {
|
|
73
|
+
// we are only getting repos for blocks that specified repos
|
|
74
|
+
if (!blockSpecifier.startsWith('github')) continue;
|
|
75
|
+
|
|
76
|
+
const [providerName, owner, repoName, ...rest] = blockSpecifier.split('/');
|
|
77
|
+
|
|
78
|
+
let repo: string;
|
|
79
|
+
// if rest is greater than 2 it isn't the block specifier so it is part of the path
|
|
80
|
+
if (rest.length > 2) {
|
|
81
|
+
repo = `${providerName}/${owner}/${repoName}/${rest.join('/')}`;
|
|
82
|
+
} else {
|
|
83
|
+
repo = `${providerName}/${owner}/${repoName}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!repoPaths.find((repoPath) => repoPath === repo)) {
|
|
87
|
+
if (!options.allow) {
|
|
88
|
+
const result = await confirm({
|
|
89
|
+
message: `Allow ${color.cyan('jsrepo')} to download and run code from ${color.cyan(repo)}?`,
|
|
90
|
+
initialValue: true,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (isCancel(result) || !result) {
|
|
94
|
+
cancel('Canceled!');
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
repoPaths.push(repo);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
71
103
|
if (!options.allow && options.repo) {
|
|
72
104
|
const result = await confirm({
|
|
73
105
|
message: `Allow ${color.cyan('jsrepo')} to download and run code from ${color.cyan(options.repo)}?`,
|
|
@@ -84,6 +116,7 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
84
116
|
|
|
85
117
|
if (!options.verbose) loading.start(`Fetching blocks from ${color.cyan(repoPaths.join(', '))}`);
|
|
86
118
|
|
|
119
|
+
// get blocks from each repo
|
|
87
120
|
for (const repo of repoPaths) {
|
|
88
121
|
const providerInfo: gitProviders.Info = (await gitProviders.getProviderInfo(repo)).match(
|
|
89
122
|
(info) => info,
|
|
@@ -126,6 +159,7 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
126
159
|
|
|
127
160
|
let installingBlockNames = blockNames;
|
|
128
161
|
|
|
162
|
+
// if no blocks are provided prompt the user for what blocks they want
|
|
129
163
|
if (installingBlockNames.length === 0) {
|
|
130
164
|
const promptResult = await multiselect({
|
|
131
165
|
message: 'Select which blocks to add.',
|
|
@@ -168,7 +202,7 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
168
202
|
|
|
169
203
|
if (options.verbose) console.log('Blocks map: ', blocksMap);
|
|
170
204
|
|
|
171
|
-
const installingBlocks = await getBlocks(installingBlockNames, blocksMap, repoPaths);
|
|
205
|
+
const installingBlocks = await getBlocks(installingBlockNames, blocksMap, repoPaths, options);
|
|
172
206
|
|
|
173
207
|
const pm = (await detect({ cwd: process.cwd() }))?.agent ?? 'npm';
|
|
174
208
|
|
|
@@ -177,12 +211,13 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
177
211
|
const devDeps: Set<string> = new Set<string>();
|
|
178
212
|
const deps: Set<string> = new Set<string>();
|
|
179
213
|
|
|
180
|
-
for (const {
|
|
214
|
+
for (const { block } of installingBlocks) {
|
|
215
|
+
const fullSpecifier = `${block.sourceRepo.url}/${block.category}/${block.name}`;
|
|
181
216
|
const watermark = getWatermark(context.package.version, block.sourceRepo.url);
|
|
182
217
|
|
|
183
218
|
const providerInfo = block.sourceRepo;
|
|
184
219
|
|
|
185
|
-
verbose(`Attempting to add ${
|
|
220
|
+
verbose(`Attempting to add ${fullSpecifier}`);
|
|
186
221
|
|
|
187
222
|
const directory = path.join(config.path, block.category);
|
|
188
223
|
|
|
@@ -205,8 +240,8 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
205
240
|
}
|
|
206
241
|
|
|
207
242
|
tasks.push({
|
|
208
|
-
loadingMessage: `Adding ${
|
|
209
|
-
completedMessage: `Added ${
|
|
243
|
+
loadingMessage: `Adding ${fullSpecifier}`,
|
|
244
|
+
completedMessage: `Added ${fullSpecifier}`,
|
|
210
245
|
run: async () => {
|
|
211
246
|
// in case the directory didn't already exist
|
|
212
247
|
fs.mkdirSync(directory, { recursive: true });
|
|
@@ -220,7 +255,9 @@ const _add = async (blockNames: string[], options: Options) => {
|
|
|
220
255
|
|
|
221
256
|
if (!response.ok) {
|
|
222
257
|
loading.stop(color.red(`Error fetching ${color.bold(rawUrl.href)}`));
|
|
223
|
-
program.error(
|
|
258
|
+
program.error(
|
|
259
|
+
color.red(`There was an error trying to get ${fullSpecifier}`)
|
|
260
|
+
);
|
|
224
261
|
}
|
|
225
262
|
|
|
226
263
|
return await response.text();
|
|
@@ -392,7 +429,8 @@ type InstallingBlock = {
|
|
|
392
429
|
const getBlocks = async (
|
|
393
430
|
blockSpecifiers: string[],
|
|
394
431
|
blocksMap: Map<string, RemoteBlock>,
|
|
395
|
-
repoPaths: string[]
|
|
432
|
+
repoPaths: string[],
|
|
433
|
+
options: Options
|
|
396
434
|
): Promise<InstallingBlock[]> => {
|
|
397
435
|
const blocks = new Map<string, InstallingBlock>();
|
|
398
436
|
|
|
@@ -411,6 +449,7 @@ const getBlocks = async (
|
|
|
411
449
|
);
|
|
412
450
|
}
|
|
413
451
|
|
|
452
|
+
// check every repo for the block and return the first block found
|
|
414
453
|
for (const repo of repoPaths) {
|
|
415
454
|
// we unwrap because we already checked this
|
|
416
455
|
const providerInfo = (await gitProviders.getProviderInfo(repo)).unwrap();
|
|
@@ -426,45 +465,6 @@ const getBlocks = async (
|
|
|
426
465
|
break;
|
|
427
466
|
}
|
|
428
467
|
} else {
|
|
429
|
-
if (repoPaths.length === 0) {
|
|
430
|
-
const [providerName, owner, repoName, ...rest] = blockSpecifier.split('/');
|
|
431
|
-
|
|
432
|
-
let repo: string;
|
|
433
|
-
// if rest is greater than 2 it isn't the block specifier so it is part of the path
|
|
434
|
-
if (rest.length > 2) {
|
|
435
|
-
repo = `${providerName}/${owner}/${repoName}/${rest.join('/')}`;
|
|
436
|
-
} else {
|
|
437
|
-
repo = `${providerName}/${owner}/${repoName}`;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const providerInfo = (await gitProviders.getProviderInfo(repo)).match(
|
|
441
|
-
(val) => val,
|
|
442
|
-
(err) => program.error(color.red(err))
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
const manifestUrl = await providerInfo.provider.resolveRaw(
|
|
446
|
-
providerInfo,
|
|
447
|
-
OUTPUT_FILE
|
|
448
|
-
);
|
|
449
|
-
|
|
450
|
-
const categories = (await gitProviders.getManifest(manifestUrl)).match(
|
|
451
|
-
(val) => val,
|
|
452
|
-
(err) => program.error(color.red(err))
|
|
453
|
-
);
|
|
454
|
-
|
|
455
|
-
for (const category of categories) {
|
|
456
|
-
for (const block of category.blocks) {
|
|
457
|
-
blocksMap.set(
|
|
458
|
-
`${providerInfo.name}/${providerInfo.owner}/${providerInfo.repoName}/${category.name}/${block.name}`,
|
|
459
|
-
{
|
|
460
|
-
...block,
|
|
461
|
-
sourceRepo: providerInfo,
|
|
462
|
-
}
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
468
|
block = blocksMap.get(blockSpecifier);
|
|
469
469
|
}
|
|
470
470
|
|
|
@@ -478,9 +478,10 @@ const getBlocks = async (
|
|
|
478
478
|
|
|
479
479
|
if (block.localDependencies && block.localDependencies.length > 0) {
|
|
480
480
|
const subDeps = await getBlocks(
|
|
481
|
-
block.localDependencies.filter((dep) => blocks.has(dep)),
|
|
481
|
+
block.localDependencies.filter((dep) => !blocks.has(dep)),
|
|
482
482
|
blocksMap,
|
|
483
|
-
repoPaths
|
|
483
|
+
repoPaths,
|
|
484
|
+
options
|
|
484
485
|
);
|
|
485
486
|
|
|
486
487
|
for (const dep of subDeps) {
|