@canva/cli 0.0.1-beta.3 → 0.0.1-beta.31
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 +218 -104
- package/cli.js +661 -394
- package/lib/cjs/index.cjs +5 -0
- package/lib/esm/index.mjs +5 -0
- package/package.json +19 -4
- package/templates/base/eslint.config.mjs +2 -27
- package/templates/base/package.json +31 -25
- package/templates/base/scripts/copy_env.ts +10 -0
- package/templates/base/scripts/start/app_runner.ts +39 -2
- package/templates/base/scripts/start/context.ts +12 -6
- package/templates/base/scripts/start/start.ts +11 -0
- package/templates/base/scripts/start/tests/start.tests.ts +61 -0
- package/templates/base/{webpack.config.cjs → webpack.config.ts} +46 -46
- package/templates/common/.cursor/mcp.json +8 -0
- package/templates/common/.gitignore.template +5 -6
- package/templates/common/.nvmrc +1 -0
- package/templates/common/.prettierrc +21 -0
- package/templates/common/.vscode/extensions.json +6 -0
- package/templates/common/.vscode/mcp.json +9 -0
- package/templates/common/README.md +4 -7
- package/templates/common/jest.config.mjs +29 -2
- package/templates/common/jest.setup.ts +20 -0
- package/templates/common/utils/backend/base_backend/create.ts +104 -0
- package/templates/common/utils/backend/jwt_middleware/index.ts +1 -0
- package/templates/common/utils/backend/jwt_middleware/jwt_middleware.ts +229 -0
- package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +630 -0
- package/templates/common/utils/table_wrapper.ts +477 -0
- package/templates/common/utils/tests/table_wrapper.tests.ts +252 -0
- package/templates/common/utils/use_add_element.ts +48 -0
- package/templates/common/utils/use_feature_support.ts +28 -0
- package/templates/common/utils/use_overlay_hook.ts +74 -0
- package/templates/common/utils/use_selection_hook.ts +37 -0
- package/templates/dam/backend/routers/dam.ts +23 -19
- package/templates/dam/eslint.config.mjs +2 -28
- package/templates/dam/package.json +43 -39
- package/templates/dam/scripts/copy_env.ts +10 -0
- package/templates/dam/scripts/start/app_runner.ts +39 -2
- package/templates/dam/scripts/start/context.ts +12 -6
- package/templates/dam/scripts/start/start.ts +11 -0
- package/templates/dam/scripts/start/tests/start.tests.ts +61 -0
- package/templates/dam/src/app.tsx +24 -3
- package/templates/dam/src/config.ts +212 -87
- package/templates/{hello_world/webpack.config.cjs → dam/webpack.config.ts} +46 -46
- package/templates/data_connector/README.md +84 -0
- package/templates/data_connector/declarations/declarations.d.ts +29 -0
- package/templates/data_connector/eslint.config.mjs +14 -0
- package/templates/data_connector/package.json +91 -0
- package/templates/data_connector/scripts/copy_env.ts +10 -0
- package/templates/data_connector/scripts/ssl/ssl.ts +131 -0
- package/templates/data_connector/scripts/start/app_runner.ts +201 -0
- package/templates/data_connector/scripts/start/context.ts +171 -0
- package/templates/data_connector/scripts/start/start.ts +46 -0
- package/templates/data_connector/scripts/start/tests/start.tests.ts +61 -0
- package/templates/data_connector/src/api/connect_client.ts +6 -0
- package/templates/data_connector/src/api/data_source.ts +96 -0
- package/templates/data_connector/src/api/data_sources/designs.tsx +296 -0
- package/templates/data_connector/src/api/data_sources/index.ts +4 -0
- package/templates/data_connector/src/api/data_sources/templates.tsx +329 -0
- package/templates/data_connector/src/api/fetch_data_table.ts +55 -0
- package/templates/data_connector/src/api/index.ts +4 -0
- package/templates/data_connector/src/api/oauth.ts +8 -0
- package/templates/data_connector/src/api/tests/data_source.test.tsx +99 -0
- package/templates/data_connector/src/app.tsx +20 -0
- package/templates/data_connector/src/components/app_error.tsx +15 -0
- package/templates/data_connector/src/components/footer.tsx +26 -0
- package/templates/data_connector/src/components/header.tsx +40 -0
- package/templates/data_connector/src/components/index.ts +3 -0
- package/templates/data_connector/src/components/inputs/messages.tsx +99 -0
- package/templates/data_connector/src/components/inputs/search_filter.tsx +108 -0
- package/templates/data_connector/src/components/inputs/select_field.tsx +26 -0
- package/templates/data_connector/src/context/app_context.tsx +124 -0
- package/templates/data_connector/src/context/index.ts +2 -0
- package/templates/data_connector/src/context/use_app_context.ts +17 -0
- package/templates/data_connector/src/entrypoint.tsx +70 -0
- package/templates/data_connector/src/home.tsx +21 -0
- package/templates/data_connector/src/index.tsx +69 -0
- package/templates/data_connector/src/pages/data_source_config.tsx +9 -0
- package/templates/data_connector/src/pages/error.tsx +37 -0
- package/templates/data_connector/src/pages/index.ts +4 -0
- package/templates/data_connector/src/pages/login.tsx +145 -0
- package/templates/data_connector/src/pages/select_source.tsx +24 -0
- package/templates/data_connector/src/routes/index.ts +2 -0
- package/templates/data_connector/src/routes/protected_route.tsx +25 -0
- package/templates/data_connector/src/routes/routes.tsx +46 -0
- package/templates/data_connector/src/utils/data_params.ts +17 -0
- package/templates/data_connector/src/utils/data_table.ts +115 -0
- package/templates/data_connector/src/utils/fetch_result.ts +36 -0
- package/templates/data_connector/src/utils/index.ts +2 -0
- package/templates/data_connector/src/utils/tests/data_table.test.ts +133 -0
- package/templates/data_connector/styles/components.css +38 -0
- package/templates/data_connector/tsconfig.json +54 -0
- package/templates/{gen_ai/webpack.config.cjs → data_connector/webpack.config.ts} +46 -46
- package/templates/gen_ai/README.md +1 -40
- package/templates/gen_ai/backend/routers/image.ts +11 -11
- package/templates/gen_ai/backend/server.ts +0 -7
- package/templates/gen_ai/eslint.config.mjs +2 -27
- package/templates/gen_ai/package.json +48 -42
- package/templates/gen_ai/scripts/copy_env.ts +10 -0
- package/templates/gen_ai/scripts/start/app_runner.ts +39 -2
- package/templates/gen_ai/scripts/start/context.ts +12 -6
- package/templates/gen_ai/scripts/start/start.ts +11 -0
- package/templates/gen_ai/scripts/start/tests/start.tests.ts +61 -0
- package/templates/gen_ai/src/api/api.ts +24 -79
- package/templates/gen_ai/src/app.tsx +16 -10
- package/templates/gen_ai/src/components/footer.messages.ts +0 -5
- package/templates/gen_ai/src/components/footer.tsx +7 -25
- package/templates/gen_ai/src/components/index.ts +0 -1
- package/templates/gen_ai/src/components/loading_results.tsx +4 -8
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +43 -0
- package/templates/gen_ai/src/context/app_context.tsx +5 -33
- package/templates/gen_ai/src/context/context.messages.ts +1 -12
- package/templates/gen_ai/src/home.tsx +13 -0
- package/templates/gen_ai/src/index.tsx +2 -18
- package/templates/gen_ai/src/routes/routes.tsx +2 -2
- package/templates/{dam/webpack.config.cjs → gen_ai/webpack.config.ts} +46 -46
- package/templates/hello_world/eslint.config.mjs +2 -27
- package/templates/hello_world/package.json +47 -34
- package/templates/hello_world/scripts/copy_env.ts +10 -0
- package/templates/hello_world/scripts/start/app_runner.ts +39 -2
- package/templates/hello_world/scripts/start/context.ts +12 -6
- package/templates/hello_world/scripts/start/start.ts +11 -0
- package/templates/hello_world/scripts/start/tests/start.tests.ts +61 -0
- package/templates/hello_world/src/app.tsx +20 -0
- package/templates/hello_world/src/tests/__snapshots__/app.tests.tsx.snap +45 -0
- package/templates/hello_world/src/tests/app.tests.tsx +86 -0
- package/templates/hello_world/webpack.config.ts +270 -0
- package/templates/common/conf/eslint-general.mjs +0 -277
- package/templates/common/conf/eslint-i18n.mjs +0 -23
- package/templates/gen_ai/backend/routers/oauth.ts +0 -393
- package/templates/gen_ai/src/components/logged_in_status.tsx +0 -44
- package/templates/gen_ai/src/services/auth.tsx +0 -26
- package/templates/gen_ai/src/services/index.ts +0 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"name": "digital_asset_management",
|
|
4
4
|
"description": "An example app leveraging @canva/app-components to develop a digital asset management (DAM) app.",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"extract": "formatjs extract
|
|
7
|
-
"build": "webpack --config webpack.config.
|
|
6
|
+
"extract": "formatjs extract \"src/**/*.{ts,tsx}\" --out-file dist/messages_en.json",
|
|
7
|
+
"build": "webpack --config webpack.config.ts --mode production && npm run extract",
|
|
8
8
|
"format": "prettier '**/*.{css,ts,tsx}' --no-config --write",
|
|
9
9
|
"format:check": "prettier '**/*.{css,ts,tsx}' --no-config --check --ignore-path",
|
|
10
10
|
"format:file": "prettier $1 --no-config --write",
|
|
@@ -12,80 +12,84 @@
|
|
|
12
12
|
"lint:fix": "eslint . --fix",
|
|
13
13
|
"lint:types": "tsc",
|
|
14
14
|
"start": "ts-node ./scripts/start/start.ts",
|
|
15
|
+
"start:preview": "npm run start -- --preview",
|
|
15
16
|
"test": "jest --no-cache",
|
|
16
|
-
"test:watch": "jest --watchAll"
|
|
17
|
+
"test:watch": "jest --watchAll",
|
|
18
|
+
"postinstall": "ts-node ./scripts/copy_env.ts"
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|
|
19
|
-
"@canva/app-components": "^1.
|
|
20
|
-
"@canva/app-i18n-kit": "^
|
|
21
|
-
"@canva/app-ui-kit": "^4.
|
|
22
|
-
"@canva/asset": "^2.
|
|
23
|
-
"@canva/design": "^2.1
|
|
24
|
-
"@canva/
|
|
25
|
-
"@canva/
|
|
26
|
-
"
|
|
21
|
+
"@canva/app-components": "^1.3.0",
|
|
22
|
+
"@canva/app-i18n-kit": "^1.0.2",
|
|
23
|
+
"@canva/app-ui-kit": "^4.9.0",
|
|
24
|
+
"@canva/asset": "^2.2.0",
|
|
25
|
+
"@canva/design": "^2.4.1",
|
|
26
|
+
"@canva/error": "^2.1.0",
|
|
27
|
+
"@canva/platform": "^2.1.0",
|
|
28
|
+
"@canva/user": "^2.1.0",
|
|
29
|
+
"cookie-parser": "1.4.7",
|
|
27
30
|
"cors": "2.8.5",
|
|
28
31
|
"react": "18.3.1",
|
|
29
32
|
"react-dom": "18.3.1",
|
|
30
|
-
"react-intl": "6.
|
|
33
|
+
"react-intl": "6.8.7"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@eslint
|
|
34
|
-
"@
|
|
35
|
-
"@formatjs/cli": "6.
|
|
36
|
-
"@formatjs/ts-transformer": "3.13.
|
|
36
|
+
"@canva/app-eslint-plugin": "^1.0.0-beta.3",
|
|
37
|
+
"@canva/cli": ">= 0.0.1-beta.13 < 0.0.2",
|
|
38
|
+
"@formatjs/cli": "6.3.15",
|
|
39
|
+
"@formatjs/ts-transformer": "3.13.27",
|
|
37
40
|
"@ngrok/ngrok": "1.4.1",
|
|
41
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
|
|
38
42
|
"@svgr/webpack": "8.1.0",
|
|
43
|
+
"@testing-library/react": "16.1.0",
|
|
39
44
|
"@types/cors": "2.8.17",
|
|
40
45
|
"@types/debug": "4.1.12",
|
|
41
46
|
"@types/express": "4.17.21",
|
|
42
|
-
"@types/express-serve-static-core": "4.19.
|
|
43
|
-
"@types/jest": "29.5.
|
|
44
|
-
"@types/jsonwebtoken": "9.0.
|
|
47
|
+
"@types/express-serve-static-core": "4.19.6",
|
|
48
|
+
"@types/jest": "29.5.14",
|
|
49
|
+
"@types/jsonwebtoken": "9.0.7",
|
|
45
50
|
"@types/node": "20.10.0",
|
|
46
|
-
"@types/node-fetch": "2.6.
|
|
51
|
+
"@types/node-fetch": "2.6.12",
|
|
47
52
|
"@types/node-forge": "1.3.11",
|
|
48
53
|
"@types/nodemon": "1.19.6",
|
|
49
54
|
"@types/prompts": "2.4.9",
|
|
50
|
-
"@types/react": "18.3.
|
|
51
|
-
"@types/react-dom": "18.3.
|
|
55
|
+
"@types/react": "18.3.12",
|
|
56
|
+
"@types/react-dom": "18.3.1",
|
|
52
57
|
"@types/webpack-env": "1.18.5",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "8.2.0",
|
|
54
|
-
"@typescript-eslint/parser": "8.2.0",
|
|
55
58
|
"chalk": "4.1.2",
|
|
56
59
|
"cli-table3": "0.6.5",
|
|
57
60
|
"css-loader": "7.1.2",
|
|
58
61
|
"css-modules-typescript-loader": "4.0.1",
|
|
59
|
-
"cssnano": "7.0.
|
|
60
|
-
"debug": "4.
|
|
61
|
-
"dotenv": "16.4.
|
|
62
|
-
"eslint": "8.57.1",
|
|
63
|
-
"eslint-plugin-formatjs": "4.13.3",
|
|
64
|
-
"eslint-plugin-jest": "28.8.0",
|
|
65
|
-
"eslint-plugin-react": "7.35.0",
|
|
62
|
+
"cssnano": "7.0.6",
|
|
63
|
+
"debug": "4.4.0",
|
|
64
|
+
"dotenv": "16.4.7",
|
|
66
65
|
"exponential-backoff": "3.1.1",
|
|
67
|
-
"express": "4.
|
|
66
|
+
"express": "4.21.2",
|
|
68
67
|
"express-basic-auth": "1.2.1",
|
|
69
68
|
"jest": "29.7.0",
|
|
69
|
+
"jest-css-modules-transform": "4.4.2",
|
|
70
|
+
"jest-environment-jsdom": "29.7.0",
|
|
70
71
|
"jsonwebtoken": "9.0.2",
|
|
71
72
|
"jwks-rsa": "3.1.0",
|
|
72
|
-
"mini-css-extract-plugin": "2.9.
|
|
73
|
+
"mini-css-extract-plugin": "2.9.2",
|
|
73
74
|
"node-fetch": "3.3.2",
|
|
74
75
|
"node-forge": "1.3.1",
|
|
75
76
|
"nodemon": "3.0.1",
|
|
77
|
+
"open": "8.4.2",
|
|
76
78
|
"postcss-loader": "8.1.1",
|
|
77
|
-
"prettier": "3.
|
|
79
|
+
"prettier": "3.4.2",
|
|
78
80
|
"prompts": "2.4.2",
|
|
81
|
+
"react-refresh": "0.16.0",
|
|
79
82
|
"style-loader": "4.0.0",
|
|
80
|
-
"terser-webpack-plugin": "5.3.
|
|
81
|
-
"
|
|
82
|
-
"ts-
|
|
83
|
+
"terser-webpack-plugin": "5.3.11",
|
|
84
|
+
"tree-kill": "1.2.2",
|
|
85
|
+
"ts-jest": "29.2.5",
|
|
86
|
+
"ts-loader": "9.5.2",
|
|
83
87
|
"ts-node": "10.9.2",
|
|
84
88
|
"typescript": "5.5.4",
|
|
85
89
|
"url-loader": "4.1.1",
|
|
86
|
-
"webpack": "5.
|
|
90
|
+
"webpack": "5.97.1",
|
|
87
91
|
"webpack-cli": "5.1.4",
|
|
88
|
-
"webpack-dev-server": "5.0
|
|
92
|
+
"webpack-dev-server": "5.2.0",
|
|
89
93
|
"yargs": "17.7.2"
|
|
90
94
|
}
|
|
91
95
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
|
|
5
|
+
const envPath = path.resolve(__dirname, "..", ".env");
|
|
6
|
+
const templatePath = path.resolve(__dirname, "..", ".env.template");
|
|
7
|
+
|
|
8
|
+
if (!fs.existsSync(envPath)) {
|
|
9
|
+
fs.copyFileSync(templatePath, envPath);
|
|
10
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import type { Context } from "./context";
|
|
3
3
|
import * as chalk from "chalk";
|
|
4
|
-
import { buildConfig } from "../../webpack.config
|
|
4
|
+
import { buildConfig } from "../../webpack.config";
|
|
5
5
|
import * as ngrok from "@ngrok/ngrok";
|
|
6
6
|
import * as nodemon from "nodemon";
|
|
7
7
|
import * as Table from "cli-table3";
|
|
8
8
|
import * as webpack from "webpack";
|
|
9
9
|
import * as WebpackDevServer from "webpack-dev-server";
|
|
10
|
+
import * as open from "open";
|
|
11
|
+
import { generatePreviewUrl } from "@canva/cli";
|
|
10
12
|
import type { Certificate } from "../ssl/ssl";
|
|
11
13
|
import { createOrRetrieveCertificate } from "../ssl/ssl";
|
|
12
14
|
|
|
@@ -46,12 +48,18 @@ export class AppRunner {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
const table = new Table(
|
|
51
|
+
const table = new Table({
|
|
52
|
+
colWidths: [30, 80],
|
|
53
|
+
wordWrap: true,
|
|
54
|
+
wrapOnWordBoundary: true,
|
|
55
|
+
});
|
|
50
56
|
|
|
51
57
|
const server = await this.runWebpackDevServer(ctx, table, cert);
|
|
52
58
|
|
|
53
59
|
await this.maybeRunBackendServer(ctx, table, cert, server);
|
|
54
60
|
|
|
61
|
+
await this.generateAndOpenPreviewUrl(ctx.openPreview, table);
|
|
62
|
+
|
|
55
63
|
console.log(table.toString(), "\n");
|
|
56
64
|
|
|
57
65
|
console.log(
|
|
@@ -161,4 +169,33 @@ export class AppRunner {
|
|
|
161
169
|
|
|
162
170
|
return server;
|
|
163
171
|
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Calls the Canva CLI to generate a preview URL for the app
|
|
175
|
+
*/
|
|
176
|
+
private readonly generateAndOpenPreviewUrl = async (
|
|
177
|
+
openPreview: boolean,
|
|
178
|
+
table: Table.Table,
|
|
179
|
+
) => {
|
|
180
|
+
const previewCellHeader = { content: "Preview your app in Canva" };
|
|
181
|
+
|
|
182
|
+
const generatePreviewResult = await generatePreviewUrl();
|
|
183
|
+
|
|
184
|
+
if (!generatePreviewResult.success) {
|
|
185
|
+
table.push([
|
|
186
|
+
previewCellHeader,
|
|
187
|
+
{ content: warnChalk(generatePreviewResult.message) },
|
|
188
|
+
]);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
table.push([
|
|
193
|
+
previewCellHeader,
|
|
194
|
+
{ content: "Preview URL", href: generatePreviewResult.data },
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
if (openPreview) {
|
|
198
|
+
open(generatePreviewResult.data);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
164
201
|
}
|
|
@@ -3,8 +3,10 @@ import * as path from "path";
|
|
|
3
3
|
|
|
4
4
|
interface CliArgs {
|
|
5
5
|
example?: string;
|
|
6
|
-
useHttps
|
|
7
|
-
ngrok
|
|
6
|
+
useHttps: boolean;
|
|
7
|
+
ngrok: boolean;
|
|
8
|
+
preview: boolean;
|
|
9
|
+
overrideFrontendPort?: number;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
interface EnvVars {
|
|
@@ -45,7 +47,7 @@ export class Context {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
get ngrokEnabled() {
|
|
48
|
-
return
|
|
50
|
+
return this.args.ngrok;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
get hmrEnabled() {
|
|
@@ -53,7 +55,7 @@ export class Context {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
get httpsEnabled() {
|
|
56
|
-
return
|
|
58
|
+
return this.args.useHttps;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
get frontendEntryPath() {
|
|
@@ -69,11 +71,11 @@ export class Context {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
get frontendUrl() {
|
|
72
|
-
return `${this.protocol}://localhost:${this.
|
|
74
|
+
return `${this.protocol}://localhost:${this.frontendPort}`;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
get frontendPort() {
|
|
76
|
-
return this.envVars.frontendPort;
|
|
78
|
+
return this.args.overrideFrontendPort || this.envVars.frontendPort;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
get developerBackendEntryPath(): string | undefined {
|
|
@@ -117,6 +119,10 @@ export class Context {
|
|
|
117
119
|
return this.envVars.appId;
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
get openPreview(): boolean {
|
|
123
|
+
return this.args.preview;
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
private get protocol(): "https" | "http" {
|
|
121
127
|
return this.httpsEnabled ? "https" : "http";
|
|
122
128
|
}
|
|
@@ -23,6 +23,17 @@ yargs(hideBin(process.argv))
|
|
|
23
23
|
default:
|
|
24
24
|
process.env.npm_config_use_https?.toLocaleLowerCase().trim() === "true",
|
|
25
25
|
})
|
|
26
|
+
.option("override-frontend-port", {
|
|
27
|
+
description:
|
|
28
|
+
"Port to run the local development server on. Overrides the frontend port set in the .env file.",
|
|
29
|
+
type: "number",
|
|
30
|
+
alias: "p",
|
|
31
|
+
})
|
|
32
|
+
.option("preview", {
|
|
33
|
+
description: "Open the app in Canva.",
|
|
34
|
+
type: "boolean",
|
|
35
|
+
default: false,
|
|
36
|
+
})
|
|
26
37
|
.command(
|
|
27
38
|
"$0",
|
|
28
39
|
"Starts local development",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import type { ChildProcess } from "child_process";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import * as treeKill from "tree-kill";
|
|
6
|
+
|
|
7
|
+
describe("start script", () => {
|
|
8
|
+
let serverProcess: ChildProcess;
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
12
|
+
treeKill(serverProcess.pid);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should execute 'npm run start' and start a dev server", async () => {
|
|
17
|
+
const testServerPort = 8089;
|
|
18
|
+
serverProcess = await spawn(
|
|
19
|
+
`npm run start -- -p ${testServerPort} --no-preview`,
|
|
20
|
+
{
|
|
21
|
+
shell: true,
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!serverProcess.pid) {
|
|
26
|
+
throw new Error("Unable to start server");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// wait for the server to start and collect output until it reports the running URL
|
|
30
|
+
let output = "";
|
|
31
|
+
await new Promise<void>((resolve, reject) => {
|
|
32
|
+
serverProcess.stdout?.on("data", (data) => {
|
|
33
|
+
output += data.toString();
|
|
34
|
+
if (output.includes("Development URL")) {
|
|
35
|
+
resolve();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
serverProcess.stderr?.on("data", (data) => {
|
|
40
|
+
console.error("Server process error: ", data.toString());
|
|
41
|
+
reject();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// timeout and fail test if the server hasn't correctly started in 10 seconds
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
47
|
+
treeKill(serverProcess.pid);
|
|
48
|
+
}
|
|
49
|
+
reject(new Error("Test timed out"));
|
|
50
|
+
}, 10000);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// check that the server is running and accessible
|
|
54
|
+
const expectedServerURL = `http://localhost:${testServerPort}`;
|
|
55
|
+
expect(output).toContain(expectedServerURL);
|
|
56
|
+
expect(serverProcess.exitCode).toBeNull();
|
|
57
|
+
|
|
58
|
+
// clean up
|
|
59
|
+
treeKill(serverProcess.pid);
|
|
60
|
+
}, 15000); // 15 seconds timeout to allow for the server to start
|
|
61
|
+
});
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { SearchableListView } from "@canva/app-components";
|
|
2
2
|
import { Box } from "@canva/app-ui-kit";
|
|
3
|
+
import "@canva/app-ui-kit/styles.css";
|
|
4
|
+
import { useConfig } from "./config";
|
|
3
5
|
import { findResources } from "./adapter";
|
|
4
|
-
import { config } from "./config";
|
|
5
6
|
import * as styles from "./index.css";
|
|
6
|
-
import "@canva/app-ui-kit/styles.css";
|
|
7
7
|
|
|
8
8
|
export function App() {
|
|
9
|
+
const config = useConfig();
|
|
9
10
|
return (
|
|
10
11
|
<Box className={styles.rootWrapper}>
|
|
11
|
-
<SearchableListView
|
|
12
|
+
<SearchableListView
|
|
13
|
+
config={config}
|
|
14
|
+
findResources={findResources}
|
|
15
|
+
// TODO remove `saveExportedDesign` and `config.export` if your app does not support exporting the Canva design into an external platform
|
|
16
|
+
saveExportedDesign={(
|
|
17
|
+
exportedDesignUrl: string,
|
|
18
|
+
containerId: string | undefined,
|
|
19
|
+
designTitle: string | undefined,
|
|
20
|
+
) => {
|
|
21
|
+
// TODO update the function to save the design to your platform
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.info(
|
|
26
|
+
`Saving file "${designTitle}" from ${exportedDesignUrl} to ${config.serviceName} container id: ${containerId}`,
|
|
27
|
+
);
|
|
28
|
+
resolve({ success: true });
|
|
29
|
+
}, 1000);
|
|
30
|
+
});
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
12
33
|
</Box>
|
|
13
34
|
);
|
|
14
35
|
}
|