@squidcloud/cli 1.0.340 → 1.0.341

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
@@ -981,13 +981,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
981
981
  };
982
982
  Object.defineProperty(exports, "__esModule", ({ value: true }));
983
983
  exports["default"] = default_1;
984
- const shell_runner_1 = __webpack_require__(5699);
985
984
  const fs = __importStar(__webpack_require__(1943));
986
985
  const process_utils_1 = __webpack_require__(8251);
987
986
  const resolve_1 = __webpack_require__(412);
988
987
  const path_1 = __importDefault(__webpack_require__(6928));
989
988
  const validate_1 = __webpack_require__(2246);
990
989
  const logging_1 = __webpack_require__(443);
990
+ const shell_runner_1 = __webpack_require__(3089);
991
991
  async function default_1() {
992
992
  const packageJson = await (0, validate_1.validateSquidProject)();
993
993
  console.log((0, logging_1.primary)('Please note:'), 'to debug your application, you need to run the "start" npm script in your IDE in debug mode');
@@ -2363,7 +2363,7 @@ const fs = __importStar(__webpack_require__(9896));
2363
2363
  const fsPromises = __importStar(__webpack_require__(1943));
2364
2364
  const path = __importStar(__webpack_require__(6928));
2365
2365
  const resolve_1 = __webpack_require__(412);
2366
- const shell_runner_1 = __webpack_require__(3344);
2366
+ const shell_runner_1 = __webpack_require__(3089);
2367
2367
  class TsoaUtils {
2368
2368
  constructor() { }
2369
2369
  static async generateAllSpecs(verbose = false, supportsDefault = true) {
@@ -2447,7 +2447,7 @@ class TsoaUtils {
2447
2447
  console.log(`Running: ${routesCmd}`);
2448
2448
  }
2449
2449
  try {
2450
- await Promise.all([(0, shell_runner_1.runInShell)(specCmd, process.cwd()), (0, shell_runner_1.runInShell)(routesCmd, process.cwd())]);
2450
+ await Promise.all([(0, shell_runner_1.runInShell)(specCmd, true, process.cwd()), (0, shell_runner_1.runInShell)(routesCmd, true, process.cwd())]);
2451
2451
  }
2452
2452
  catch (e) {
2453
2453
  const errorMessage = e?.stderr || e;
@@ -2470,9 +2470,10 @@ class TsoaUtils {
2470
2470
  const routesOutput = path.join(outputDir, 'routes.ts');
2471
2471
  try {
2472
2472
  const swaggerContent = await fsPromises.readFile(swaggerOutput, { encoding: 'utf8' });
2473
+ const modifiedSwaggerContent = await TsoaUtils.attachCodeSamples(swaggerContent);
2473
2474
  const routesContent = await fsPromises.readFile(routesOutput, { encoding: 'utf8' });
2474
2475
  specsMap[specName] = {
2475
- openApiSpecStr: swaggerContent,
2476
+ openApiSpecStr: modifiedSwaggerContent,
2476
2477
  openApiControllersStr: routesContent,
2477
2478
  };
2478
2479
  }
@@ -2509,6 +2510,85 @@ class TsoaUtils {
2509
2510
  return namePart || 'default';
2510
2511
  }
2511
2512
  }
2513
+ static async attachCodeSamples(swaggerContent) {
2514
+ const parsedSpec = JSON.parse(swaggerContent);
2515
+ const paths = parsedSpec.paths;
2516
+ for (const route in paths) {
2517
+ // renamed to avoid conflict with Node's "path" module
2518
+ const methods = paths[route];
2519
+ for (const method in methods) {
2520
+ const operation = methods[method];
2521
+ const originalDescription = operation['description'] || '';
2522
+ // Split description into individual lines
2523
+ const lines = originalDescription.split('\n');
2524
+ // Find lines that contain the directive
2525
+ const directiveLines = lines.filter(line => line.includes('--squidCodeSampleFile'));
2526
+ // Remove the directive lines from the description
2527
+ operation['description'] = lines
2528
+ .filter(line => !line.includes('--squidCodeSampleFile'))
2529
+ .join('\n')
2530
+ .trim();
2531
+ // Prepare an array to hold the code samples
2532
+ const codeSamples = [];
2533
+ for (const line of directiveLines) {
2534
+ // Find the directive in the line and extract the remainder
2535
+ const index = line.indexOf('--squidCodeSampleFile');
2536
+ const directiveContent = line.slice(index + '--squidCodeSampleFile'.length).trim();
2537
+ // Expecting format: "<file-path>,<label>"
2538
+ const parts = directiveContent.split(',').map(item => item.trim());
2539
+ if (parts.length < 2) {
2540
+ console.warn(`Directive format invalid: ${line}`);
2541
+ continue;
2542
+ }
2543
+ const [codeSampleFilePath, codeSampleLabel] = parts;
2544
+ // Determine language based on file extension
2545
+ let lang = 'Text';
2546
+ if (codeSampleFilePath.endsWith('.ts')) {
2547
+ lang = 'TypeScript';
2548
+ }
2549
+ else if (codeSampleFilePath.endsWith('.js')) {
2550
+ lang = 'JavaScript';
2551
+ }
2552
+ else if (codeSampleFilePath.endsWith('.py')) {
2553
+ lang = 'Python';
2554
+ }
2555
+ // Construct the full file path
2556
+ const fullCodeSamplePath = path.join(process.cwd(), codeSampleFilePath);
2557
+ let codeSampleContent;
2558
+ try {
2559
+ codeSampleContent = await fsPromises.readFile(fullCodeSamplePath, { encoding: 'utf8' });
2560
+ // Remove lines with '@ignore' and also remove the line immediately after each ignore line
2561
+ const codeLines = codeSampleContent.split('\n');
2562
+ const filteredLines = [];
2563
+ for (let i = 0; i < codeLines.length; i++) {
2564
+ if (codeLines[i].trim().includes('@ignore')) {
2565
+ // Skip this line and the next line
2566
+ i++;
2567
+ continue;
2568
+ }
2569
+ filteredLines.push(codeLines[i]);
2570
+ }
2571
+ codeSampleContent = filteredLines.join('\n').trim();
2572
+ }
2573
+ catch (e) {
2574
+ console.error(`Error reading code sample file ${codeSampleFilePath}:`, e);
2575
+ throw e;
2576
+ }
2577
+ // Add the code sample to the array
2578
+ codeSamples.push({
2579
+ lang,
2580
+ label: codeSampleLabel,
2581
+ source: codeSampleContent,
2582
+ });
2583
+ }
2584
+ // Attach the x-codeSamples entry if any directives were found
2585
+ if (codeSamples.length > 0) {
2586
+ operation['x-codeSamples'] = codeSamples;
2587
+ }
2588
+ }
2589
+ }
2590
+ return JSON.stringify(parsedSpec, null, 2);
2591
+ }
2512
2592
  }
2513
2593
  exports.TsoaUtils = TsoaUtils;
2514
2594
 
@@ -5869,7 +5949,7 @@ async function validateSquidProject() {
5869
5949
  const packageJson = await promises_1.default.readFile('package.json', 'utf8');
5870
5950
  const parsedJson = JSON.parse(packageJson);
5871
5951
  const { scripts } = parsedJson;
5872
- if (!scripts?.['start-squid'] && !scripts?.['start'].startsWith('squid start')) {
5952
+ if (!scripts?.['start-squid'] && !scripts?.['start'].includes('squid start')) {
5873
5953
  (0, process_utils_1.exitWithError)(exports.INVALID_PROJECT_ERROR);
5874
5954
  }
5875
5955
  return parsedJson;
@@ -8113,6 +8193,78 @@ async function reportLocalBackendInitialized(appId, apiKey, appRegion, verbose)
8113
8193
  }
8114
8194
 
8115
8195
 
8196
+ /***/ }),
8197
+
8198
+ /***/ 3089:
8199
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
8200
+
8201
+ "use strict";
8202
+
8203
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8204
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8205
+ };
8206
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
8207
+ exports.runInShell = runInShell;
8208
+ exports.printCombinedOutput = printCombinedOutput;
8209
+ const child_process_1 = __webpack_require__(5317);
8210
+ const process_1 = __importDefault(__webpack_require__(932));
8211
+ function runInShell(command, printMessages = true, cwd = process_1.default.cwd(), envVars) {
8212
+ return new Promise((resolve, reject) => {
8213
+ const execution = (0, child_process_1.spawn)(command, {
8214
+ cwd,
8215
+ shell: true,
8216
+ stdio: 'pipe',
8217
+ env: envVars ? { ...process_1.default.env, ...envVars } : undefined,
8218
+ });
8219
+ const combinedOutput = [];
8220
+ execution.stdout.on('data', data => {
8221
+ const str = data.toString();
8222
+ combinedOutput.push({ level: 'info', message: str });
8223
+ if (printMessages)
8224
+ stdoutLog(str);
8225
+ });
8226
+ execution.stderr.on('data', data => {
8227
+ const str = data.toString();
8228
+ combinedOutput.push({ level: 'error', message: str });
8229
+ if (printMessages)
8230
+ stderrLog(str);
8231
+ });
8232
+ execution.on('error', error => {
8233
+ reject(error);
8234
+ });
8235
+ execution.on('exit', code => {
8236
+ if (code === 0) {
8237
+ resolve({ combinedOutput });
8238
+ }
8239
+ else {
8240
+ const errorMessage = `The command exited with code ${code}`;
8241
+ if (printMessages) {
8242
+ printCombinedOutput(combinedOutput);
8243
+ }
8244
+ const processError = { errorMessage, combinedOutput };
8245
+ reject(processError);
8246
+ }
8247
+ });
8248
+ });
8249
+ }
8250
+ function printCombinedOutput(combinedOutput) {
8251
+ for (const line of combinedOutput) {
8252
+ if (line.level === 'error') {
8253
+ stderrLog(line.message);
8254
+ }
8255
+ else {
8256
+ stdoutLog(line.message);
8257
+ }
8258
+ }
8259
+ }
8260
+ function stdoutLog(message) {
8261
+ process_1.default.stdout.write(message);
8262
+ }
8263
+ function stderrLog(message) {
8264
+ process_1.default.stderr.write(message);
8265
+ }
8266
+
8267
+
8116
8268
  /***/ }),
