jsrepo 1.0.3 → 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 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)}?`,
@@ -1264,10 +1287,11 @@ var _add = async (blockNames, options) => {
1264
1287
  const tasks = [];
1265
1288
  const devDeps = /* @__PURE__ */ new Set();
1266
1289
  const deps = /* @__PURE__ */ new Set();
1267
- for (const { name: specifier, block } of installingBlocks) {
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 ${specifier}`);
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 ${specifier}`,
1286
- completedMessage: `Added ${specifier}`,
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(color5.red(`There was an error trying to get ${specifier}`));
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
  };
@@ -1438,43 +1464,6 @@ var getBlocks = async (blockSpecifiers, blocksMap, repoPaths, options) => {
1438
1464
  break;
1439
1465
  }
1440
1466
  } else {
1441
- const [providerName, owner, repoName, ...rest] = blockSpecifier.split("/");
1442
- let repo;
1443
- if (rest.length > 2) {
1444
- repo = `${providerName}/${owner}/${repoName}/${rest.join("/")}`;
1445
- } else {
1446
- repo = `${providerName}/${owner}/${repoName}`;
1447
- }
1448
- const providerInfo = (await getProviderInfo(repo)).match(
1449
- (val) => val,
1450
- (err) => program2.error(color5.red(err))
1451
- );
1452
- const manifestUrl = await providerInfo.provider.resolveRaw(providerInfo, OUTPUT_FILE);
1453
- if (!options.allow) {
1454
- const result = await confirm({
1455
- message: `Allow ${color5.cyan("jsrepo")} to download and run code from ${color5.cyan(repo)}?`,
1456
- initialValue: true
1457
- });
1458
- if (isCancel(result) || !result) {
1459
- cancel("Canceled!");
1460
- process.exit(0);
1461
- }
1462
- }
1463
- const categories = (await getManifest(manifestUrl)).match(
1464
- (val) => val,
1465
- (err) => program2.error(color5.red(err))
1466
- );
1467
- for (const category of categories) {
1468
- for (const block2 of category.blocks) {
1469
- blocksMap.set(
1470
- `${providerInfo.name}/${providerInfo.owner}/${providerInfo.repoName}/${category.name}/${block2.name}`,
1471
- {
1472
- ...block2,
1473
- sourceRepo: providerInfo
1474
- }
1475
- );
1476
- }
1477
- }
1478
1467
  block = blocksMap.get(blockSpecifier);
1479
1468
  }
1480
1469
  if (!block) {
@@ -1485,7 +1474,7 @@ var getBlocks = async (blockSpecifiers, blocksMap, repoPaths, options) => {
1485
1474
  blocks.set(blockSpecifier, { name: blockSpecifier, subDependency: false, block });
1486
1475
  if (block.localDependencies && block.localDependencies.length > 0) {
1487
1476
  const subDeps = await getBlocks(
1488
- block.localDependencies.filter((dep) => blocks.has(dep)),
1477
+ block.localDependencies.filter((dep) => !blocks.has(dep)),
1489
1478
  blocksMap,
1490
1479
  repoPaths,
1491
1480
  options
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jsrepo",
3
3
  "description": "A CLI to add shared code from remote repositories.",
4
- "version": "1.0.3",
4
+ "version": "1.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ieedan/jsrepo"
@@ -1,7 +1,7 @@
1
1
  /*
2
- jsrepo 1.0.0-next.18
2
+ jsrepo 1.0.3
3
3
  Installed from github/ieedan/std
4
- 11-18-2024
4
+ 11-19-2024
5
5
  */
6
6
 
7
7
  import { stripAsni } from './strip-ansi';
@@ -1,7 +1,7 @@
1
1
  /*
2
- jsrepo 1.0.0-next.18
2
+ jsrepo 1.0.3
3
3
  Installed from github/ieedan/std
4
- 11-18-2024
4
+ 11-19-2024
5
5
  */
6
6
 
7
7
  import ansiRegex from 'ansi-regex';
@@ -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.',
@@ -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 { name: specifier, block } of installingBlocks) {
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 ${specifier}`);
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 ${specifier}`,
209
- completedMessage: `Added ${specifier}`,
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(color.red(`There was an error trying to get ${specifier}`));
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();
@@ -412,6 +449,7 @@ const getBlocks = async (
412
449
  );
413
450
  }
414
451
 
452
+ // check every repo for the block and return the first block found
415
453
  for (const repo of repoPaths) {
416
454
  // we unwrap because we already checked this
417
455
  const providerInfo = (await gitProviders.getProviderInfo(repo)).unwrap();
@@ -427,52 +465,6 @@ const getBlocks = async (
427
465
  break;
428
466
  }
429
467
  } else {
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(providerInfo, OUTPUT_FILE);
446
-
447
- if (!options.allow) {
448
- const result = await confirm({
449
- message: `Allow ${color.cyan('jsrepo')} to download and run code from ${color.cyan(repo)}?`,
450
- initialValue: true,
451
- });
452
-
453
- if (isCancel(result) || !result) {
454
- cancel('Canceled!');
455
- process.exit(0);
456
- }
457
- }
458
-
459
- const categories = (await gitProviders.getManifest(manifestUrl)).match(
460
- (val) => val,
461
- (err) => program.error(color.red(err))
462
- );
463
-
464
- for (const category of categories) {
465
- for (const block of category.blocks) {
466
- blocksMap.set(
467
- `${providerInfo.name}/${providerInfo.owner}/${providerInfo.repoName}/${category.name}/${block.name}`,
468
- {
469
- ...block,
470
- sourceRepo: providerInfo,
471
- }
472
- );
473
- }
474
- }
475
-
476
468
  block = blocksMap.get(blockSpecifier);
477
469
  }
478
470
 
@@ -486,7 +478,7 @@ const getBlocks = async (
486
478
 
487
479
  if (block.localDependencies && block.localDependencies.length > 0) {
488
480
  const subDeps = await getBlocks(
489
- block.localDependencies.filter((dep) => blocks.has(dep)),
481
+ block.localDependencies.filter((dep) => !blocks.has(dep)),
490
482
  blocksMap,
491
483
  repoPaths,
492
484
  options