@canva/cli 0.0.1-beta.1
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/LICENSE.md +48 -0
- package/README.md +206 -0
- package/cli.js +566 -0
- package/package.json +30 -0
- package/templates/base/backend/database/database.ts +42 -0
- package/templates/base/backend/routers/auth.ts +285 -0
- package/templates/base/declarations/declarations.d.ts +29 -0
- package/templates/base/eslint.config.mjs +309 -0
- package/templates/base/package.json +83 -0
- package/templates/base/scripts/ssl/ssl.ts +131 -0
- package/templates/base/scripts/start/app_runner.ts +164 -0
- package/templates/base/scripts/start/context.ts +165 -0
- package/templates/base/scripts/start/start.ts +35 -0
- package/templates/base/styles/components.css +38 -0
- package/templates/base/tsconfig.json +54 -0
- package/templates/base/utils/backend/base_backend/create.ts +104 -0
- package/templates/base/utils/backend/jwt_middleware/index.ts +1 -0
- package/templates/base/utils/backend/jwt_middleware/jwt_middleware.ts +229 -0
- package/templates/base/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +630 -0
- package/templates/base/webpack.config.cjs +270 -0
- package/templates/common/.env.template +6 -0
- package/templates/common/.gitignore.template +9 -0
- package/templates/common/LICENSE.md +48 -0
- package/templates/common/README.md +250 -0
- package/templates/common/jest.config.mjs +8 -0
- package/templates/dam/backend/database/database.ts +42 -0
- package/templates/dam/backend/routers/auth.ts +285 -0
- package/templates/dam/backend/routers/dam.ts +86 -0
- package/templates/dam/backend/server.ts +65 -0
- package/templates/dam/declarations/declarations.d.ts +29 -0
- package/templates/dam/eslint.config.mjs +309 -0
- package/templates/dam/package.json +90 -0
- package/templates/dam/scripts/ssl/ssl.ts +131 -0
- package/templates/dam/scripts/start/app_runner.ts +164 -0
- package/templates/dam/scripts/start/context.ts +165 -0
- package/templates/dam/scripts/start/start.ts +35 -0
- package/templates/dam/src/adapter.ts +44 -0
- package/templates/dam/src/app.tsx +147 -0
- package/templates/dam/src/config.ts +95 -0
- package/templates/dam/src/index.css +10 -0
- package/templates/dam/src/index.tsx +22 -0
- package/templates/dam/tsconfig.json +54 -0
- package/templates/dam/utils/backend/base_backend/create.ts +104 -0
- package/templates/dam/utils/backend/jwt_middleware/index.ts +1 -0
- package/templates/dam/utils/backend/jwt_middleware/jwt_middleware.ts +229 -0
- package/templates/dam/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +630 -0
- package/templates/dam/webpack.config.cjs +270 -0
- package/templates/gen_ai/README.md +27 -0
- package/templates/gen_ai/backend/database/database.ts +42 -0
- package/templates/gen_ai/backend/routers/auth.ts +285 -0
- package/templates/gen_ai/backend/routers/image.ts +234 -0
- package/templates/gen_ai/backend/server.ts +56 -0
- package/templates/gen_ai/declarations/declarations.d.ts +29 -0
- package/templates/gen_ai/eslint.config.mjs +309 -0
- package/templates/gen_ai/package.json +92 -0
- package/templates/gen_ai/scripts/ssl/ssl.ts +131 -0
- package/templates/gen_ai/scripts/start/app_runner.ts +164 -0
- package/templates/gen_ai/scripts/start/context.ts +165 -0
- package/templates/gen_ai/scripts/start/start.ts +35 -0
- package/templates/gen_ai/src/api/api.ts +228 -0
- package/templates/gen_ai/src/api/index.ts +1 -0
- package/templates/gen_ai/src/app.tsx +13 -0
- package/templates/gen_ai/src/components/app_error.tsx +18 -0
- package/templates/gen_ai/src/components/footer.messages.ts +53 -0
- package/templates/gen_ai/src/components/footer.tsx +157 -0
- package/templates/gen_ai/src/components/image_grid.tsx +96 -0
- package/templates/gen_ai/src/components/index.ts +8 -0
- package/templates/gen_ai/src/components/loading_results.tsx +169 -0
- package/templates/gen_ai/src/components/logged_in_status.tsx +44 -0
- package/templates/gen_ai/src/components/prompt_input.messages.ts +14 -0
- package/templates/gen_ai/src/components/prompt_input.tsx +149 -0
- package/templates/gen_ai/src/components/remaining_credits.tsx +75 -0
- package/templates/gen_ai/src/components/report_box.tsx +53 -0
- package/templates/gen_ai/src/config.ts +21 -0
- package/templates/gen_ai/src/context/app_context.tsx +174 -0
- package/templates/gen_ai/src/context/context.messages.ts +41 -0
- package/templates/gen_ai/src/context/index.ts +2 -0
- package/templates/gen_ai/src/context/use_app_context.ts +17 -0
- package/templates/gen_ai/src/index.tsx +31 -0
- package/templates/gen_ai/src/pages/error.tsx +41 -0
- package/templates/gen_ai/src/pages/generate.tsx +9 -0
- package/templates/gen_ai/src/pages/index.ts +3 -0
- package/templates/gen_ai/src/pages/results.tsx +31 -0
- package/templates/gen_ai/src/routes/index.ts +1 -0
- package/templates/gen_ai/src/routes/routes.tsx +26 -0
- package/templates/gen_ai/src/services/auth.tsx +31 -0
- package/templates/gen_ai/src/services/index.ts +1 -0
- package/templates/gen_ai/src/utils/index.ts +1 -0
- package/templates/gen_ai/src/utils/obscenity_filter.ts +33 -0
- package/templates/gen_ai/styles/components.css +38 -0
- package/templates/gen_ai/styles/utils.css +3 -0
- package/templates/gen_ai/tsconfig.json +54 -0
- package/templates/gen_ai/utils/backend/base_backend/create.ts +104 -0
- package/templates/gen_ai/utils/backend/jwt_middleware/index.ts +1 -0
- package/templates/gen_ai/utils/backend/jwt_middleware/jwt_middleware.ts +229 -0
- package/templates/gen_ai/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +630 -0
- package/templates/gen_ai/webpack.config.cjs +270 -0
- package/templates/hello_world/declarations/declarations.d.ts +29 -0
- package/templates/hello_world/eslint.config.mjs +309 -0
- package/templates/hello_world/package.json +73 -0
- package/templates/hello_world/scripts/ssl/ssl.ts +131 -0
- package/templates/hello_world/scripts/start/app_runner.ts +164 -0
- package/templates/hello_world/scripts/start/context.ts +165 -0
- package/templates/hello_world/scripts/start/start.ts +35 -0
- package/templates/hello_world/src/app.tsx +41 -0
- package/templates/hello_world/src/index.tsx +22 -0
- package/templates/hello_world/styles/components.css +38 -0
- package/templates/hello_world/tsconfig.json +54 -0
- package/templates/hello_world/webpack.config.cjs +270 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
require("dotenv").config();
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
4
|
+
const { DefinePlugin, optimize } = require("webpack");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const { transform } = require("@formatjs/ts-transformer");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} [options]
|
|
11
|
+
* @param {string} [options.appEntry=./src/index.tsx]
|
|
12
|
+
* @param {string} [options.backendHost]
|
|
13
|
+
* @param {Object} [options.devConfig]
|
|
14
|
+
* @param {number} [options.devConfig.port]
|
|
15
|
+
* @param {boolean} [options.devConfig.enableHmr]
|
|
16
|
+
* @param {boolean} [options.devConfig.enableHttps]
|
|
17
|
+
* @param {string} [options.devConfig.appOrigin]
|
|
18
|
+
* @param {string} [options.devConfig.appId] - Deprecated in favour of appOrigin
|
|
19
|
+
* @param {string} [options.devConfig.certFile]
|
|
20
|
+
* @param {string} [options.devConfig.keyFile]
|
|
21
|
+
* @returns {Object}
|
|
22
|
+
*/
|
|
23
|
+
function buildConfig({
|
|
24
|
+
devConfig,
|
|
25
|
+
appEntry = path.join(process.cwd(), "src", "index.tsx"),
|
|
26
|
+
backendHost = process.env.CANVA_BACKEND_HOST,
|
|
27
|
+
} = {}) {
|
|
28
|
+
const mode = devConfig ? "development" : "production";
|
|
29
|
+
|
|
30
|
+
if (!backendHost) {
|
|
31
|
+
console.error(
|
|
32
|
+
chalk.redBright.bold("BACKEND_HOST is undefined."),
|
|
33
|
+
`Refer to "Customizing the backend host" in the README.md for more information.`,
|
|
34
|
+
);
|
|
35
|
+
process.exit(-1);
|
|
36
|
+
} else if (backendHost.includes("localhost") && mode === "production") {
|
|
37
|
+
console.error(
|
|
38
|
+
chalk.redBright.bold(
|
|
39
|
+
"BACKEND_HOST should not be set to localhost for production builds!",
|
|
40
|
+
),
|
|
41
|
+
`Refer to "Customizing the backend host" in the README.md for more information.`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
mode,
|
|
47
|
+
context: path.resolve(process.cwd(), "./"),
|
|
48
|
+
entry: {
|
|
49
|
+
app: appEntry,
|
|
50
|
+
},
|
|
51
|
+
target: "web",
|
|
52
|
+
resolve: {
|
|
53
|
+
alias: {
|
|
54
|
+
assets: path.resolve(process.cwd(), "assets"),
|
|
55
|
+
utils: path.resolve(process.cwd(), "utils"),
|
|
56
|
+
styles: path.resolve(process.cwd(), "styles"),
|
|
57
|
+
src: path.resolve(process.cwd(), "src"),
|
|
58
|
+
},
|
|
59
|
+
extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
|
|
60
|
+
},
|
|
61
|
+
infrastructureLogging: {
|
|
62
|
+
level: "none",
|
|
63
|
+
},
|
|
64
|
+
module: {
|
|
65
|
+
rules: [
|
|
66
|
+
{
|
|
67
|
+
test: /\.tsx?$/,
|
|
68
|
+
exclude: /node_modules/,
|
|
69
|
+
use: [
|
|
70
|
+
{
|
|
71
|
+
loader: "ts-loader",
|
|
72
|
+
options: {
|
|
73
|
+
transpileOnly: true,
|
|
74
|
+
getCustomTransformers() {
|
|
75
|
+
return {
|
|
76
|
+
before: [
|
|
77
|
+
transform({
|
|
78
|
+
overrideIdFn: "[sha512:contenthash:base64:6]",
|
|
79
|
+
}),
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
test: /\.css$/,
|
|
89
|
+
exclude: /node_modules/,
|
|
90
|
+
use: [
|
|
91
|
+
"style-loader",
|
|
92
|
+
{
|
|
93
|
+
loader: "css-loader",
|
|
94
|
+
options: {
|
|
95
|
+
modules: true,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
loader: "postcss-loader",
|
|
100
|
+
options: {
|
|
101
|
+
postcssOptions: {
|
|
102
|
+
plugins: [require("cssnano")({ preset: "default" })],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
test: /\.(png|jpg|jpeg)$/i,
|
|
110
|
+
type: "asset/inline",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
test: /\.(woff|woff2)$/,
|
|
114
|
+
type: "asset/inline",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
test: /\.svg$/,
|
|
118
|
+
oneOf: [
|
|
119
|
+
{
|
|
120
|
+
issuer: /\.[jt]sx?$/,
|
|
121
|
+
resourceQuery: /react/, // *.svg?react
|
|
122
|
+
use: ["@svgr/webpack", "url-loader"],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: "asset/resource",
|
|
126
|
+
parser: {
|
|
127
|
+
dataUrlCondition: {
|
|
128
|
+
maxSize: 200,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
test: /\.css$/,
|
|
136
|
+
include: /node_modules/,
|
|
137
|
+
use: [
|
|
138
|
+
"style-loader",
|
|
139
|
+
"css-loader",
|
|
140
|
+
{
|
|
141
|
+
loader: "postcss-loader",
|
|
142
|
+
options: {
|
|
143
|
+
postcssOptions: {
|
|
144
|
+
plugins: [require("cssnano")({ preset: "default" })],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
optimization: {
|
|
153
|
+
minimizer: [
|
|
154
|
+
new TerserPlugin({
|
|
155
|
+
terserOptions: {
|
|
156
|
+
format: {
|
|
157
|
+
// Turned on because emoji and regex is not minified properly using default
|
|
158
|
+
// https://github.com/facebook/create-react-app/issues/2488
|
|
159
|
+
ascii_only: true,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
output: {
|
|
166
|
+
filename: `[name].js`,
|
|
167
|
+
path: path.resolve(process.cwd(), "dist"),
|
|
168
|
+
clean: true,
|
|
169
|
+
},
|
|
170
|
+
plugins: [
|
|
171
|
+
new DefinePlugin({
|
|
172
|
+
BACKEND_HOST: JSON.stringify(backendHost),
|
|
173
|
+
}),
|
|
174
|
+
// Apps can only submit a single JS file via the developer portal
|
|
175
|
+
new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
176
|
+
],
|
|
177
|
+
...buildDevConfig(devConfig),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} [options]
|
|
184
|
+
* @param {number} [options.port]
|
|
185
|
+
* @param {boolean} [options.enableHmr]
|
|
186
|
+
* @param {boolean} [options.enableHttps]
|
|
187
|
+
* @param {string} [options.appOrigin]
|
|
188
|
+
* @param {string} [options.appId] - Deprecated in favour of appOrigin
|
|
189
|
+
* @param {string} [options.certFile]
|
|
190
|
+
* @param {string} [options.keyFile]
|
|
191
|
+
* @returns {Object|null}
|
|
192
|
+
*/
|
|
193
|
+
function buildDevConfig(options) {
|
|
194
|
+
if (!options) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const { port, enableHmr, appOrigin, appId, enableHttps, certFile, keyFile } =
|
|
199
|
+
options;
|
|
200
|
+
|
|
201
|
+
let devServer = {
|
|
202
|
+
server: enableHttps
|
|
203
|
+
? {
|
|
204
|
+
type: "https",
|
|
205
|
+
options: {
|
|
206
|
+
cert: certFile,
|
|
207
|
+
key: keyFile,
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
: "http",
|
|
211
|
+
host: "localhost",
|
|
212
|
+
historyApiFallback: {
|
|
213
|
+
rewrites: [{ from: /^\/$/, to: "/app.js" }],
|
|
214
|
+
},
|
|
215
|
+
port,
|
|
216
|
+
client: {
|
|
217
|
+
logging: "verbose",
|
|
218
|
+
},
|
|
219
|
+
static: {
|
|
220
|
+
directory: path.resolve(process.cwd(), "assets"),
|
|
221
|
+
publicPath: "/assets",
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
if (enableHmr && appOrigin) {
|
|
226
|
+
devServer = {
|
|
227
|
+
...devServer,
|
|
228
|
+
allowedHosts: new URL(appOrigin).hostname,
|
|
229
|
+
headers: {
|
|
230
|
+
"Access-Control-Allow-Origin": appOrigin,
|
|
231
|
+
"Access-Control-Allow-Credentials": "true",
|
|
232
|
+
"Access-Control-Allow-Private-Network": "true",
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
} else if (enableHmr && appId) {
|
|
236
|
+
// Deprecated - App ID should not be used to configure HMR in the future and can be safely removed
|
|
237
|
+
// after a few months.
|
|
238
|
+
|
|
239
|
+
console.warn(
|
|
240
|
+
"Enabling Hot Module Replacement (HMR) with an App ID is deprecated, please see the README.md on how to update.",
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const appDomain = `app-${appId.toLowerCase().trim()}.canva-apps.com`;
|
|
244
|
+
devServer = {
|
|
245
|
+
...devServer,
|
|
246
|
+
allowedHosts: appDomain,
|
|
247
|
+
headers: {
|
|
248
|
+
"Access-Control-Allow-Origin": `https://${appDomain}`,
|
|
249
|
+
"Access-Control-Allow-Credentials": "true",
|
|
250
|
+
"Access-Control-Allow-Private-Network": "true",
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
if (enableHmr && !appOrigin) {
|
|
255
|
+
console.warn(
|
|
256
|
+
"Attempted to enable Hot Module Replacement (HMR) without configuring App Origin... Disabling HMR.",
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
devServer.webSocketServer = false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
devtool: "source-map",
|
|
264
|
+
devServer,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
module.exports = () => buildConfig();
|
|
269
|
+
|
|
270
|
+
module.exports.buildConfig = buildConfig;
|