@stacksjs/actions 0.59.11 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/add.js +29 -0
  2. package/dist/build/component-libs.js +9 -0
  3. package/dist/build/core.js +21 -0
  4. package/dist/build/stacks.js +8 -0
  5. package/dist/build.js +317 -0
  6. package/dist/bump.js +16 -0
  7. package/dist/changelog.js +17 -0
  8. package/dist/clean.js +6 -0
  9. package/dist/commit.js +17 -0
  10. package/dist/copy-types.js +14 -0
  11. package/dist/database/seed.js +8 -0
  12. package/dist/deploy/index.js +31 -0
  13. package/dist/dev/components.js +11 -0
  14. package/dist/dev/docs.js +7 -0
  15. package/dist/dev/index.js +112 -0
  16. package/dist/examples.js +43 -0
  17. package/dist/fresh.js +19 -0
  18. package/dist/generate/component-meta.js +59 -0
  19. package/dist/generate/ide-helpers.js +96 -0
  20. package/dist/generate/index.js +251 -0
  21. package/dist/generate/lib-entries.js +175 -0
  22. package/dist/generate/vscode-custom-data.js +96 -0
  23. package/dist/helpers/component-meta.js +50 -0
  24. package/dist/helpers/lib-entries.js +166 -0
  25. package/dist/helpers/package-json.js +146 -0
  26. package/dist/helpers/utils.js +67 -0
  27. package/dist/helpers/vscode-custom-data.js +88 -0
  28. package/dist/index.js +676 -0
  29. package/dist/key-generate.js +10 -0
  30. package/dist/lint/fix.js +12 -0
  31. package/dist/lint/index.js +16 -0
  32. package/dist/make.js +319 -0
  33. package/dist/prepublish.js +17 -0
  34. package/dist/release.js +646 -0
  35. package/dist/test/coverage.js +9 -0
  36. package/dist/test/feature.js +9 -0
  37. package/dist/test/ui.js +6 -0
  38. package/dist/test/unit.js +6 -0
  39. package/dist/test.js +6 -0
  40. package/dist/typecheck.js +6 -0
  41. package/dist/types.js +21 -0
  42. package/dist/upgrade/dependencies.js +6 -0
  43. package/dist/upgrade/framework.js +1 -0
  44. package/dist/upgrade/index.js +78 -0
  45. package/dist/upgrade.js +46 -0
  46. package/package.json +5 -5
  47. package/src/action.ts +1 -0
  48. package/src/actions.ts +2 -2
  49. package/src/add.ts +3 -6
  50. package/src/ai/request-model-access.ts +10 -7
  51. package/src/build/component-libs.ts +5 -2
  52. package/src/build/core.ts +1 -2
  53. package/src/build/stacks.ts +8 -5
  54. package/src/build.ts +11 -25
  55. package/src/bump.ts +0 -2
  56. package/src/check/ports.ts +2 -3
  57. package/src/commit.ts +2 -2
  58. package/src/copy-types.ts +1 -1
  59. package/src/database/seed.ts +8 -4
  60. package/src/deploy/create-receipt-rule.ts +3 -7
  61. package/src/deploy/index.ts +2 -1
  62. package/src/dev/api.ts +4 -4
  63. package/src/dev/components.ts +3 -5
  64. package/src/dev/index.ts +2 -2
  65. package/src/domains/add.ts +8 -6
  66. package/src/domains/purchase.ts +26 -24
  67. package/src/domains/remove.ts +5 -7
  68. package/src/examples.ts +9 -13
  69. package/src/find-projects.ts +4 -6
  70. package/src/fresh.ts +2 -1
  71. package/src/generate/action-types.ts +5 -7
  72. package/src/generate/component-meta.ts +2 -5
  73. package/src/generate/custom-cli-file.ts +4 -3
  74. package/src/generate/env-files.ts +38 -43
  75. package/src/generate/ide-helpers.ts +1 -2
  76. package/src/generate/index.ts +16 -40
  77. package/src/generate/lib-entries.ts +4 -7
  78. package/src/generate/pkgx-file.ts +6 -11
  79. package/src/generate/vscode-custom-data.ts +1 -3
  80. package/src/helpers/component-meta.ts +6 -11
  81. package/src/helpers/index.ts +5 -0
  82. package/src/helpers/lib-entries.ts +30 -25
  83. package/src/helpers/package-json.ts +13 -16
  84. package/src/helpers/utils.ts +56 -13
  85. package/src/helpers/vscode-custom-data.ts +1 -2
  86. package/src/index.ts +2 -1
  87. package/src/key-generate.ts +3 -4
  88. package/src/lint/fix.ts +10 -2
  89. package/src/lint/index.ts +6 -8
  90. package/src/make.ts +79 -77
  91. package/src/migrate/database.ts +22 -1
  92. package/src/migrate/fresh.ts +20 -0
  93. package/src/orm/base.ts +0 -0
  94. package/src/orm/generate-model.ts +1177 -0
  95. package/src/{generate/model-classes.ts → orm/user.ts} +33 -48
  96. package/src/prepublish.ts +5 -2
  97. package/src/release.ts +15 -11
  98. package/src/test/coverage.ts +5 -2
  99. package/src/test/feature.ts +5 -2
  100. package/src/test/ui.ts +1 -1
  101. package/src/test/unit.ts +1 -1
  102. package/src/test.ts +1 -1
  103. package/src/typecheck.ts +1 -1
  104. package/src/types.ts +2 -2
  105. package/src/upgrade/binary.ts +3 -5
  106. package/src/upgrade/index.ts +4 -8
  107. package/src/upgrade/shell.ts +10 -10
  108. package/src/upgrade.ts +28 -25
  109. package/dist/action.d.ts +0 -36
  110. package/dist/add.d.ts +0 -6
  111. package/dist/build/component-libs.d.ts +0 -1
  112. package/dist/build/core.d.ts +0 -1
  113. package/dist/build/stacks.d.ts +0 -1
  114. package/dist/build.d.ts +0 -9
  115. package/dist/bump.d.ts +0 -1
  116. package/dist/changelog.d.ts +0 -1
  117. package/dist/clean.d.ts +0 -1
  118. package/dist/commit.d.ts +0 -3
  119. package/dist/copy-types.d.ts +0 -5
  120. package/dist/database/seed.d.ts +0 -1
  121. package/dist/deploy/index.d.ts +0 -1
  122. package/dist/dev/components.d.ts +0 -1
  123. package/dist/dev/docs.d.ts +0 -1
  124. package/dist/dev/index.d.ts +0 -10
  125. package/dist/examples.d.ts +0 -5
  126. package/dist/fresh.d.ts +0 -1
  127. package/dist/generate/component-meta.d.ts +0 -5
  128. package/dist/generate/ide-helpers.d.ts +0 -6
  129. package/dist/generate/index.d.ts +0 -13
  130. package/dist/generate/lib-entries.d.ts +0 -2
  131. package/dist/generate/vscode-custom-data.d.ts +0 -6
  132. package/dist/helpers/component-meta.d.ts +0 -22
  133. package/dist/helpers/lib-entries.d.ts +0 -13
  134. package/dist/helpers/package-json.d.ts +0 -3
  135. package/dist/helpers/utils.d.ts +0 -18
  136. package/dist/helpers/vscode-custom-data.d.ts +0 -2
  137. package/dist/index.d.ts +0 -7
  138. package/dist/key-generate.d.ts +0 -1
  139. package/dist/lint/fix.d.ts +0 -1
  140. package/dist/lint/index.d.ts +0 -1
  141. package/dist/make.d.ts +0 -20
  142. package/dist/prepublish.d.ts +0 -1
  143. package/dist/release.d.ts +0 -2
  144. package/dist/test/coverage.d.ts +0 -1
  145. package/dist/test/feature.d.ts +0 -1
  146. package/dist/test/ui.d.ts +0 -1
  147. package/dist/test/unit.d.ts +0 -1
  148. package/dist/test.d.ts +0 -1
  149. package/dist/tinker.d.ts +0 -1
  150. package/dist/typecheck.d.ts +0 -1
  151. package/dist/types.d.ts +0 -3
  152. package/dist/upgrade/dependencies.d.ts +0 -1
  153. package/dist/upgrade/framework.d.ts +0 -1
  154. package/dist/upgrade/index.d.ts +0 -1
  155. package/dist/upgrade.d.ts +0 -4
  156. package/src/database/fields.ts +0 -111
  157. package/src/database/migration-mysql.ts +0 -72
  158. package/src/database/migration-sqlite.ts +0 -67
  159. package/src/database/migration.ts +0 -10
  160. package/src/database/user-migration.ts +0 -20
  161. package/src/generate/model-generate.ts +0 -12
  162. package/src/migrate/dns.ts +0 -3
  163. package/src/tinker.ts +0 -10