8117
8269
 
8118
8270
  /***/ 3106:
@@ -8366,41 +8518,6 @@ module.exports = require("string_decoder");
8366
8518
  "use strict";
8367
8519
  module.exports = require("module");
8368
8520
 
8369
- /***/ }),
8370
-
8371
- /***/ 3344:
8372
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
8373
-
8374
- "use strict";
8375
-
8376
- Object.defineProperty(exports, "__esModule", ({ value: true }));
8377
- exports.runInShell = runInShell;
8378
- const child_process_1 = __webpack_require__(5317);
8379
- /** @internal */
8380
- function runInShell(command, cwd = process.cwd()) {
8381
- return new Promise((resolve, reject) => {
8382
- const process = (0, child_process_1.spawn)(command, { cwd, shell: true, stdio: 'pipe' });
8383
- let stdout = '';
8384
- let stderr = '';
8385
- process.stdout.on('data', data => {
8386
- stdout += data.toString();
8387
- });
8388
- process.stderr.on('data', data => {
8389
- stderr += data.toString();
8390
- });
8391
- process.on('error', error => reject(error));
8392
- process.on('exit', code => {
8393
- if (code === 0) {
8394
- resolve({ stdout, stderr });
8395
- }
8396
- else {
8397
- reject({ err: new Error(`The command exited with code ${code}`), stdout, stderr });
8398
- }
8399
- });
8400
- });
8401
- }
8402
-
8403
-
8404
8521
  /***/ }),
