@canva/cli 1.7.0 → 1.9.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/cli.js +455 -555
  4. package/lib/cjs/index.cjs +6 -6
  5. package/lib/esm/index.mjs +6 -6
  6. package/package.json +1 -1
  7. package/templates/base/backend/database/database.ts +2 -2
  8. package/templates/base/backend/routers/auth.ts +5 -5
  9. package/templates/base/backend/routers/oauth.ts +4 -4
  10. package/templates/base/package.json +1 -1
  11. package/templates/base/scripts/copy_env.ts +6 -3
  12. package/templates/base/scripts/ssl/ssl.ts +3 -3
  13. package/templates/base/scripts/start/app_runner.ts +29 -7
  14. package/templates/base/scripts/start/context.ts +2 -2
  15. package/templates/base/scripts/start/start.ts +1 -1
  16. package/templates/base/scripts/start.tests.ts +1 -1
  17. package/templates/base/tsconfig.json +2 -1
  18. package/templates/base/utils/backend/base_backend/create.ts +4 -4
  19. package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +1 -1
  20. package/templates/base/utils/backend/jwt_middleware/jwt_middleware.ts +3 -6
  21. package/templates/base/webpack.config.ts +3 -3
  22. package/templates/common/utils/backend/base_backend/create.ts +4 -4
  23. package/templates/common/utils/backend/jwt_middleware/jwt_middleware.ts +3 -6
  24. package/templates/dam/backend/routers/dam.ts +2 -2
  25. package/templates/dam/backend/server.ts +2 -2
  26. package/templates/dam/package.json +1 -1
  27. package/templates/dam/scripts/copy_env.ts +6 -3
  28. package/templates/dam/scripts/ssl/ssl.ts +3 -3
  29. package/templates/dam/scripts/start/app_runner.ts +29 -7
  30. package/templates/dam/scripts/start/context.ts +2 -2
  31. package/templates/dam/scripts/start/start.ts +1 -1
  32. package/templates/dam/tsconfig.json +2 -1
  33. package/templates/dam/utils/backend/base_backend/create.ts +4 -4
  34. package/templates/dam/utils/backend/jwt_middleware/jwt_middleware.ts +3 -6
  35. package/templates/dam/webpack.config.ts +3 -3
  36. package/templates/data_connector/package.json +1 -1
  37. package/templates/data_connector/scripts/copy_env.ts +6 -3
  38. package/templates/data_connector/scripts/ssl/ssl.ts +3 -3
  39. package/templates/data_connector/scripts/start/app_runner.ts +29 -7
  40. package/templates/data_connector/scripts/start/context.ts +2 -2
  41. package/templates/data_connector/scripts/start/start.ts +1 -1
  42. package/templates/data_connector/tsconfig.json +2 -1
  43. package/templates/data_connector/webpack.config.ts +3 -3
  44. package/templates/gen_ai/backend/database/database.ts +2 -2
  45. package/templates/gen_ai/backend/routers/image.ts +1 -1
  46. package/templates/gen_ai/backend/server.ts +2 -2
  47. package/templates/gen_ai/package.json +1 -1
  48. package/templates/gen_ai/scripts/copy_env.ts +6 -3
  49. package/templates/gen_ai/scripts/ssl/ssl.ts +3 -3
  50. package/templates/gen_ai/scripts/start/app_runner.ts +29 -7
  51. package/templates/gen_ai/scripts/start/context.ts +2 -2
  52. package/templates/gen_ai/scripts/start/start.ts +1 -1
  53. package/templates/gen_ai/tsconfig.json +2 -1
  54. package/templates/gen_ai/utils/backend/base_backend/create.ts +4 -4
  55. package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +1 -1
  56. package/templates/gen_ai/webpack.config.ts +3 -3
  57. package/templates/hello_world/package.json +1 -1
  58. package/templates/hello_world/scripts/copy_env.ts +6 -3
  59. package/templates/hello_world/scripts/ssl/ssl.ts +3 -3
  60. package/templates/hello_world/scripts/start/app_runner.ts +29 -7
  61. package/templates/hello_world/scripts/start/context.ts +2 -2
  62. package/templates/hello_world/scripts/start/start.ts +1 -1
  63. package/templates/hello_world/tsconfig.json +2 -1
  64. package/templates/hello_world/webpack.config.ts +3 -3
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import * as fs from "fs";
3
- import * as path from "path";
2
+ /* eslint-disable no-console */
3
+ import fs from "fs";
4
+ import path from "path";
4
5
 
5
6
  const envPath = path.resolve(__dirname, "..", ".env");
6
7
  const templatePath = path.resolve(__dirname, "..", ".env.template");
7
8
 
