@superblocksteam/cli 0.0.11

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 (42) hide show
  1. package/README.md +175 -0
  2. package/assets/custom-components/.eslintrc.js +26 -0
  3. package/assets/custom-components/package.json +26 -0
  4. package/assets/custom-components/tsconfig.json +13 -0
  5. package/bin/dev +8 -0
  6. package/bin/dev.cmd +3 -0
  7. package/bin/run +8 -0
  8. package/bin/run.cmd +3 -0
  9. package/dist/commands/components/create.d.ts +5 -0
  10. package/dist/commands/components/create.js +146 -0
  11. package/dist/commands/components/register.d.ts +6 -0
  12. package/dist/commands/components/register.js +38 -0
  13. package/dist/commands/components/upload.d.ts +6 -0
  14. package/dist/commands/components/upload.js +151 -0
  15. package/dist/commands/components/watch.d.ts +7 -0
  16. package/dist/commands/components/watch.js +101 -0
  17. package/dist/commands/init.d.ts +15 -0
  18. package/dist/commands/init.js +238 -0
  19. package/dist/commands/login.d.ts +9 -0
  20. package/dist/commands/login.js +66 -0
  21. package/dist/commands/pull.d.ts +14 -0
  22. package/dist/commands/pull.js +167 -0
  23. package/dist/common/authenticated-command.d.ts +14 -0
  24. package/dist/common/authenticated-command.js +58 -0
  25. package/dist/common/defaults/create-component-defaults.d.ts +9 -0
  26. package/dist/common/defaults/create-component-defaults.js +60 -0
  27. package/dist/common/types.d.ts +7 -0
  28. package/dist/common/types.js +2 -0
  29. package/dist/common/version-control.d.ts +21 -0
  30. package/dist/common/version-control.js +166 -0
  31. package/dist/exportedTypes.d.ts +20 -0
  32. package/dist/exportedTypes.js +2 -0
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.js +7 -0
  35. package/dist/util/identifiers.d.ts +7 -0
  36. package/dist/util/identifiers.js +37 -0
  37. package/dist/util/prompt.d.ts +7 -0
  38. package/dist/util/prompt.js +33 -0
  39. package/dist/util/types.d.ts +9 -0
  40. package/dist/util/types.js +26 -0
  41. package/oclif.manifest.json +151 -0
  42. package/package.json +97 -0
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ @superblocksteam/cli
2
+ =================
3
+
4
+ <!-- toc -->
5
+ * [Usage](#usage)
6
+ * [Commands](#commands)
7
+ <!-- tocstop -->
8
+ # Usage
9
+ <!-- usage -->
10
+ ```sh-session
11
+ $ npm install -g @superblocksteam/cli
12
+ $ superblocks COMMAND
13
+ running command...
14
+ $ superblocks (--version)
15
+ @superblocksteam/cli/0.0.11 linux-x64 node-v18.16.1
16
+ $ superblocks --help [COMMAND]
17
+ USAGE
18
+ $ superblocks COMMAND
19
+ ...
20
+ ```
21
+ <!-- usagestop -->
22
+ # Commands
23
+ <!-- commands -->
24
+ * [`superblocks components create`](#superblocks-components-create)
25
+ * [`superblocks components register`](#superblocks-components-register)
26
+ * [`superblocks components upload`](#superblocks-components-upload)
27
+ * [`superblocks components watch`](#superblocks-components-watch)
28
+ * [`superblocks help [COMMANDS]`](#superblocks-help-commands)
29
+ * [`superblocks init [RESOURCEURL]`](#superblocks-init-resourceurl)
30
+ * [`superblocks login`](#superblocks-login)
31
+ * [`superblocks pull [ONLY]`](#superblocks-pull-only)
32
+
33
+ ## `superblocks components create`
34
+
35
+ Creates a new Superblocks component in the current application folder
36
+
37
+ ```
38
+ USAGE
39
+ $ superblocks components create
40
+
41
+ DESCRIPTION
42
+ Creates a new Superblocks component in the current application folder
43
+ ```
44
+
45
+ ## `superblocks components register`
46
+
47
+ Registers all local component config files
48
+
49
+ ```
50
+ USAGE
51
+ $ superblocks components register
52
+
53
+ DESCRIPTION
54
+ Registers all local component config files
55
+
56
+ EXAMPLES
57
+ $ superblocks components register
58
+ ```
59
+
60
+ ## `superblocks components upload`
61
+
62
+ Upload creates a production-ready bundle and saves the files for use outside of Local Development mode.
63
+
64
+ ```
65
+ USAGE
66
+ $ superblocks components upload
67
+
68
+ DESCRIPTION
69
+ Upload creates a production-ready bundle and saves the files for use outside of Local Development mode.
70
+
71
+ EXAMPLES
72
+ $ superblocks components upload
73
+ ```
74
+
75
+ ## `superblocks components watch`
76
+
77
+ watch for changes to your custom components
78
+
79
+ ```
80
+ USAGE
81
+ $ superblocks components watch
82
+
83
+ DESCRIPTION
84
+ watch for changes to your custom components
85
+ ```
86
+
87
+ ## `superblocks help [COMMANDS]`
88
+
89
+ Display help for superblocks.
90
+
91
+ ```
92
+ USAGE
93
+ $ superblocks help [COMMANDS] [-n]
94
+
95
+ ARGUMENTS
96
+ COMMANDS Command to show help for.
97
+
98
+ FLAGS
99
+ -n, --nested-commands Include all nested commands in the output.
100
+
101
+ DESCRIPTION
102
+ Display help for superblocks.
103
+ ```
104
+
105
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.10/src/commands/help.ts)_
106
+
107
+ ## `superblocks init [RESOURCEURL]`
108
+
109
+ Interactively configure the current directory as a Superblocks project or initialize new services in an already configured Superblocks project directory
110
+
111
+ ```
112
+ USAGE
113
+ $ superblocks init [RESOURCEURL] [-m live|latest|deployed]
114
+
115
+ ARGUMENTS
116
+ RESOURCEURL Superblocks resource URL (i.e. https://app.superblocks.com/applications/<application_id>/pages/<page_id>)
117
+
118
+ FLAGS
119
+ -m, --mode=<option> Pull mode
120
+ <options: live|latest|deployed>
121
+
122
+ DESCRIPTION
123
+ Interactively configure the current directory as a Superblocks project or initialize new services in an already
124
+ configured Superblocks project directory
125
+
126
+ EXAMPLES
127
+ $ superblocks init
128
+
129
+ $ superblocks init https://app.superblocks.com/applications/11111111-1111-1111-1111-111111111111/pages/22222222-2222-2222-2222-222222222222
130
+ ```
131
+
132
+ ## `superblocks login`
133
+
134
+ Authenticates with Superblocks cloud
135
+
136
+ ```
137
+ USAGE
138
+ $ superblocks login [-t <value>] [-b <value>]
139
+
140
+ FLAGS
141
+ -b, --superblocksBaseUrl=<value> Superblocks base URL
142
+ -t, --token=<value> Superblocks user access token
143
+
144
+ DESCRIPTION
145
+ Authenticates with Superblocks cloud
146
+ ```
147
+
148
+ ## `superblocks pull [ONLY]`
149
+
150
+ Download objects from Superblocks and save them locally
151
+
152
+ ```
153
+ USAGE
154
+ $ superblocks pull [ONLY] [-m live|latest|deployed]
155
+
156
+ ARGUMENTS
157
+ ONLY Superblocks resource location to pull (i.e. apps/my-app or backends/my-workflow)
158
+
159
+ FLAGS
160
+ -m, --mode=<option> Pull mode
161
+ <options: live|latest|deployed>
162
+
163
+ DESCRIPTION
164
+ Download objects from Superblocks and save them locally
165
+
166
+ EXAMPLES
167
+ $ superblocks pull
168
+
169
+ $ superblocks pull apps/my-app
170
+
171
+ $ superblocks pull backends/my-workflow
172
+
173
+ $ superblocks pull backends/my-scheduled-job
174
+ ```
175
+ <!-- commandsstop -->
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true,
5
+ },
6
+ extends: [
7
+ "plugin:@typescript-eslint/recommended",
8
+ "plugin:react/recommended",
9
+ "plugin:react/jsx-runtime",
10
+ "prettier",
11
+ "plugin:prettier/recommended",
12
+ ],
13
+ parserOptions: {
14
+ ecmaVersion: "latest",
15
+ sourceType: "module",
16
+ project: true,
17
+ },
18
+ plugins: ["react"],
19
+ rules: {},
20
+ settings: {
21
+ react: {
22
+ version: "detect",
23
+ },
24
+ },
25
+ ignorePatterns: [".eslintrc.js", "dist/", "node_modules/"],
26
+ };
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "superblocks-custom-components",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "scripts": {
6
+ "lint": "npx eslint .",
7
+ "lint:fix": "npx eslint . --fix"
8
+ },
9
+ "dependencies": {},
10
+ "peerDependencies": {
11
+ "react": "^17",
12
+ "react-dom": "^17"
13
+ },
14
+ "devDependencies": {
15
+ "@superblocksteam/cli": "0.0.11",
16
+ "@types/react": "^17",
17
+ "@types/react-dom": "^17",
18
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
19
+ "eslint": "^8.45.0",
20
+ "eslint-config-prettier": "^8.8.0",
21
+ "eslint-plugin-prettier": "^5.0.0",
22
+ "eslint-plugin-react": "^7.32.2",
23
+ "prettier": "3.0.0",
24
+ "typescript": "^5.1.6"
25
+ }
26
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "noEmit": true,
4
+ "importHelpers": true,
5
+ "module": "CommonJS",
6
+ "strict": true,
7
+ "target": "es2019",
8
+ "lib": ["dom", "es2015", "es2019"],
9
+ "esModuleInterop": true,
10
+ "jsx": "react-jsxdev",
11
+ },
12
+ "include": ["components/**/*"],
13
+ }
package/bin/dev ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ // eslint-disable-next-line node/shebang
4
+ (async () => {
5
+ const oclif = await import("@oclif/core");
6
+ // eslint-disable-next-line unicorn/prefer-module
7
+ await oclif.execute({ type: "cjs", development: true, dir: __dirname });
8
+ })();
package/bin/dev.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\dev" %*
package/bin/run ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ // eslint-disable-next-line node/shebang
4
+ (async () => {
5
+ const oclif = await import("@oclif/core");
6
+ // eslint-disable-next-line unicorn/prefer-module
7
+ await oclif.execute({ type: "cjs", dir: __dirname });
8
+ })();
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
@@ -0,0 +1,5 @@
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
2
+ export default class CreateComponent extends AuthenticatedApplicationCommand {
3
+ static description: string;
4
+ run(): Promise<void>;
5
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /* eslint-disable no-await-in-loop */
5
+ const node_child_process_1 = require("node:child_process");
6
+ const node_crypto_1 = require("node:crypto");
7
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
+ const node_util_1 = tslib_1.__importDefault(require("node:util"));
9
+ const core_1 = require("@oclif/core");
10
+ const util_1 = require("@superblocksteam/util");
11
+ const colorette_1 = require("colorette");
12
+ const fs = tslib_1.__importStar(require("fs-extra"));
13
+ const listr2_1 = require("listr2");
14
+ const authenticated_command_1 = require("../../common/authenticated-command");
15
+ const create_component_defaults_1 = require("../../common/defaults/create-component-defaults");
16
+ const identifiers_1 = require("../../util/identifiers");
17
+ const prompt_1 = require("../../util/prompt");
18
+ const types_1 = require("../../util/types");
19
+ // eslint-disable-next-line unicorn/prefer-module
20
+ const rootDirectory = node_path_1.default.resolve(__dirname, "../../../");
21
+ const DEFAULT_PACKAGE_JSON_TEMPLATE_PATH = node_path_1.default.resolve(rootDirectory, "assets/custom-components");
22
+ const tsStringify = (obj) => {
23
+ const entries = Object.entries(obj);
24
+ const stringifiedEntries = entries.map(([key, value]) => {
25
+ return `${key}: ${value === undefined ? "undefined" : JSON.stringify(value)}`;
26
+ });
27
+ return `{\n${stringifiedEntries.join(",\n")}\n},\n`;
28
+ };
29
+ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCommand {
30
+ async run() {
31
+ var _a;
32
+ const displayName = await core_1.ux.prompt("What is the display name of the component you want to create? (e.g. Date Picker)");
33
+ const name = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the component you want to create?", { default: (0, identifiers_1.suggestIdentifier)(displayName, true) || "DatePicker" }, (response) => (0, identifiers_1.isValidIdentifier)(response) || "Invalid identifier");
34
+ this.log();
35
+ const hasStatefulProps = await core_1.ux.confirm("Does this component have stateful props? (e.g. a date picker component that has a selected date prop) [y/n]");
36
+ const statefulProps = [];
37
+ if (hasStatefulProps) {
38
+ for (;;) {
39
+ const statefulPropName = await core_1.ux.prompt("What is the label of the stateful prop? (e.g. Selected Date)");
40
+ const statefulPropPath = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the stateful prop?", { default: (0, identifiers_1.suggestIdentifier)(statefulPropName) || "selectedDate" }, (response) => {
41
+ if (!(0, identifiers_1.isValidIdentifier)(response))
42
+ return "Invalid identifier";
43
+ if (statefulProps.some((v) => v.path === response))
44
+ return "Duplicate property name";
45
+ return true;
46
+ });
47
+ const task = new listr2_1.Listr({
48
+ task: async (ctx, task) => {
49
+ ctx.inputType = await task.prompt({
50
+ type: "Select",
51
+ message: `What input type should ${statefulPropName} be?`,
52
+ choices: Object.values(types_1.inputTypeDefinions).map((v) => v.prompt),
53
+ initial: 0,
54
+ });
55
+ },
56
+ });
57
+ const runContext = await task.run();
58
+ const statefulPropType = (_a = Object.entries(types_1.inputTypeDefinions).find(([, v]) => v.prompt === runContext.inputType)) === null || _a === void 0 ? void 0 : _a[0];
59
+ const placeholderText = await core_1.ux.prompt(`What placeholder text should ${statefulPropName} have, if any?`, { required: false });
60
+ statefulProps.push({
61
+ label: statefulPropName,
62
+ path: statefulPropPath,
63
+ inputType: statefulPropType,
64
+ placeholder: placeholderText || undefined,
65
+ });
66
+ const addAnotherStatefulProp = await core_1.ux.confirm("Do you want to add another stateful prop? [y/n]");
67
+ if (!addAnotherStatefulProp) {
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ this.log();
73
+ const hasEventHandlers = await core_1.ux.confirm("Does this component have event handlers? (e.g. a date picker component that has a On Change event handler) [y/n]");
74
+ const eventHandlers = [];
75
+ if (hasEventHandlers) {
76
+ for (;;) {
77
+ const eventHandlerName = await core_1.ux.prompt("What is the label of the event handler? (e.g. On Change)");
78
+ const eventHandlerPath = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the event handler?", { default: (0, identifiers_1.suggestIdentifier)(eventHandlerName) || "onChange" }, (response) => {
79
+ if (!(0, identifiers_1.isValidIdentifier)(response))
80
+ return "Invalid identifier";
81
+ if (eventHandlers.some((v) => v.path === response))
82
+ return "Duplicate property name";
83
+ return true;
84
+ });
85
+ eventHandlers.push({
86
+ label: eventHandlerName,
87
+ path: eventHandlerPath,
88
+ });
89
+ const addAnotherEventHandler = await core_1.ux.confirm("Do you want to add another event handler? [y/n]");
90
+ if (!addAnotherEventHandler) {
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ const configTs = (0, create_component_defaults_1.getDefaultConfigTs)({
96
+ id: (0, node_crypto_1.randomUUID)(),
97
+ name,
98
+ displayName,
99
+ statefulPropsRendered: statefulProps
100
+ .map((statefulProp) => tsStringify(statefulProp))
101
+ .join(""),
102
+ eventHandlersRendered: eventHandlers
103
+ .map((eventHandler) => tsStringify(eventHandler))
104
+ .join(""),
105
+ });
106
+ const componentTsx = (0, create_component_defaults_1.getDefaultComponentTsx)(statefulProps, eventHandlers.map((prop) => prop.path));
107
+ const packageJsonExists = await fs.exists("package.json");
108
+ if (!packageJsonExists) {
109
+ await fs.copy(DEFAULT_PACKAGE_JSON_TEMPLATE_PATH, ".");
110
+ }
111
+ await fs.ensureDir("components/" + name);
112
+ await fs.writeFile(`components/${name}/config.ts`, configTs);
113
+ await fs.writeFile(`components/${name}/component.tsx`, componentTsx);
114
+ this.log((0, colorette_1.green)("Successfully created component! Added the following files:"));
115
+ this.log();
116
+ const tree = core_1.ux.tree();
117
+ tree.insert("components");
118
+ tree.nodes.components.insert(name);
119
+ tree.nodes.components.nodes[name].insert("config.ts # update this file to configure your component's properties panel");
120
+ tree.nodes.components.nodes[name].insert("component.tsx # your component's react code");
121
+ tree.display();
122
+ this.log();
123
+ this.log(`${(0, colorette_1.green)("Remember to run $ ")}${(0, colorette_1.cyan)("superblocks components watch")}${(0, colorette_1.green)(" to watch for changes to your component files")}`);
124
+ this.log();
125
+ this.log(`Edit your component's react code here:
126
+ ${(0, colorette_1.green)(`components/${name}/component.tsx`)}`);
127
+ this.log();
128
+ if (!packageJsonExists) {
129
+ core_1.ux.action.start("Installing dependencies...");
130
+ try {
131
+ await node_util_1.default.promisify(node_child_process_1.exec)("npm i");
132
+ }
133
+ catch {
134
+ core_1.ux.action.stop();
135
+ this.error((0, colorette_1.red)("Failed to install dependencies. Please run 'npm install' manually."));
136
+ }
137
+ core_1.ux.action.stop();
138
+ }
139
+ core_1.ux.action.start("Registering components...");
140
+ const components = await (0, util_1.getComponentConfigs)();
141
+ await this.getSdk().registerComponents(this.applicationConfig.id, components);
142
+ core_1.ux.action.stop();
143
+ }
144
+ }
145
+ CreateComponent.description = "Creates a new Superblocks component in the current application folder";
146
+ exports.default = CreateComponent;
@@ -0,0 +1,6 @@
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
2
+ export default class Register extends AuthenticatedApplicationCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const util_1 = require("@superblocksteam/util");
6
+ const fs = tslib_1.__importStar(require("fs-extra"));
7
+ const authenticated_command_1 = require("../../common/authenticated-command");
8
+ class Register extends authenticated_command_1.AuthenticatedApplicationCommand {
9
+ async run() {
10
+ core_1.ux.action.start("Scanning for Superblocks components...");
11
+ const exists = await fs.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
12
+ if (!exists) {
13
+ core_1.ux.action.stop();
14
+ this.error("No components folder found in current directory, please run 'superblocks components create' first", {
15
+ exit: 1,
16
+ });
17
+ }
18
+ const configs = await (0, util_1.getComponentConfigs)();
19
+ if (configs.length === 0) {
20
+ core_1.ux.action.stop();
21
+ this.log("No components found in current components directory, please run 'superblocks components create' first");
22
+ }
23
+ core_1.ux.action.stop();
24
+ this.log(JSON.stringify(configs, null, 2));
25
+ try {
26
+ core_1.ux.action.start("Registering components...");
27
+ await this.getSdk().registerComponents(this.applicationConfig.id, configs);
28
+ core_1.ux.action.stop();
29
+ }
30
+ catch {
31
+ core_1.ux.action.stop();
32
+ this.error("Failed to register components", { exit: 1 });
33
+ }
34
+ }
35
+ }
36
+ Register.description = "Registers all local component config files";
37
+ Register.examples = ["superblocks components register"];
38
+ exports.default = Register;
@@ -0,0 +1,6 @@
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
2
+ export default class Upload extends AuthenticatedApplicationCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const node_http_1 = tslib_1.__importDefault(require("node:http"));
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const core_1 = require("@oclif/core");
7
+ const util_1 = require("@superblocksteam/util");
8
+ const plugin_react_1 = tslib_1.__importDefault(require("@vitejs/plugin-react"));
9
+ const fs = tslib_1.__importStar(require("fs-extra"));
10
+ const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
11
+ const vite_1 = require("vite");
12
+ const vite_plugin_externals_1 = require("vite-plugin-externals");
13
+ const authenticated_command_1 = require("../../common/authenticated-command");
14
+ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
15
+ async run() {
16
+ core_1.ux.action.start("Scanning for Superblocks components...");
17
+ const exists = await fs.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
18
+ if (!exists) {
19
+ core_1.ux.action.stop();
20
+ this.error("No components folder found in current directory, please run 'superblocks components create' first", {
21
+ exit: 1,
22
+ });
23
+ }
24
+ const configs = await (0, util_1.getComponentConfigs)();
25
+ if (configs.length === 0) {
26
+ core_1.ux.action.stop();
27
+ this.log("No components found in current components directory, please run 'superblocks components create' first");
28
+ }
29
+ core_1.ux.action.stop();
30
+ try {
31
+ core_1.ux.action.start("Registering components...");
32
+ await this.getSdk().registerComponents(this.applicationConfig.id, configs);
33
+ core_1.ux.action.stop();
34
+ }
35
+ catch (e) {
36
+ core_1.ux.action.stop();
37
+ this.log(e.message);
38
+ this.error("Failed to register components", { exit: 1 });
39
+ }
40
+ // Map component name to component path- each name is a separate entry point
41
+ const entryFiles = Object.fromEntries(Object.values(configs).map((config) => [
42
+ config.name,
43
+ config.componentPath,
44
+ ]));
45
+ const viteLogger = (0, vite_1.createLogger)();
46
+ viteLogger.info = (message) => {
47
+ this.log(message);
48
+ };
49
+ core_1.ux.action.start("Building components...");
50
+ await (async () => {
51
+ await (0, vite_1.build)({
52
+ configFile: false,
53
+ build: {
54
+ rollupOptions: {
55
+ input: entryFiles,
56
+ preserveEntrySignatures: "strict",
57
+ output: {
58
+ entryFileNames: "[name].js",
59
+ sourcemap: true,
60
+ },
61
+ },
62
+ copyPublicDir: true,
63
+ write: true,
64
+ },
65
+ customLogger: viteLogger,
66
+ plugins: [
67
+ (0, plugin_react_1.default)(),
68
+ (0, vite_plugin_externals_1.viteExternalsPlugin)({
69
+ react: "React",
70
+ "react-dom": "ReactDOM",
71
+ }),
72
+ ],
73
+ });
74
+ })();
75
+ core_1.ux.action.stop();
76
+ /*
77
+ 1. Build
78
+ 2. Get S3 prefix
79
+ 3. Upload to S3
80
+ 4. Update DSL with new prefix
81
+ 5. Auto-commit DSL
82
+ */
83
+ try {
84
+ core_1.ux.action.start("Uploading components...");
85
+ const fileRelativePaths = [];
86
+ const excluded = [
87
+ ".superblocks",
88
+ "node_modules",
89
+ "apis",
90
+ "page.yaml",
91
+ "application.yaml",
92
+ ];
93
+ await walkThroughDirectory(".", fileRelativePaths, excluded);
94
+ this.log(fileRelativePaths.join("\n"));
95
+ await this.getSdk().uploadComponents(this.applicationConfig.id, configs, fileRelativePaths);
96
+ core_1.ux.action.stop();
97
+ }
98
+ catch (e) {
99
+ core_1.ux.action.stop();
100
+ this.log(e.message);
101
+ this.error("Failed to upload components", { exit: 1 });
102
+ }
103
+ this.log("For testing purposes, the production assets will be served from this machine.");
104
+ const server = node_http_1.default.createServer((request, response) => {
105
+ // You pass two more arguments for config and middleware
106
+ // More details here: https://github.com/vercel/serve-handler#options
107
+ return (0, serve_handler_1.default)(request, response, {
108
+ public: "./",
109
+ headers: [
110
+ {
111
+ source: "**/*",
112
+ headers: [
113
+ {
114
+ key: "Access-Control-Allow-Origin",
115
+ value: "*",
116
+ },
117
+ {
118
+ key: "Access-Control-Allow-Credentials",
119
+ value: "true",
120
+ },
121
+ {
122
+ key: "Access-Control-Allow-Private-Network",
123
+ value: "true",
124
+ },
125
+ ],
126
+ },
127
+ ],
128
+ });
129
+ });
130
+ server.listen(3030, () => {
131
+ console.log("Running asset server at http://localhost:3030");
132
+ });
133
+ }
134
+ }
135
+ Upload.description = "Upload creates a production-ready bundle and saves the files for use outside of Local Development mode.";
136
+ Upload.examples = ["<%= config.bin %> components upload"];
137
+ exports.default = Upload;
138
+ async function walkThroughDirectory(directory, mutableFiles, excluded) {
139
+ const files = await fs.readdir(directory);
140
+ for (const file of files) {
141
+ if (excluded.includes(file))
142
+ return;
143
+ const absolute = path_1.default.join(directory, file);
144
+ if ((await fs.stat(absolute)).isDirectory()) {
145
+ await walkThroughDirectory(absolute, mutableFiles, excluded);
146
+ }
147
+ else {
148
+ mutableFiles.push(absolute);
149
+ }
150
+ }
151
+ }
@@ -0,0 +1,7 @@
1
+ import { Plugin } from "vite";
2
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
3
+ export declare function healthEndpointMiddleware(): Plugin;
4
+ export default class Watch extends AuthenticatedApplicationCommand {
5
+ static description: string;
6
+ run(): Promise<void>;
7
+ }