@canva/cli 1.19.0 → 1.20.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/CHANGELOG.md +7 -0
- package/README.md +1 -9
- package/cli.js +408 -409
- package/package.json +1 -2
- package/templates/base/backend/base_backend/create.ts +0 -114
- package/templates/base/backend/database/database.ts +0 -42
- package/templates/base/backend/routers/auth.ts +0 -288
- package/templates/base/declarations/declarations.d.ts +0 -29
- package/templates/base/eslint.config.mjs +0 -14
- package/templates/base/package.json +0 -91
- package/templates/base/scripts/copy_env.ts +0 -13
- package/templates/base/scripts/ssl/ssl.ts +0 -131
- package/templates/base/scripts/start/app_runner.ts +0 -223
- package/templates/base/scripts/start/context.ts +0 -171
- package/templates/base/scripts/start/start.ts +0 -46
- package/templates/base/scripts/start.tests.ts +0 -61
- package/templates/base/styles/components.css +0 -38
- package/templates/base/tsconfig.json +0 -56
- package/templates/base/webpack.config.ts +0 -247
- package/templates/common/.env.template +0 -6
- package/templates/common/.gitignore.template +0 -8
- package/templates/common/.nvmrc +0 -1
- package/templates/common/.prettierrc +0 -21
- package/templates/common/LICENSE.md +0 -48
- package/templates/common/README.md +0 -179
- package/templates/common/jest.config.mjs +0 -35
- package/templates/common/jest.setup.ts +0 -35
- package/templates/content_publisher/README.md +0 -58
- package/templates/content_publisher/canva-app.json +0 -17
- package/templates/content_publisher/declarations/declarations.d.ts +0 -29
- package/templates/content_publisher/eslint.config.mjs +0 -14
- package/templates/content_publisher/package.json +0 -90
- package/templates/content_publisher/scripts/copy_env.ts +0 -13
- package/templates/content_publisher/scripts/ssl/ssl.ts +0 -131
- package/templates/content_publisher/scripts/start/app_runner.ts +0 -223
- package/templates/content_publisher/scripts/start/context.ts +0 -171
- package/templates/content_publisher/scripts/start/start.ts +0 -46
- package/templates/content_publisher/src/index.tsx +0 -4
- package/templates/content_publisher/src/intents/content_publisher/index.tsx +0 -107
- package/templates/content_publisher/src/intents/content_publisher/post_preview.tsx +0 -240
- package/templates/content_publisher/src/intents/content_publisher/preview_ui.tsx +0 -62
- package/templates/content_publisher/src/intents/content_publisher/settings_ui.tsx +0 -81
- package/templates/content_publisher/src/intents/content_publisher/types.ts +0 -29
- package/templates/content_publisher/styles/components.css +0 -38
- package/templates/content_publisher/styles/preview_ui.css +0 -49
- package/templates/content_publisher/tsconfig.json +0 -56
- package/templates/content_publisher/webpack.config.ts +0 -247
- package/templates/dam/backend/routers/dam.ts +0 -108
- package/templates/dam/backend/server.ts +0 -65
- package/templates/dam/canva-app.json +0 -25
- package/templates/dam/declarations/declarations.d.ts +0 -29
- package/templates/dam/eslint.config.mjs +0 -14
- package/templates/dam/package.json +0 -97
- package/templates/dam/scripts/copy_env.ts +0 -13
- package/templates/dam/scripts/ssl/ssl.ts +0 -131
- package/templates/dam/scripts/start/app_runner.ts +0 -223
- package/templates/dam/scripts/start/context.ts +0 -171
- package/templates/dam/scripts/start/start.ts +0 -46
- package/templates/dam/src/index.tsx +0 -4
- package/templates/dam/src/intents/design_editor/adapter.ts +0 -44
- package/templates/dam/src/intents/design_editor/app.tsx +0 -35
- package/templates/dam/src/intents/design_editor/config.ts +0 -220
- package/templates/dam/src/intents/design_editor/index.css +0 -3
- package/templates/dam/src/intents/design_editor/index.tsx +0 -25
- package/templates/dam/tsconfig.json +0 -56
- package/templates/dam/utils/backend/base_backend/create.ts +0 -114
- package/templates/dam/webpack.config.ts +0 -247
- package/templates/data_connector/README.md +0 -84
- package/templates/data_connector/canva-app.json +0 -21
- package/templates/data_connector/declarations/declarations.d.ts +0 -29
- package/templates/data_connector/eslint.config.mjs +0 -14
- package/templates/data_connector/package.json +0 -92
- package/templates/data_connector/scripts/copy_env.ts +0 -13
- package/templates/data_connector/scripts/ssl/ssl.ts +0 -131
- package/templates/data_connector/scripts/start/app_runner.ts +0 -223
- package/templates/data_connector/scripts/start/context.ts +0 -171
- package/templates/data_connector/scripts/start/start.ts +0 -46
- package/templates/data_connector/src/api/connect_client.ts +0 -6
- package/templates/data_connector/src/api/data_source.ts +0 -97
- package/templates/data_connector/src/api/data_sources/designs.tsx +0 -296
- package/templates/data_connector/src/api/data_sources/index.ts +0 -4
- package/templates/data_connector/src/api/data_sources/templates.tsx +0 -328
- package/templates/data_connector/src/api/fetch_data_table.ts +0 -55
- package/templates/data_connector/src/api/index.ts +0 -4
- package/templates/data_connector/src/api/oauth.ts +0 -8
- package/templates/data_connector/src/api/tests/data_source.test.tsx +0 -99
- package/templates/data_connector/src/components/app_error.tsx +0 -15
- package/templates/data_connector/src/components/footer.tsx +0 -26
- package/templates/data_connector/src/components/header.tsx +0 -40
- package/templates/data_connector/src/components/index.ts +0 -3
- package/templates/data_connector/src/components/inputs/messages.tsx +0 -95
- package/templates/data_connector/src/components/inputs/search_filter.tsx +0 -109
- package/templates/data_connector/src/components/inputs/select_field.tsx +0 -26
- package/templates/data_connector/src/context/app_context.tsx +0 -125
- package/templates/data_connector/src/context/index.ts +0 -2
- package/templates/data_connector/src/context/use_app_context.ts +0 -17
- package/templates/data_connector/src/index.tsx +0 -4
- package/templates/data_connector/src/intents/data_connector/app.tsx +0 -20
- package/templates/data_connector/src/intents/data_connector/entrypoint.tsx +0 -70
- package/templates/data_connector/src/intents/data_connector/home.tsx +0 -21
- package/templates/data_connector/src/intents/data_connector/index.tsx +0 -56
- package/templates/data_connector/src/pages/data_source_config.tsx +0 -9
- package/templates/data_connector/src/pages/error.tsx +0 -37
- package/templates/data_connector/src/pages/index.ts +0 -4
- package/templates/data_connector/src/pages/login.tsx +0 -145
- package/templates/data_connector/src/pages/select_source.tsx +0 -24
- package/templates/data_connector/src/routes/index.ts +0 -2
- package/templates/data_connector/src/routes/paths.ts +0 -7
- package/templates/data_connector/src/routes/protected_route.tsx +0 -26
- package/templates/data_connector/src/routes/routes.tsx +0 -42
- package/templates/data_connector/src/utils/data_params.ts +0 -17
- package/templates/data_connector/src/utils/data_table.ts +0 -116
- package/templates/data_connector/src/utils/fetch_result.ts +0 -36
- package/templates/data_connector/src/utils/index.ts +0 -2
- package/templates/data_connector/src/utils/tests/data_table.test.ts +0 -133
- package/templates/data_connector/styles/components.css +0 -38
- package/templates/data_connector/tsconfig.json +0 -56
- package/templates/data_connector/webpack.config.ts +0 -247
- package/templates/gen_ai/README.md +0 -27
- package/templates/gen_ai/backend/routers/image.ts +0 -232
- package/templates/gen_ai/backend/server.ts +0 -65
- package/templates/gen_ai/canva-app.json +0 -25
- package/templates/gen_ai/declarations/declarations.d.ts +0 -29
- package/templates/gen_ai/eslint.config.mjs +0 -14
- package/templates/gen_ai/package.json +0 -101
- package/templates/gen_ai/scripts/copy_env.ts +0 -13
- package/templates/gen_ai/scripts/ssl/ssl.ts +0 -131
- package/templates/gen_ai/scripts/start/app_runner.ts +0 -223
- package/templates/gen_ai/scripts/start/context.ts +0 -171
- package/templates/gen_ai/scripts/start/start.ts +0 -46
- package/templates/gen_ai/src/api/api.ts +0 -194
- package/templates/gen_ai/src/api/index.ts +0 -1
- package/templates/gen_ai/src/components/app_error.tsx +0 -18
- package/templates/gen_ai/src/components/footer.messages.ts +0 -48
- package/templates/gen_ai/src/components/footer.tsx +0 -156
- package/templates/gen_ai/src/components/image_grid.tsx +0 -103
- package/templates/gen_ai/src/components/index.ts +0 -7
- package/templates/gen_ai/src/components/loading_results.tsx +0 -169
- package/templates/gen_ai/src/components/prompt_input.messages.ts +0 -14
- package/templates/gen_ai/src/components/prompt_input.tsx +0 -154
- package/templates/gen_ai/src/components/remaining_credits.tsx +0 -84
- package/templates/gen_ai/src/components/report_box.tsx +0 -54
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +0 -47
- package/templates/gen_ai/src/config.ts +0 -21
- package/templates/gen_ai/src/context/app_context.tsx +0 -153
- package/templates/gen_ai/src/context/context.messages.ts +0 -30
- package/templates/gen_ai/src/context/index.ts +0 -2
- package/templates/gen_ai/src/context/use_app_context.ts +0 -17
- package/templates/gen_ai/src/index.tsx +0 -4
- package/templates/gen_ai/src/intents/design_editor/app.tsx +0 -19
- package/templates/gen_ai/src/intents/design_editor/home.tsx +0 -13
- package/templates/gen_ai/src/intents/design_editor/index.tsx +0 -17
- package/templates/gen_ai/src/pages/error.tsx +0 -41
- package/templates/gen_ai/src/pages/generate.tsx +0 -9
- package/templates/gen_ai/src/pages/index.ts +0 -3
- package/templates/gen_ai/src/pages/results.tsx +0 -31
- package/templates/gen_ai/src/routes/index.ts +0 -1
- package/templates/gen_ai/src/routes/paths.ts +0 -4
- package/templates/gen_ai/src/routes/routes.tsx +0 -24
- package/templates/gen_ai/src/utils/index.ts +0 -1
- package/templates/gen_ai/src/utils/obscenity_filter.ts +0 -33
- package/templates/gen_ai/styles/components.css +0 -38
- package/templates/gen_ai/styles/utils.css +0 -3
- package/templates/gen_ai/tsconfig.json +0 -56
- package/templates/gen_ai/utils/backend/base_backend/create.ts +0 -114
- package/templates/gen_ai/webpack.config.ts +0 -247
- package/templates/hello_world/canva-app.json +0 -21
- package/templates/hello_world/declarations/declarations.d.ts +0 -29
- package/templates/hello_world/eslint.config.mjs +0 -14
- package/templates/hello_world/package.json +0 -90
- package/templates/hello_world/scripts/copy_env.ts +0 -13
- package/templates/hello_world/scripts/ssl/ssl.ts +0 -131
- package/templates/hello_world/scripts/start/app_runner.ts +0 -223
- package/templates/hello_world/scripts/start/context.ts +0 -171
- package/templates/hello_world/scripts/start/start.ts +0 -46
- package/templates/hello_world/src/index.tsx +0 -4
- package/templates/hello_world/src/intents/design_editor/app.tsx +0 -86
- package/templates/hello_world/src/intents/design_editor/index.tsx +0 -25
- package/templates/hello_world/src/intents/design_editor/tests/__snapshots__/app.tests.tsx.snap +0 -45
- package/templates/hello_world/src/intents/design_editor/tests/app.tests.tsx +0 -92
- package/templates/hello_world/styles/components.css +0 -38
- package/templates/hello_world/tsconfig.json +0 -56
- package/templates/hello_world/webpack.config.ts +0 -247
- package/templates/mls/README.md +0 -81
- package/templates/mls/canva-app.json +0 -25
- package/templates/mls/declarations/declarations.d.ts +0 -29
- package/templates/mls/eslint.config.mjs +0 -14
- package/templates/mls/jest.config.mjs +0 -36
- package/templates/mls/jest.setup.ts +0 -39
- package/templates/mls/package.json +0 -117
- package/templates/mls/scripts/copy_env.ts +0 -13
- package/templates/mls/scripts/ssl/ssl.ts +0 -131
- package/templates/mls/scripts/start/app_runner.ts +0 -223
- package/templates/mls/scripts/start/context.ts +0 -171
- package/templates/mls/scripts/start/start.ts +0 -46
- package/templates/mls/src/__tests__/app.tests.tsx +0 -11
- package/templates/mls/src/__tests__/office_selection_page.tests.tsx +0 -72
- package/templates/mls/src/__tests__/utils.tsx +0 -19
- package/templates/mls/src/adapter.ts +0 -126
- package/templates/mls/src/components/agent/agent_card.tsx +0 -57
- package/templates/mls/src/components/agent/agent_grid.tsx +0 -37
- package/templates/mls/src/components/agent/agent_list.tsx +0 -17
- package/templates/mls/src/components/agent/agent_search_filters.tsx +0 -88
- package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +0 -40
- package/templates/mls/src/components/listing/listing_card.tsx +0 -64
- package/templates/mls/src/components/listing/listing_grid.tsx +0 -37
- package/templates/mls/src/components/listing/listing_list.tsx +0 -21
- package/templates/mls/src/components/listing/listing_search_filters.tsx +0 -145
- package/templates/mls/src/components/placeholders/placeholders.tsx +0 -65
- package/templates/mls/src/data.ts +0 -359
- package/templates/mls/src/index.tsx +0 -4
- package/templates/mls/src/intents/design_editor/app.tsx +0 -44
- package/templates/mls/src/intents/design_editor/index.tsx +0 -25
- package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +0 -175
- package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +0 -126
- package/templates/mls/src/pages/list_page/list_page.tsx +0 -67
- package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +0 -135
- package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +0 -418
- package/templates/mls/src/pages/loading_page/loading_page.tsx +0 -152
- package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +0 -144
- package/templates/mls/src/real_estate.type.ts +0 -44
- package/templates/mls/src/util/use_add_element.tsx +0 -62
- package/templates/mls/src/util/use_drag_element.tsx +0 -68
- package/templates/mls/styles/components.css +0 -38
- package/templates/mls/tsconfig.json +0 -54
- package/templates/mls/webpack.config.ts +0 -248
- package/templates/optional/.cursor/mcp.json +0 -8
- package/templates/optional/.vscode/extensions.json +0 -6
- package/templates/optional/.vscode/mcp.json +0 -9
- package/templates/optional/AGENTS.md +0 -154
- package/templates/optional/CLAUDE.md +0 -154
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module "*.css" {
|
|
2
|
-
const styles: { [className: string]: string };
|
|
3
|
-
export = styles;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare module "*.jpg" {
|
|
7
|
-
const content: string;
|
|
8
|
-
export default content;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare module "*.jpeg" {
|
|
12
|
-
const content: string;
|
|
13
|
-
export default content;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module "*.png" {
|
|
17
|
-
const content: string;
|
|
18
|
-
export default content;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare module "*.svg" {
|
|
22
|
-
const content: React.FunctionComponent<{
|
|
23
|
-
size?: "tiny" | "small" | "medium" | "large";
|
|
24
|
-
className?: string;
|
|
25
|
-
}>;
|
|
26
|
-
export default content;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare const BACKEND_HOST: string;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"private": true,
|
|
3
|
-
"name": "digital_asset_management",
|
|
4
|
-
"description": "An example app leveraging @canva/app-components to develop a digital asset management (DAM) app.",
|
|
5
|
-
"scripts": {
|
|
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
|
-
"format": "prettier '**/*.{css,ts,tsx}' --no-config --write",
|
|
9
|
-
"format:check": "prettier '**/*.{css,ts,tsx}' --no-config --check --ignore-path",
|
|
10
|
-
"format:file": "prettier $1 --no-config --write",
|
|
11
|
-
"lint": "eslint .",
|
|
12
|
-
"lint:fix": "eslint . --fix",
|
|
13
|
-
"lint:types": "tsc",
|
|
14
|
-
"start": "ts-node ./scripts/start/start.ts",
|
|
15
|
-
"start:preview": "npm run start -- --preview",
|
|
16
|
-
"test": "jest --no-cache",
|
|
17
|
-
"test:watch": "jest --watchAll",
|
|
18
|
-
"postinstall": "ts-node ./scripts/copy_env.ts"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@canva/app-components": "^2.1.0",
|
|
22
|
-
"@canva/app-hooks": "^0.0.0-beta.4",
|
|
23
|
-
"@canva/app-i18n-kit": "^1.2.0",
|
|
24
|
-
"@canva/app-middleware": "^0.0.0-beta.5",
|
|
25
|
-
"@canva/app-ui-kit": "^5.5.0",
|
|
26
|
-
"@canva/asset": "^2.3.0",
|
|
27
|
-
"@canva/design": "^2.8.0",
|
|
28
|
-
"@canva/error": "^2.2.0",
|
|
29
|
-
"@canva/intents": "^2.2.0",
|
|
30
|
-
"@canva/platform": "^2.2.1",
|
|
31
|
-
"@canva/user": "^2.1.2",
|
|
32
|
-
"cookie-parser": "1.4.7",
|
|
33
|
-
"cors": "2.8.5",
|
|
34
|
-
"react": "^19.2.3",
|
|
35
|
-
"react-dom": "^19.2.3",
|
|
36
|
-
"react-intl": "^7.1.11"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@canva/app-eslint-plugin": "^1.0.0-beta.7",
|
|
40
|
-
"@canva/cli": ">= 0.0.1-beta.13",
|
|
41
|
-
"@formatjs/cli": "6.7.2",
|
|
42
|
-
"@formatjs/ts-transformer": "3.14.0",
|
|
43
|
-
"@ngrok/ngrok": "1.5.2",
|
|
44
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
|
|
45
|
-
"@svgr/webpack": "8.1.0",
|
|
46
|
-
"@testing-library/react": "16.3.0",
|
|
47
|
-
"@types/cors": "2.8.19",
|
|
48
|
-
"@types/debug": "4.1.12",
|
|
49
|
-
"@types/express": "4.17.21",
|
|
50
|
-
"@types/jest": "29.5.14",
|
|
51
|
-
"@types/jsonwebtoken": "9.0.10",
|
|
52
|
-
"@types/node": "20.19.2",
|
|
53
|
-
"@types/node-fetch": "2.6.13",
|
|
54
|
-
"@types/node-forge": "1.3.14",
|
|
55
|
-
"@types/nodemon": "1.19.6",
|
|
56
|
-
"@types/prompts": "2.4.9",
|
|
57
|
-
"@types/react": "19.2.2",
|
|
58
|
-
"@types/react-dom": "19.2.1",
|
|
59
|
-
"@types/webpack-env": "1.18.8",
|
|
60
|
-
"chalk": "4.1.2",
|
|
61
|
-
"cli-table3": "0.6.5",
|
|
62
|
-
"css-loader": "7.1.2",
|
|
63
|
-
"css-modules-typescript-loader": "4.0.1",
|
|
64
|
-
"cssnano": "7.1.1",
|
|
65
|
-
"debug": "4.4.1",
|
|
66
|
-
"dotenv": "16.6.0",
|
|
67
|
-
"exponential-backoff": "3.1.2",
|
|
68
|
-
"express": "4.22.1",
|
|
69
|
-
"express-basic-auth": "1.2.1",
|
|
70
|
-
"jest": "29.7.0",
|
|
71
|
-
"jest-css-modules-transform": "4.4.2",
|
|
72
|
-
"jest-environment-jsdom": "29.7.0",
|
|
73
|
-
"jsonwebtoken": "9.0.3",
|
|
74
|
-
"jwks-rsa": "3.2.0",
|
|
75
|
-
"mini-css-extract-plugin": "2.9.4",
|
|
76
|
-
"node-fetch": "3.3.2",
|
|
77
|
-
"node-forge": "1.3.2",
|
|
78
|
-
"nodemon": "3.0.1",
|
|
79
|
-
"open": "8.4.2",
|
|
80
|
-
"postcss-loader": "8.1.1",
|
|
81
|
-
"prettier": "3.6.2",
|
|
82
|
-
"prompts": "2.4.2",
|
|
83
|
-
"react-refresh": "0.17.0",
|
|
84
|
-
"style-loader": "4.0.0",
|
|
85
|
-
"terser-webpack-plugin": "5.3.14",
|
|
86
|
-
"tree-kill": "1.2.2",
|
|
87
|
-
"ts-jest": "29.4.1",
|
|
88
|
-
"ts-loader": "9.5.4",
|
|
89
|
-
"ts-node": "10.9.2",
|
|
90
|
-
"typescript": "5.9.2",
|
|
91
|
-
"url-loader": "4.1.1",
|
|
92
|
-
"webpack": "5.99.9",
|
|
93
|
-
"webpack-cli": "6.0.1",
|
|
94
|
-
"webpack-dev-server": "5.2.2",
|
|
95
|
-
"yargs": "17.7.2"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
|
|
6
|
-
const envPath = path.resolve(__dirname, "..", ".env");
|
|
7
|
-
const templatePath = path.resolve(__dirname, "..", ".env.template");
|
|
8
|
-
|
|
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)) {
|
|
12
|
-
fs.copyFileSync(templatePath, envPath);
|
|
13
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import { pki } from "node-forge";
|
|
4
|
-
import path from "path";
|
|
5
|
-
|
|
6
|
-
const SSL_CERT_DIR = path.resolve(process.cwd(), "..", "..", ".ssl");
|
|
7
|
-
const CERT_FILE = path.resolve(SSL_CERT_DIR, "certificate.pem");
|
|
8
|
-
const KEY_FILE = path.resolve(SSL_CERT_DIR, "private-key.pem");
|
|
9
|
-
|
|
10
|
-
export interface Certificate {
|
|
11
|
-
keyFile: string;
|
|
12
|
-
certFile: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const CERT_ATTRS: { name: string; value: string }[] = [
|
|
16
|
-
{
|
|
17
|
-
name: "commonName",
|
|
18
|
-
value: "localhost",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: "countryName",
|
|
22
|
-
value: "AU",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "stateOrProvinceName",
|
|
26
|
-
value: "New South Wales",
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: "localityName",
|
|
30
|
-
value: "Sydney",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "organizationName",
|
|
34
|
-
value: "Test",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "organizationalUnitName",
|
|
38
|
-
value: "Test",
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const generateRsaKeys = async (): Promise<{
|
|
43
|
-
publicKey: string;
|
|
44
|
-
privateKey: string;
|
|
45
|
-
}> =>
|
|
46
|
-
new Promise((resolve, reject) => {
|
|
47
|
-
crypto.generateKeyPair(
|
|
48
|
-
"rsa",
|
|
49
|
-
{
|
|
50
|
-
modulusLength: 2096,
|
|
51
|
-
publicKeyEncoding: {
|
|
52
|
-
type: "spki",
|
|
53
|
-
format: "pem",
|
|
54
|
-
},
|
|
55
|
-
privateKeyEncoding: {
|
|
56
|
-
type: "pkcs8",
|
|
57
|
-
format: "pem",
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
(err, publicKey, privateKey) => {
|
|
61
|
-
if (err) {
|
|
62
|
-
reject(err);
|
|
63
|
-
} else {
|
|
64
|
-
resolve({ publicKey, privateKey });
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const generateCertificate = (opts: {
|
|
71
|
-
privateKey: string;
|
|
72
|
-
publicKey: string;
|
|
73
|
-
}): string => {
|
|
74
|
-
const privateKey = pki.privateKeyFromPem(opts.privateKey);
|
|
75
|
-
const publicKey = pki.publicKeyFromPem(opts.publicKey);
|
|
76
|
-
|
|
77
|
-
const cert = pki.createCertificate();
|
|
78
|
-
|
|
79
|
-
cert.publicKey = publicKey;
|
|
80
|
-
cert.serialNumber = "01";
|
|
81
|
-
cert.validity.notBefore = new Date();
|
|
82
|
-
cert.validity.notAfter = new Date();
|
|
83
|
-
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
84
|
-
|
|
85
|
-
cert.setSubject(CERT_ATTRS);
|
|
86
|
-
cert.setIssuer(CERT_ATTRS);
|
|
87
|
-
|
|
88
|
-
// the actual certificate signing
|
|
89
|
-
cert.sign(privateKey);
|
|
90
|
-
|
|
91
|
-
// now convert the Forge certificate to PEM format
|
|
92
|
-
return pki.certificateToPem(cert);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const writeCertFiles = async (opts: {
|
|
96
|
-
cert: string;
|
|
97
|
-
privateKey: string;
|
|
98
|
-
}): Promise<void> => {
|
|
99
|
-
const { cert, privateKey } = opts;
|
|
100
|
-
|
|
101
|
-
await fs.mkdir(SSL_CERT_DIR, { recursive: true });
|
|
102
|
-
await Promise.all([
|
|
103
|
-
fs.writeFile(CERT_FILE, cert, { encoding: "utf8" }),
|
|
104
|
-
fs.writeFile(KEY_FILE, privateKey, { encoding: "utf8" }),
|
|
105
|
-
]);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const cerfFilesExist = async (): Promise<boolean> => {
|
|
109
|
-
try {
|
|
110
|
-
await Promise.all([
|
|
111
|
-
fs.access(CERT_FILE, fs.constants.R_OK | fs.constants.W_OK),
|
|
112
|
-
fs.access(KEY_FILE, fs.constants.R_OK | fs.constants.W_OK),
|
|
113
|
-
]);
|
|
114
|
-
return true;
|
|
115
|
-
} catch {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const createOrRetrieveCertificate = async (): Promise<Certificate> => {
|
|
121
|
-
if (!(await cerfFilesExist())) {
|
|
122
|
-
const keys = await generateRsaKeys();
|
|
123
|
-
const cert = generateCertificate(keys);
|
|
124
|
-
await writeCertFiles({ cert, privateKey: keys.privateKey });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
certFile: CERT_FILE,
|
|
129
|
-
keyFile: KEY_FILE,
|
|
130
|
-
};
|
|
131
|
-
};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { generatePreviewUrl } from "@canva/cli";
|
|
3
|
-
import ngrok from "@ngrok/ngrok";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import Table from "cli-table3";
|
|
6
|
-
import nodemon from "nodemon";
|
|
7
|
-
import open from "open";
|
|
8
|
-
import os from "os";
|
|
9
|
-
import webpack from "webpack";
|
|
10
|
-
import WebpackDevServer from "webpack-dev-server";
|
|
11
|
-
import { buildConfig } from "../../webpack.config";
|
|
12
|
-
import type { Certificate } from "../ssl/ssl";
|
|
13
|
-
import { createOrRetrieveCertificate } from "../ssl/ssl";
|
|
14
|
-
import type { Context } from "./context";
|
|
15
|
-
|
|
16
|
-
export const infoChalk = chalk.blue.bold;
|
|
17
|
-
export const warnChalk = chalk.bgYellow.bold;
|
|
18
|
-
export const errorChalk = chalk.bgRed.bold;
|
|
19
|
-
export const highlightChalk = chalk.greenBright.bold;
|
|
20
|
-
export const linkChalk = chalk.cyan;
|
|
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
|
-
|
|
38
|
-
export class AppRunner {
|
|
39
|
-
async run(ctx: Context) {
|
|
40
|
-
console.log(
|
|
41
|
-
infoChalk("Info:"),
|
|
42
|
-
`Starting development server for ${highlightChalk(ctx.entryDir)}\n`,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (!ctx.hmrEnabled) {
|
|
46
|
-
console.log(
|
|
47
|
-
`${infoChalk(
|
|
48
|
-
"Note:",
|
|
49
|
-
)} Hot Module Replacement (HMR) not enabled. To enable it, please refer to the instructions in the ${highlightChalk(
|
|
50
|
-
"README.md",
|
|
51
|
-
)}\n`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let cert: Certificate | undefined;
|
|
56
|
-
if (ctx.httpsEnabled) {
|
|
57
|
-
try {
|
|
58
|
-
cert = await createOrRetrieveCertificate();
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.log(
|
|
61
|
-
errorChalk("Error:"),
|
|
62
|
-
"Unable to generate SSL certificate.",
|
|
63
|
-
);
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const table = new Table({
|
|
69
|
-
colWidths: [30, 80],
|
|
70
|
-
wordWrap: true,
|
|
71
|
-
wrapOnWordBoundary: true,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const server = await this.runWebpackDevServer(ctx, table, cert);
|
|
75
|
-
|
|
76
|
-
await this.maybeRunBackendServer(ctx, table, cert, server);
|
|
77
|
-
|
|
78
|
-
await this.generateAndOpenPreviewUrl(ctx.openPreview, table);
|
|
79
|
-
|
|
80
|
-
console.log(table.toString(), "\n");
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
83
|
-
`${infoChalk(
|
|
84
|
-
"Note:",
|
|
85
|
-
)} For instructions on how to set up the app via the Developer Portal, see the ${highlightChalk(
|
|
86
|
-
"README.md",
|
|
87
|
-
)}.\n`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private readonly maybeRunBackendServer = async (
|
|
92
|
-
ctx: Context,
|
|
93
|
-
table: Table.Table,
|
|
94
|
-
cert: Certificate | undefined,
|
|
95
|
-
webpackDevServer: WebpackDevServer,
|
|
96
|
-
) => {
|
|
97
|
-
if (!ctx.developerBackendEntryPath) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// App ID must be set when running a backend example
|
|
102
|
-
if (!ctx.appId) {
|
|
103
|
-
console.log(
|
|
104
|
-
errorChalk("Error:"),
|
|
105
|
-
`'CANVA_APP_ID' environment variable is undefined. Refer to the instructions in the ${highlightChalk(
|
|
106
|
-
"README.md",
|
|
107
|
-
)} on starting a backend example.`,
|
|
108
|
-
);
|
|
109
|
-
throw new Error("'CANVA_APP_ID' env variable not set.");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await new Promise((resolve) => {
|
|
113
|
-
const nodemonServer = nodemon({
|
|
114
|
-
script: ctx.developerBackendEntryPath,
|
|
115
|
-
ext: "ts",
|
|
116
|
-
env: {
|
|
117
|
-
SHOULD_ENABLE_HTTPS: ctx.httpsEnabled,
|
|
118
|
-
HTTPS_CERT_FILE: cert?.certFile || "",
|
|
119
|
-
HTTPS_KEY_FILE: cert?.keyFile || "",
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
nodemonServer.on("start", resolve);
|
|
124
|
-
|
|
125
|
-
nodemonServer.on("crash", async () => {
|
|
126
|
-
console.log(errorChalk("Shutting down local server.\n"));
|
|
127
|
-
|
|
128
|
-
await webpackDevServer.stop();
|
|
129
|
-
process.exit(1);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
if (ctx.ngrokEnabled) {
|
|
134
|
-
console.log(
|
|
135
|
-
warnChalk("Warning:"),
|
|
136
|
-
`ngrok exposes a local port via a public URL. Be mindful of what's exposed and shut down the server when it's not in use.\n`,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let url = ctx.backendUrl;
|
|
141
|
-
if (ctx.ngrokEnabled) {
|
|
142
|
-
try {
|
|
143
|
-
const ngrokListener = await ngrok.forward({
|
|
144
|
-
addr: ctx.backendPort,
|
|
145
|
-
// requires an `NGROK_AUTHTOKEN` env var to be set
|
|
146
|
-
authtoken_from_env: true,
|
|
147
|
-
});
|
|
148
|
-
url = ngrokListener.url() ?? url;
|
|
149
|
-
} catch (err) {
|
|
150
|
-
console.log(
|
|
151
|
-
errorChalk("Error:"),
|
|
152
|
-
`Unable to start ngrok server: ${err}`,
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
table.push(["Base URL (Backend)", linkChalk(url)]);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
private readonly runWebpackDevServer = async (
|
|
161
|
-
ctx: Context,
|
|
162
|
-
table: Table.Table,
|
|
163
|
-
cert: Certificate | undefined,
|
|
164
|
-
): Promise<WebpackDevServer> => {
|
|
165
|
-
const runtimeWebpackConfig = buildConfig({
|
|
166
|
-
appEntry: ctx.frontendEntryPath,
|
|
167
|
-
backendHost: ctx.backendHost,
|
|
168
|
-
devConfig: {
|
|
169
|
-
port: ctx.frontendPort,
|
|
170
|
-
enableHmr: ctx.hmrEnabled,
|
|
171
|
-
appId: ctx.appId,
|
|
172
|
-
appOrigin: ctx.appOrigin,
|
|
173
|
-
enableHttps: ctx.httpsEnabled,
|
|
174
|
-
...cert,
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const compiler = webpack(runtimeWebpackConfig);
|
|
179
|
-
const server = new WebpackDevServer(
|
|
180
|
-
runtimeWebpackConfig.devServer,
|
|
181
|
-
compiler,
|
|
182
|
-
);
|
|
183
|
-
await server.start();
|
|
184
|
-
|
|
185
|
-
table.push(["Development URL (Frontend)", linkChalk(ctx.frontendUrl)]);
|
|
186
|
-
|
|
187
|
-
return server;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Calls the Canva CLI to generate a preview URL for the app
|
|
192
|
-
*/
|
|
193
|
-
private readonly generateAndOpenPreviewUrl = async (
|
|
194
|
-
openPreview: boolean,
|
|
195
|
-
table: Table.Table,
|
|
196
|
-
) => {
|
|
197
|
-
const previewCellHeader = { content: "Preview your app in Canva" };
|
|
198
|
-
|
|
199
|
-
const generatePreviewResult = await generatePreviewUrl();
|
|
200
|
-
|
|
201
|
-
if (!generatePreviewResult.success) {
|
|
202
|
-
table.push([
|
|
203
|
-
previewCellHeader,
|
|
204
|
-
{ content: warnChalk(generatePreviewResult.message) },
|
|
205
|
-
]);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const modifierKey = getModifierKey();
|
|
210
|
-
|
|
211
|
-
table.push([
|
|
212
|
-
previewCellHeader,
|
|
213
|
-
{
|
|
214
|
-
content: `Preview URL (${modifierKey} + click)`,
|
|
215
|
-
href: generatePreviewResult.data,
|
|
216
|
-
},
|
|
217
|
-
]);
|
|
218
|
-
|
|
219
|
-
if (openPreview) {
|
|
220
|
-
open(generatePreviewResult.data);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
interface CliArgs {
|
|
5
|
-
example?: string;
|
|
6
|
-
useHttps: boolean;
|
|
7
|
-
ngrok: boolean;
|
|
8
|
-
preview: boolean;
|
|
9
|
-
overrideFrontendPort?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface EnvVars {
|
|
13
|
-
frontendPort: number;
|
|
14
|
-
backendPort: number;
|
|
15
|
-
hmrEnabled: boolean;
|
|
16
|
-
appId?: string;
|
|
17
|
-
appOrigin?: string;
|
|
18
|
-
backendHost?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class Context {
|
|
22
|
-
private readonly envVars: EnvVars;
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
private env: NodeJS.ProcessEnv = process.env,
|
|
26
|
-
private readonly args: CliArgs,
|
|
27
|
-
) {
|
|
28
|
-
this.envVars = this.parseAndValidateEnvironmentVariables();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static get srcDir() {
|
|
32
|
-
const src = path.join(Context.rootDir, "src");
|
|
33
|
-
|
|
34
|
-
if (!fs.existsSync(src)) {
|
|
35
|
-
throw new Error(`Directory does not exist: ${src}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return src;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static get readmeDir() {
|
|
42
|
-
return path.join(Context.rootDir, "README.md");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get entryDir() {
|
|
46
|
-
return Context.srcDir;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get ngrokEnabled() {
|
|
50
|
-
return this.args.ngrok;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get hmrEnabled() {
|
|
54
|
-
return this.envVars.hmrEnabled;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get httpsEnabled() {
|
|
58
|
-
return this.args.useHttps;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get frontendEntryPath() {
|
|
62
|
-
const frontendEntryPath = path.join(this.entryDir, "index.tsx");
|
|
63
|
-
|
|
64
|
-
if (!fs.existsSync(frontendEntryPath)) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Entry point for frontend does not exist: ${frontendEntryPath}`,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return frontendEntryPath;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get frontendUrl() {
|
|
74
|
-
return `${this.protocol}://localhost:${this.frontendPort}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get frontendPort() {
|
|
78
|
-
return this.args.overrideFrontendPort || this.envVars.frontendPort;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get developerBackendEntryPath(): string | undefined {
|
|
82
|
-
const developerBackendEntryPath = path.join(
|
|
83
|
-
Context.rootDir,
|
|
84
|
-
"backend",
|
|
85
|
-
"server.ts",
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
if (!fs.existsSync(developerBackendEntryPath)) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return developerBackendEntryPath;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
get backendUrl() {
|
|
96
|
-
return `${this.protocol}://localhost:${this.envVars.backendPort}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get backendHost() {
|
|
100
|
-
let backendHost = this.envVars.backendHost;
|
|
101
|
-
|
|
102
|
-
// if there's no custom URL provided by the developer, we fallback to our localhost backend
|
|
103
|
-
if (!backendHost || backendHost.trim() === "") {
|
|
104
|
-
backendHost = this.backendUrl;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return backendHost;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
get backendPort() {
|
|
111
|
-
return this.envVars.backendPort;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get appOrigin(): string | undefined {
|
|
115
|
-
return this.envVars.appOrigin;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get appId(): string | undefined {
|
|
119
|
-
return this.envVars.appId;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get openPreview(): boolean {
|
|
123
|
-
return this.args.preview;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private get protocol(): "https" | "http" {
|
|
127
|
-
return this.httpsEnabled ? "https" : "http";
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private static get rootDir() {
|
|
131
|
-
return path.join(process.cwd());
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private parseAndValidateEnvironmentVariables(): EnvVars {
|
|
135
|
-
const {
|
|
136
|
-
CANVA_FRONTEND_PORT,
|
|
137
|
-
CANVA_BACKEND_PORT,
|
|
138
|
-
CANVA_BACKEND_HOST,
|
|
139
|
-
CANVA_APP_ID,
|
|
140
|
-
CANVA_APP_ORIGIN,
|
|
141
|
-
CANVA_HMR_ENABLED,
|
|
142
|
-
} = this.env;
|
|
143
|
-
|
|
144
|
-
if (!CANVA_FRONTEND_PORT) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
"CANVA_FRONTEND_PORT environment variable is not defined",
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!CANVA_BACKEND_PORT) {
|
|
151
|
-
throw new Error("CANVA_BACKEND_PORT environment variable is not defined");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const envVars: EnvVars = {
|
|
155
|
-
frontendPort: parseInt(CANVA_FRONTEND_PORT, 10),
|
|
156
|
-
backendPort: parseInt(CANVA_BACKEND_PORT, 10),
|
|
157
|
-
hmrEnabled: CANVA_HMR_ENABLED?.toLowerCase().trim() === "true",
|
|
158
|
-
appId: CANVA_APP_ID,
|
|
159
|
-
appOrigin: CANVA_APP_ORIGIN,
|
|
160
|
-
backendHost: CANVA_BACKEND_HOST,
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
if (envVars.hmrEnabled && envVars.appOrigin == null) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
"CANVA_HMR_ENABLED environment variable is TRUE, but CANVA_APP_ORIGIN is not set. Refer to the instructions in the README.md on configuring HMR.",
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return envVars;
|
|
170
|
-
}
|
|
171
|
-
}
|