8
- if (!fs.existsSync(envPath)) {
9
+ if (!fs.existsSync(templatePath)) {
10
+ console.warn(".env.template file does not exist, skipping copy of .env file");
11
+ } else if (!fs.existsSync(envPath)) {
9
12
  fs.copyFileSync(templatePath, envPath);
10
13
  }
@@ -1,7 +1,7 @@
1
- import * as crypto from "crypto";
2
- import * as fs from "fs/promises";
1
+ import crypto from "crypto";
2
+ import fs from "fs/promises";
3
3
  import { pki } from "node-forge";
4
- import * as path from "path";
4
+ import path from "path";
5
5
 
6
6
  const SSL_CERT_DIR = path.resolve(process.cwd(), "..", "..", ".ssl");
7
7
  const CERT_FILE = path.resolve(SSL_CERT_DIR, "certificate.pem");
@@ -1,12 +1,13 @@
1
1
  /* eslint-disable no-console */
2
2
  import { generatePreviewUrl } from "@canva/cli";
3
- import * as ngrok from "@ngrok/ngrok";
4
- import * as chalk from "chalk";
5
- import * as Table from "cli-table3";
6
- import * as nodemon from "nodemon";
3
+ import ngrok from "@ngrok/ngrok";
4
+ import chalk from "chalk";
5
+ import Table from "cli-table3";
6
+ import nodemon from "nodemon";
7
7
  import open from "open";
8
- import * as webpack from "webpack";
9
- import * as WebpackDevServer from "webpack-dev-server";
8
+ import os from "os";
9
+ import webpack from "webpack";
10
+ import WebpackDevServer from "webpack-dev-server";
10
11
  import { buildConfig } from "../../webpack.config";
11
12
  import type { Certificate } from "../ssl/ssl";
12
13
  import { createOrRetrieveCertificate } from "../ssl/ssl";
@@ -18,6 +19,22 @@ export const errorChalk = chalk.bgRed.bold;
18
19
  export const highlightChalk = chalk.greenBright.bold;
19
20
  export const linkChalk = chalk.cyan;
20
21
 
22
+ /**
23
+ * Returns the appropriate modifier key text based on the user's operating system.
24
+ * @returns "cmd" for macOS, "ctrl" for Windows and Linux
25
+ */
26
+ export function getModifierKey(): string {
27
+ const platform = os.platform();
28
+ switch (platform) {
29
+ case "darwin": // macOS
30
+ return "cmd";
31
+ case "win32": // Windows
32
+ return "ctrl";
33
+ default: // Linux and others
34
+ return "ctrl";
35
+ }
36
+ }
37
+
21
38
  export class AppRunner {
22
39
  async run(ctx: Context) {
23
40
  console.log(
@@ -189,9 +206,14 @@ export class AppRunner {
189
206
  return;
190
207
  }
191
208
 
209
+ const modifierKey = getModifierKey();
210
+
192
211
  table.push([
193
212
  previewCellHeader,
194
- { content: "Preview URL", href: generatePreviewResult.data },
213
+ {
214
+ content: `Preview URL (${modifierKey} + click)`,
215
+ href: generatePreviewResult.data,
216
+ },
195
217
  ]);
196
218
 
197
219
  if (openPreview) {
@@ -1,5 +1,5 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
1
+ import fs from "fs";
2
+ import path from "path";
3
3
 
4
4
  interface CliArgs {
5
5
  example?: string;
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import * as yargs from "yargs";
2
+ import yargs from "yargs";
3
3
  import { hideBin } from "yargs/helpers";
4
4
  import { AppRunner } from "./app_runner";
5
5
  import { Context } from "./context";
@@ -18,7 +18,8 @@
18
18
  "experimentalDecorators": true,
19
19
  "importHelpers": true,
20
20
  "noImplicitOverride": true,
21
- "moduleResolution": "node",
21
+ "moduleResolution": "bundler",
22
+ "esModuleInterop": true,
22
23
  "rootDir": ".",
23
24
  "outDir": "dist",
24
25
  "strict": true,
@@ -1,9 +1,9 @@
1
1
  import type { Configuration } from "webpack";
2
2
  import { DefinePlugin, optimize } from "webpack";
3
- import * as path from "path";
4
- import * as TerserPlugin from "terser-webpack-plugin";
3
+ import path from "path";
4
+ import TerserPlugin from "terser-webpack-plugin";
5
5
  import { transform } from "@formatjs/ts-transformer";
6
- import * as chalk from "chalk";
6
+ import chalk from "chalk";
7
7
  import { config } from "dotenv";
8
8
  import { Configuration as DevServerConfiguration } from "webpack-dev-server";
9
9