package/dist/index.js ADDED
@@ -0,0 +1,676 @@
1
+ // @bun
2
+ // src/helpers/utils.ts
3
+ import {buddyOptions, runCommand, runCommands} from "@stacksjs/cli";
4
+ import {err} from "@stacksjs/error-handling";
5
+ import {log} from "@stacksjs/logging";
6
+ import * as p from "@stacksjs/path";
7
+ import {glob} from "@stacksjs/storage";
8
+ var {Glob } = globalThis.Bun;
9
+ async function runAction(action, options) {
10
+ const glob2 = new Glob("**/*.ts");
11
+ const scanOptions = { cwd: p.userActionsPath(), onlyFiles: true };
12
+ for await (const file of glob2.scan(scanOptions)) {
13
+ log.debug("file", file);
14
+ if (file === `${action}.ts` || file.endsWith(`${action}.ts`))
15
+ return (await import(p.userActionsPath(file))).default.handle();
16
+ const a = await import(p.userActionsPath(file));
17
+ if (a.name === action)
18
+ return await a.handle();
19
+ }
20
+ const opts = buddyOptions();
21
+ const path = p.relativeActionsPath(`src/${action}.ts`);
22
+ const cmd = `bun --bun ${path} ${opts}`.trimEnd();
23
+ const optionsWithCwd = {
24
+ cwd: options?.cwd || p.projectPath(),
25
+ ...options
26
+ };
27
+ log.debug("runAction:", cmd);
28
+ log.debug("action options:", optionsWithCwd);
29
+ return await runCommand(cmd, optionsWithCwd);
30
+ }
31
+ async function runActions(actions, options) {
32
+ log.debug("runActions:", actions, options);
33
+ if (!actions.length)
34
+ return err("No actions were specified");
35
+ for (const action of actions) {
36
+ log.debug(`running action "${action}"`);
37
+ if (!hasAction(action))
38
+ return err(`The specified action "${action}" does not exist`);
39
+ }
40
+ const opts = buddyOptions();
41
+ const o = {
42
+ cwd: options?.cwd || p.projectPath(),
43
+ ...options
44
+ };
45
+ const commands = actions.map((action) => `bun --bun ${p.relativeActionsPath(`src/${action}.ts`)} ${opts}`);
46
+ log.debug("commands:", commands);
47
+ return await runCommands(commands, o);
48
+ }
49
+ function hasAction(action) {
50
+ const userActionPatterns = [
51
+ `${action}.ts`,
52
+ `${action}`,
53
+ `Dashboard/${action}.ts`,
54
+ `Dashboard/${action}`,
55
+ `Buddy/${action}.ts`,
56
+ `Buddy/${action}`
57
+ ];
58
+ const actionPatterns = [`src/${action}.ts`, `src/${action}`, `${action}.ts`, `${action}`];
59
+ const userActionFiles = glob.sync(userActionPatterns.map((pattern) => p.userActionsPath(pattern)));
60
+ const actionFiles = glob.sync(actionPatterns.map((pattern) => p.actionsPath(pattern)));
61
+ return userActionFiles.length > 0 || actionFiles.length > 0;
62
+ }
63
+
64
+ // src/dev/index.ts
65
+ import {Action} from "@stacksjs/enums";
66
+ import {log as log2} from "@stacksjs/logging";
67
+ async function runDevServer(options) {
68
+ log2.info("Starting your Frontend Engine...");
69
+ await runAction(Action.Dev, options);
70
+ }
71
+ async function runFrontendDevServer(options) {
72
+ log2.info("Starting your UI Engine...");
73
+ await runAction(Action.Dev, options);
74
+ }
75
+ async function runBackendDevServer(options) {
76
+ runApiDevServer(options);
77
+ }
78
+ async function runApiDevServer(options) {
79
+ log2.info("Starting your API...");
80
+ await runAction(Action.DevApi, options);
81
+ }
82
+ async function runComponentsDevServer(options) {
83
+ log2.info("Starting your Library Engine...");
84
+ await runAction(Action.DevComponents, options);
85
+ }
86
+ async function runDashboardDevServer(options) {
87
+ log2.info("Starting your Dashboard...");
88
+ await runAction(Action.DevDashboard, options);
89
+ }
90
+ async function runSystemTrayDevServer(options) {
91
+ log2.info("Starting your System Tray...");
92
+ await runAction(Action.DevSystemTray, options);
93
+ }
94
+ async function runDesktopDevServer(options) {
95
+ log2.info("Starting your Desktop Engine...");
96
+ await runAction(Action.DevDesktop, options);
97
+ }
98
+ async function runDocsDevServer(options) {
99
+ log2.info("Starting your Docs Engine...");
100
+ await runAction(Action.DevDocs, options);
101
+ }
102
+
103
+ // src/helpers/vscode-custom-data.ts
104
+ import {log as log3} from "@stacksjs/logging";
105
+ import {customElementsDataPath} from "@stacksjs/path";
106
+ import {writeTextFile} from "@stacksjs/storage";
107
+
108
+ // ../../../../config/library.ts
109
+ var library_default = {
110
+ name: "hello-world",
111
+ owner: "@stacksjs",
112
+ repository: "stacksjs/stacks",
113
+ license: "MIT",
114
+ author: "Chris Breuer",
115
+ contributors: ["Chris Breuer <chris@stacksjs.org>"],
116
+ defaultLanguage: "en",
117
+ releaseable: true,
118
+ vueComponents: {
119
+ name: "hello-world-vue",
120
+ description: "Your Vue component library description",
121
+ keywords: ["component", "library", "vue", "vite", "typescript", "javascript"],
122
+ tags: [
123
+ {
124
+ name: ["HelloWorld", "AppHelloWorld"],
125
+ description: "The Hello World custom element, built via this framework.",
126
+ attributes: [
127
+ {
128
+ name: "greeting",
129
+ description: "The greeting."
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ },
135
+ webComponents: {
136
+ name: "hello-world-elements",
137
+ description: "Your framework agnostic web component library description.",
138
+ keywords: ["custom-elements", "web-components", "library", "framework-agnostic", "typescript", "javascript"],
139
+ tags: [
140
+ {
141
+ name: ["HelloWorld", "AppHelloWorld"],
142
+ description: "The Hello World custom element, built via this framework.",
143
+ attributes: [
144
+ {
145
+ name: "greeting",
146
+ description: "The greeting."
147
+ }
148
+ ]
149
+ }
150
+ ]
151
+ },
152
+ functions: {
153
+ name: "hello-world-fx",
154
+ description: "Your function library description.",
155
+ keywords: ["functions", "composables", "library", "typescript", "javascript"],
156
+ shouldGenerateSourcemap: false,
157
+ files: ["counter", "dark"]
158
+ }
159
+ };
160
+
161
+ // src/helpers/vscode-custom-data.ts
162
+ async function generateVsCodeCustomData() {
163
+ try {
164
+ log3.info("Generating custom-elements.json...");
165
+ await writeTextFile({
166
+ path: customElementsDataPath(),
167
+ data: generateComponentInfoData()
168
+ });
169
+ log3.success("Generated custom-elements.json for IDEs.");
170
+ } catch (err2) {
171
+ log3.error("There was an error generating the custom-elements.json file.", err2);
172
+ }
173
+ }
174
+ async function generateWebTypes() {
175
+ log3.info("Generating web-types.json...");
176
+ log3.info("This feature is not yet implemented.");
177
+ }
178
+ var generateComponentInfoData = function() {
179
+ const componentsData = JSON.stringify(library_default.vueComponents?.tags);
180
+ return `{
181
+ "version": 1.1,
182
+ "tags": ${componentsData}
183
+ }
184
+ `;
185
+ };
186
+
187
+ // src/generate/index.ts
188
+ import process from "process";
189
+ import {runCommand as runCommand2} from "@stacksjs/cli";
190
+ import {Action as Action2, NpmScript} from "@stacksjs/enums";
191
+ import {log as log4} from "@stacksjs/logging";
192
+ import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
193
+ import {runNpmScript} from "@stacksjs/utils";
194
+ async function invoke(options) {
195
+ if (options?.types)
196
+ await generateTypes(options);
197
+ else if (options?.entries)
198
+ await generateLibEntries(options);
199
+ else if (options?.webTypes)
200
+ await generateWebTypes2(options);
201
+ else if (options?.customData)
202
+ await generateVsCodeCustomData2(options);
203
+ else if (options?.ideHelpers)
204
+ await generateIdeHelpers(options);
205
+ else if (options?.componentMeta)
206
+ await generateComponentMeta(options);
207
+ else if (options?.coreSymlink)
208
+ await generateCoreSymlink();
209
+ }
210
+ function generate(options) {
211
+ return invoke(options);
212
+ }
213
+ async function generateLibEntries(options) {
214
+ const result = await runAction(Action2.GenerateLibraryEntries, {
215
+ ...options,
216
+ cwd: projectPath2()
217
+ });
218
+ if (result.isErr()) {
219
+ log4.error("There was an error generating your library entry points", result.error);
220
+ process.exit();
221
+ }
222
+ log4.success("Library entry points generated successfully");
223
+ }
224
+ async function generateWebTypes2(options) {
225
+ const result = await runNpmScript(NpmScript.GenerateWebTypes, options);
226
+ if (result.isErr()) {
227
+ log4.error("There was an error generating the web-types.json file.", result.error);
228
+ process.exit();
229
+ }
230
+ log4.success("Successfully generated the web-types.json file");
231
+ }
232
+ async function generateVsCodeCustomData2(options) {
233
+ const result = await generateVsCodeCustomData();
234
+ if (result.isErr()) {
235
+ log4.error("There was an error generating the custom-elements.json file.", result.error);
236
+ process.exit();
237
+ }
238
+ await runAction(Action2.LintFix, { verbose: true });
239
+ log4.success("Successfully generated the custom-elements.json file");
240
+ }
241
+ async function generateIdeHelpers(options) {
242
+ const result = await runNpmScript(NpmScript.GenerateIdeHelpers, options);
243
+ if (result.isErr()) {
244
+ log4.error("There was an error generating IDE helpers.", result.error);
245
+ process.exit();
246
+ }
247
+ await runAction(Action2.LintFix, { verbose: true });
248
+ log4.success("Successfully generated IDE helpers");
249
+ }
250
+ async function generateComponentMeta(options) {
251
+ const result = await generateVsCodeCustomData();
252
+ if (result.isErr()) {
253
+ log4.error("There was an error generating your component meta information.", result.error);
254
+ process.exit();
255
+ }
256
+ await runAction(Action2.LintFix, { verbose: true });
257
+ log4.success("Successfully generated component meta information");
258
+ }
259
+ async function generateTypes(options) {
260
+ const result = await runNpmScript(NpmScript.GenerateTypes, {
261
+ cwd: frameworkPath(),
262
+ ...options
263
+ });
264
+ if (result.isErr()) {
265
+ log4.error("There was an error generating your types.", result.error);
266
+ process.exit();
267
+ }
268
+ log4.success("Types were generated successfully");
269
+ }
270
+ function generatePkgxConfig() {
271
+ log4.success("Successfully generated `./pkgx.yaml` based on your config");
272
+ }
273
+ async function generateSeeder() {
274
+ }
275
+ async function generateCoreSymlink() {
276
+ await runCommand2(`ln -s ${frameworkPath()} ${projectPath2(".stacks")}`);
277
+ }
278
+
279
+ // src/add.ts
280
+ import {installPackage} from "@stacksjs/cli";
281
+ async function invoke2(options) {
282
+ if (options?.table)
283
+ await addTable();
284
+ if (options?.calendar)
285
+ await addCalendar();
286
+ }
287
+ async function add(options) {
288
+ return invoke2(options);
289
+ }
290
+ async function addTable() {
291
+ await installPackage("@stacksjs/table");
292
+ }
293
+ async function addCalendar() {
294
+ await installPackage("@stacksjs/calendar");
295
+ }
296
+ async function installPackages(names) {
297
+ for (const name of names)
298
+ await installPackage(name);
299
+ }
300
+
301
+ // src/commit.ts
302
+ import {NpmScript as NpmScript2} from "@stacksjs/enums";
303
+ import {log as log5} from "@stacksjs/logging";
304
+ import {runNpmScript as runNpmScript2} from "@stacksjs/utils";
305
+ async function invoke3(options) {
306
+ log5.info("Committing...");
307
+ await runNpmScript2(NpmScript2.Commit, options);
308
+ log5.success("Committed");
309
+ }
310
+ async function commit(options) {
311
+ return invoke3(options);
312
+ }
313
+
314
+ // src/make.ts
315
+ import process2 from "process";
316
+ import {italic} from "@stacksjs/cli";
317
+ import {log as log6} from "@stacksjs/logging";
318
+ import {frameworkPath as frameworkPath2, path as p2, resolve} from "@stacksjs/path";
319
+ import {createFolder, doesFolderExist, writeTextFile as writeTextFile2} from "@stacksjs/storage";
320
+ async function invoke4(options) {
321
+ if (options.component)
322
+ await makeComponent(options);
323
+ if (options.database)
324
+ makeDatabase(options);
325
+ if (options.function)
326
+ await makeFunction(options);
327
+ if (options.language)
328
+ await makeLanguage(options);
329
+ if (options.notification)
330
+ await makeNotification(options);
331
+ if (options.page)
332
+ await makePage(options);
333
+ if (options.stack)
334
+ makeStack(options);
335
+ }
336
+ async function make(options) {
337
+ return invoke4(options);
338
+ }
339
+ async function makeAction(options) {
340
+ try {
341
+ const name = options.name;
342
+ log6.info("Creating your action...");
343
+ await createAction(options);
344
+ log6.success(`Created ${italic(name)} action`);
345
+ } catch (error) {
346
+ log6.error("There was an error creating your action", error);
347
+ process2.exit();
348
+ }
349
+ }
350
+ async function makeComponent(options) {
351
+ try {
352
+ const name = options.name;
353
+ log6.info("Creating your component...");
354
+ await createComponent(options);
355
+ log6.success(`Created ${italic(name)} component`);
356
+ } catch (error) {
357
+ log6.error("There was an error creating your component", error);
358
+ process2.exit();
359
+ }
360
+ }
361
+ async function createAction(options) {
362
+ const name = options.name;
363
+ await writeTextFile2({
364
+ path: p2.userActionsPath(`${name}.ts`),
365
+ data: `import { Action } from '@stacksjs/actions'
366
+
367
+ export default new Action({
368
+ name: '${name}',
369
+ description: '${name} action',
370
+
371
+ handle() {
372
+ return 'Hello World action'
373
+ },
374
+ })
375
+ `
376
+ });
377
+ }
378
+ async function createComponent(options) {
379
+ const name = options.name;
380
+ await writeTextFile2({
381
+ path: p2.userComponentsPath(`${name}.stx`),
382
+ data: `<script setup lang="ts">
383
+ console.log('Hello World component created')
384
+ </script>
385
+
386
+ <template>
387
+ <div>
388
+ Some HTML block
389
+ </div>
390
+ </template>
391
+ `
392
+ });
393
+ }
394
+ function makeDatabase(options) {
395
+ try {
396
+ const name = options.name;
397
+ log6.info(`Creating your ${italic(name)} database...`);
398
+ createDatabase(options);
399
+ log6.success(`Created ${italic(name)} database`);
400
+ } catch (error) {
401
+ log6.error("There was an error creating your database", error);
402
+ process2.exit();
403
+ }
404
+ }
405
+ function createDatabase(options) {
406
+ console.log("createDatabase options", options);
407
+ }
408
+ function factory(options) {
409
+ try {
410
+ const name = options.name;
411
+ log6.info(`Creating your ${italic(name)} factory...`);
412
+ createDatabase(options);
413
+ log6.success(`Created ${italic(name)} factory`);
414
+ } catch (error) {
415
+ log6.error("There was an error creating your factory", error);
416
+ process2.exit();
417
+ }
418
+ }
419
+ function createFactory(options) {
420
+ console.log("options", options);
421
+ }
422
+ async function makeNotification(options) {
423
+ try {
424
+ const name = options.name;
425
+ log6.info(`Creating your ${italic(name)} notification...`);
426
+ await createNotification(options);
427
+ log6.success(`Created ${italic(name)} notification`);
428
+ } catch (error) {
429
+ log6.error("There was an error creating your notification", error);
430
+ process2.exit();
431
+ }
432
+ }
433
+ async function makePage(options) {
434
+ try {
435
+ const name = options.name;
436
+ log6.info("Creating your page...");
437
+ await createPage(options);
438
+ log6.success(`Created ${name} page`);
439
+ } catch (error) {
440
+ log6.error("There was an error creating your page", error);
441
+ process2.exit();
442
+ }
443
+ }
444
+ async function createPage(options) {
445
+ const name = options.name;
446
+ await writeTextFile2({
447
+ path: p2.userViewsPath(`${name}.stx`),
448
+ data: `<script setup lang="ts">
449
+ console.log('Hello World page created')
450
+ </script>
451
+
452
+ <template>
453
+ <div>
454
+ Visit http://127.0.0.1/${name}
455
+ </div>
456
+ </template>
457
+ `
458
+ });
459
+ }
460
+ async function makeFunction(options) {
461
+ try {
462
+ const name = options.name;
463
+ log6.info("Creating your function...");
464
+ await createFunction(options);
465
+ log6.success(`Created ${name} function`);
466
+ } catch (error) {
467
+ log6.error("There was an error creating your function", error);
468
+ process2.exit();
469
+ }
470
+ }
471
+ async function createFunction(options) {
472
+ const name = options.name;
473
+ await writeTextFile2({
474
+ path: p2.userFunctionsPath(`${name}.ts`),
475
+ data: `// reactive state
476
+ const ${name} = ref(0)
477
+
478
+ // functions that mutate state and trigger updates
479
+ function increment() {
480
+ ${name}.value++
481
+ }
482
+
483
+ export {
484
+ ${name},
485
+ increment,
486
+ }
487
+ `
488
+ });
489
+ }
490
+ async function makeLanguage(options) {
491
+ try {
492
+ const name = options.name;
493
+ log6.info("Creating your translation file...");
494
+ await createLanguage(options);
495
+ log6.success(`Created ${name} translation file`);
496
+ } catch (error) {
497
+ log6.error("There was an error creating your language.", error);
498
+ process2.exit();
499
+ }
500
+ }
501
+ async function createLanguage(options) {
502
+ const name = options.name;
503
+ await writeTextFile2({
504
+ path: p2.resourcesPath(`lang/${name}.yml`),
505
+ data: `button:
506
+ text: Copy
507
+ `
508
+ });
509
+ }
510
+ function makeStack(options) {
511
+ try {
512
+ const name = options.name;
513
+ log6.info(`Creating your ${name} stack...`);
514
+ const path4 = resolve(process2.cwd(), name);
515
+ log6.success("Successfully scaffolded your project");
516
+ log6.info(`cd ${path4} && bun install`);
517
+ } catch (error) {
518
+ log6.error("There was an error creating your stack", error);
519
+ process2.exit();
520
+ }
521
+ }
522
+ async function createNotification(options) {
523
+ const name = options.name;
524
+ try {
525
+ let importOption = "EmailOptions";
526
+ if (!doesFolderExist("notifications"))
527
+ await createFolder("./notifications");
528
+ if (options.chat)
529
+ importOption = "ChatOptions";
530
+ if (options.sms)
531
+ importOption = "SMSOptions";
532
+ await writeTextFile2({
533
+ path: p2.userNotificationsPath(`${name}.ts`),
534
+ data: `import type { ${importOption} } from \'@stacksjs/types\'
535
+
536
+ function content(): string {
537
+ return 'example'
538
+ }
539
+
540
+ function send(): ${importOption} {
541
+ return {
542
+ content: content(),
543
+ }
544
+ }`
545
+ });
546
+ return true;
547
+ } catch (error) {
548
+ return false;
549
+ }
550
+ }
551
+ async function createMigration(options) {
552
+ const optionName = options.name;
553
+ const table = "dummy-name";
554
+ if (!optionName[0])
555
+ throw new Error("options.name is required and cannot be empty");
556
+ const name = optionName[0].toUpperCase() + optionName.slice(1);
557
+ const path4 = frameworkPath2(`database/migrations/${name}.ts`);
558
+ try {
559
+ await writeTextFile2({
560
+ path: `${path4}`,
561
+ data: `import { Kysely } from 'kysely'
562
+
563
+ export async function up(db: Kysely<any>): Promise<void> {
564
+ await db.schema
565
+ .createTable('${table}')
566
+ .addColumn('id', 'integer', col => col.autoIncrement().primaryKey())
567
+ .execute()
568
+ }`
569
+ });
570
+ log6.success(`Successfully created your migration file at stacks/database/migrations/${name}.ts`);
571
+ } catch (error) {
572
+ log6.error(error);
573
+ }
574
+ }
575
+ async function createModel(options) {
576
+ const optionName = options.name;
577
+ if (!optionName[0])
578
+ throw new Error("options.name is required and cannot be empty");
579
+ const name = optionName[0].toUpperCase() + optionName.slice(1);
580
+ const path4 = p2.userModelsPath(`${name}.ts`);
581
+ try {
582
+ await writeTextFile2({
583
+ path: `${path4}`,
584
+ data: `import { faker } from '@stacksjs/faker'
585
+ import { schema } from '@stacksjs/validation'
586
+ import type { Model } from '@stacksjs/types'
587
+
588
+ export default {
589
+ name: '${name}',
590
+
591
+ traits: {
592
+ useTimestamps: true,
593
+
594
+ useSeeder: {
595
+ count: 10,
596
+ },
597
+ },
598
+
599
+ attributes: {
600
+ // your attributes here
601
+ },
602
+ } satisfies Model`
603
+ });
604
+ log6.success(`Model created: ${italic(`app/Models/${name}.ts`)}`);
605
+ } catch (error) {
606
+ log6.error(error);
607
+ }
608
+ }
609
+
610
+ // src/action.ts
611
+ class Action3 {
612
+ name;
613
+ description;
614
+ fields;
615
+ rate;
616
+ tries;
617
+ backoff;
618
+ enabled;
619
+ handle;
620
+ constructor({ name, description, fields, handle, rate, tries, backoff, enabled }) {
621
+ this.name = name;
622
+ this.description = description;
623
+ this.fields = fields;
624
+ this.rate = rate;
625
+ this.tries = tries;
626
+ this.backoff = backoff;
627
+ this.enabled = enabled;
628
+ this.handle = handle;
629
+ }
630
+ }
631
+ export {
632
+ runSystemTrayDevServer,
633
+ make as runMake,
634
+ runFrontendDevServer,
635
+ runDocsDevServer,
636
+ runDevServer,
637
+ runDesktopDevServer,
638
+ runDashboardDevServer,
639
+ runComponentsDevServer,
640
+ commit as runCommit,
641
+ runBackendDevServer,
642
+ runApiDevServer,
643
+ add as runAdd,
644
+ runActions,
645
+ runAction,
646
+ makeStack,
647
+ makePage,
648
+ makeNotification,
649
+ makeLanguage,
650
+ makeFunction,
651
+ makeDatabase,
652
+ makeComponent,
653
+ makeAction,
654
+ invoke,
655
+ hasAction,
656
+ generateWebTypes2 as generateWebTypes,
657
+ generateVsCodeCustomData2 as generateVsCodeCustomData,
658
+ generateTypes,
659
+ generateSeeder,
660
+ generatePkgxConfig,
661
+ generateLibEntries,
662
+ generateIdeHelpers,
663
+ generateCoreSymlink,
664
+ generateComponentMeta,
665
+ generate,
666
+ createPage,
667
+ createNotification,
668
+ createModel,
669
+ createMigration,
670
+ createLanguage,
671
+ createFunction,
672
+ createFactory,
673
+ createDatabase,
674
+ createComponent,
675
+ Action3 as Action
676
+ };
@@ -0,0 +1,10 @@
1
+ // @bun
2
+ // src/key-generate.ts
3
+ import {runCommand} from "@stacksjs/cli";
4
+ import {projectPath} from "@stacksjs/path";
5
+ import {generateAppKey} from "@stacksjs/security";
6
+ import {isFile} from "@stacksjs/storage";
7
+ import {setEnvValue} from "@stacksjs/utils";
8
+ if (!isFile(".env"))
9
+ await runCommand("cp .env.example .env", { cwd: projectPath() });
10
+ await setEnvValue("APP_KEY", generateAppKey());
@@ -0,0 +1,12 @@
1
+ // @bun
2
+ // src/lint/fix.ts
3
+ import {log, parseOptions, runCommand} from "@stacksjs/cli";
4
+ import {NpmScript} from "@stacksjs/enums";
5
+ import {projectPath} from "@stacksjs/path";
6
+ log.info("Ensuring Code Style...");
7
+ var options = parseOptions();
8
+ var result = await runCommand(NpmScript.LintFix, {
9
+ cwd: projectPath(),
10
+ ...options
11
+ });
12
+ log.success("Linted");
@@ -0,0 +1,16 @@
1
+ // @bun
2
+ // src/lint/index.ts
3
+ import process from "process";
4
+ import {log, runCommands} from "@stacksjs/cli";
5
+ import {NpmScript} from "@stacksjs/enums";
6
+ import {projectPath} from "@stacksjs/path";
7
+ import {ExitCode} from "@stacksjs/types";
8
+ log.info("Ensuring Code Style...");
9
+ var result = await runCommands([NpmScript.Lint, NpmScript.LintPackageJson], {
10
+ cwd: projectPath()
11
+ });
12
+ if (Array.isArray(result)) {
13
+ if (result.map((r) => r.isErr()).includes(true))
14
+ process.exit(ExitCode.FatalError);
15
+ }
16
+ log.success("Linted");