8405
8522
 
8406
8523
  /***/ 3367:
@@ -11757,12 +11874,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11757
11874
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11758
11875
  exports["default"] = initSample;
11759
11876
  const promises_1 = __importDefault(__webpack_require__(1943));
11760
- const shell_runner_1 = __webpack_require__(5699);
11761
11877
  const path_1 = __importDefault(__webpack_require__(6928));
11762
11878
  const report_utils_1 = __webpack_require__(3066);
11763
11879
  const process_utils_1 = __webpack_require__(8251);
11764
11880
  const git_utils_1 = __webpack_require__(954);
11765
11881
  const logging_1 = __webpack_require__(443);
11882
+ const shell_runner_1 = __webpack_require__(3089);
11766
11883
  const ORG = 'squid-cloud-samples';
11767
11884
  async function initSample(dirPath, appId, apiKey, environmentId, squidDeveloperId, region, templateName, verbose = false) {
11768
11885
  try {
@@ -15722,69 +15839,6 @@ module.exports = () => input => {
15722
15839
  };
15723
15840
 
15724
15841
 
15725
- /***/ }),
15726
-
15727
- /***/ 5699:
15728
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
15729
-
15730
- "use strict";
15731
-
15732
- Object.defineProperty(exports, "__esModule", ({ value: true }));
15733
- exports.runInShell = runInShell;
15734
- exports.printCombinedOutput = printCombinedOutput;
15735
- const child_process_1 = __webpack_require__(5317);
15736
- function runInShell(command, printMessages = true, cwd = process.cwd()) {
15737
- return new Promise((resolve, reject) => {
15738
- const process = (0, child_process_1.spawn)(command, { cwd, shell: true, stdio: 'pipe' });
15739
- const combinedOutput = [];
15740
- process.stdout.on('data', data => {
15741
- const str = data.toString();
15742
- combinedOutput.push({ level: 'info', message: str });
15743
- if (printMessages)
15744
- stdoutLog(str);
15745
- });
15746
- process.stderr.on('data', data => {
15747
- const str = data.toString();
15748
- combinedOutput.push({ level: 'error', message: str });
15749
- if (printMessages)
15750
- stderrLog(str);
15751
- });
15752
- process.on('error', error => {
15753
- reject(error);
15754
- });
15755
- process.on('exit', code => {
15756
- if (code === 0) {
15757
- resolve({ combinedOutput });
15758
- }
15759
- else {
15760
- const errorMessage = `The command exited with code ${code}`;
15761
- if (printMessages) {
15762
- printCombinedOutput(combinedOutput);
15763
- }
15764
- const processError = { errorMessage, combinedOutput };
15765
- reject(processError);
15766
- }
15767
- });
15768
- });
15769
- }
15770
- function printCombinedOutput(combinedOutput) {
15771
- for (const line of combinedOutput) {
15772
- if (line.level === 'error') {
15773
- stderrLog(line.message);
15774
- }
15775
- else {
15776
- stdoutLog(line.message);
15777
- }
15778
- }
15779
- }
15780
- function stdoutLog(message) {
15781
- process.stdout.write(message);
15782
- }
15783
- function stderrLog(message) {
15784
- process.stderr.write(message);
15785
- }
15786
-
15787
-
15788
15842
  /***/ }),
15789
15843
 
15790
15844
  /***/ 5704:
@@ -22712,7 +22766,7 @@ function exitWithError(...messages) {
22712
22766
  /***/ ((module) => {
22713
22767
 
22714
22768
  "use strict";
22715
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@squidcloud/cli","version":"1.0.340","description":"The Squid CLI","main":"dist/index.js","scripts":{"start":"node dist/index.js","start-ts":"ts-node -r tsconfig-paths/register src/index.ts","prebuild":"rimraf dist","build":"webpack --mode=production","build:dev":"webpack --mode=development","build:prod":"webpack --mode=production","lint":"eslint","link":"npm run build && chmod 755 dist/index.js && npm link","watch":"webpack --watch","deploy":"npm run build && npm pack --silent | xargs -I {} mv {} package.tgz && npm install -g package.tgz && rm -rf package.tgz","publish:public":"npm run build && npm publish --access public"},"files":["dist/**/*"],"bin":{"squid":"dist/index.js"},"keywords":[],"author":"","license":"ISC","engines":{"node":">=18.0.0"},"dependencies":{"@squidcloud/local-backend":"^1.0.340","copy-webpack-plugin":"^12.0.2","decompress":"^4.2.1","nodemon":"^3.1.3","terser-webpack-plugin":"^5.3.10","ts-loader":"^9.5.1","ts-node":"^10.9.2","tsconfig-paths":"^4.2.0","tsconfig-paths-webpack-plugin":"^4.1.0","webpack":"^5.96.0","zip-webpack-plugin":"^4.0.1"},"devDependencies":{"@types/decompress":"^4.2.7","@types/node":"^20.16.10","terminal-link":"^3.0.0"}}');
22769
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@squidcloud/cli","version":"1.0.341","description":"The Squid CLI","main":"dist/index.js","scripts":{"start":"node dist/index.js","start-ts":"ts-node -r tsconfig-paths/register src/index.ts","prebuild":"rimraf dist","build":"webpack --mode=production","build:dev":"webpack --mode=development","build:prod":"webpack --mode=production","lint":"eslint","link":"npm run build && chmod 755 dist/index.js && npm link","watch":"webpack --watch","deploy":"npm run build && npm pack --silent | xargs -I {} mv {} package.tgz && npm install -g package.tgz && rm -rf package.tgz","publish:public":"npm run build && npm publish --access public"},"files":["dist/**/*"],"bin":{"squid":"dist/index.js"},"keywords":[],"author":"","license":"ISC","engines":{"node":">=18.0.0"},"dependencies":{"@squidcloud/local-backend":"^1.0.341","copy-webpack-plugin":"^12.0.2","decompress":"^4.2.1","nodemon":"^3.1.3","terser-webpack-plugin":"^5.3.10","ts-loader":"^9.5.1","ts-node":"^10.9.2","tsconfig-paths":"^4.2.0","tsconfig-paths-webpack-plugin":"^4.1.0","webpack":"^5.96.0","zip-webpack-plugin":"^4.0.1"},"devDependencies":{"@types/decompress":"^4.2.7","@types/node":"^20.16.10","terminal-link":"^3.0.0"}}');
22716
22770
 
22717
22771
  /***/ }),
22718
22772
 
@@ -23566,12 +23620,12 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
23566
23620
  exports["default"] = default_1;
23567
23621
  const environment_1 = __webpack_require__(722);
23568
23622
  const process_utils_1 = __webpack_require__(8251);
23569
- const shell_runner_1 = __webpack_require__(5699);
23570
23623
  const fs = __importStar(__webpack_require__(1943));
23571
23624
  const http_1 = __webpack_require__(866);
23572
23625
  const communication_types_1 = __webpack_require__(3443);
23573
23626
  const console_app_utils_1 = __webpack_require__(7580);
23574
23627
  const assertic_1 = __webpack_require__(5036);
23628
+ const shell_runner_1 = __webpack_require__(3089);
23575
23629
  async function default_1(stage, appId, bundlePath, apiKey, verbose, direct, isUserSpecifiedPath, skipBuild, internalApiKey, environmentId) {
23576
23630
  if (!direct && !isUserSpecifiedPath && !skipBuild) {
23577
23631
  console.log('Building code bundle...');
@@ -6,7 +6,7 @@ export interface ProcessError {
6
6
  errorMessage: string;
7
7
  combinedOutput: Array<ErrorLine>;
8
8
  }
9
- export declare function runInShell(command: string, printMessages?: boolean, cwd?: string): Promise<{
9
+ export declare function runInShell(command: string, printMessages?: boolean, cwd?: string, envVars?: Record<string, string>): Promise<{
10
10
  combinedOutput: Array<ErrorLine>;
11
11
  }>;
12
12
  export declare function printCombinedOutput(combinedOutput: Array<ErrorLine>): void;
@@ -6,4 +6,5 @@ export declare class TsoaUtils {
6
6
  constructor();
7
7
  static generateAllSpecs(verbose?: boolean, supportsDefault?: boolean): Promise<OpenApiSpecAndControllers>;
8
8
  private static extractTsoaName;
9
+ private static attachCodeSamples;
9
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/cli",
3
- "version": "1.0.340",
3
+ "version": "1.0.341",
4
4
  "description": "The Squid CLI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "node": ">=18.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@squidcloud/local-backend": "^1.0.340",
32
+ "@squidcloud/local-backend": "^1.0.341",
33
33
  "copy-webpack-plugin": "^12.0.2",
34
34
  "decompress": "^4.2.1",
35
35
  "nodemon": "^3.1.3",
@@ -1,5 +0,0 @@
1
- /** @internal */
2
- export declare function runInShell(command: string, cwd?: string): Promise<{
3
- stdout: string;
4
- stderr: string;
5
- }>;