@stacksjs/actions 0.59.11 → 0.61.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.
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
@@ -1,12 +1,17 @@
1
1
  import { log } from '@stacksjs/logging'
2
- import { writeTextFile } from '@stacksjs/storage'
3
2
  import { packageJsonPath } from '@stacksjs/path'
3
+ import { writeTextFile } from '@stacksjs/storage'
4
4
  import library from '~/config/library'
5
5
 
6
6
  type PackageJsonType = 'vue-components' | 'web-components' | 'functions'
7
7
 
8
8
  export async function generatePackageJson(type: PackageJsonType) {
9
- let name, description, directory, keywords, config, prettyName
9
+ let name
10
+ let description
11
+ let directory
12
+ let keywords
13
+ let config
14
+ let prettyName
10
15
 
11
16
  if (type === 'vue-components') {
12
17
  name = library.vueComponents?.name
@@ -14,17 +19,13 @@ export async function generatePackageJson(type: PackageJsonType) {
14
19
  directory = 'components'
15
20
  keywords = library.vueComponents?.keywords
16
21
  config = 'vue-components'
17
- }
18
-
19
- else if (type === 'web-components') {
22
+ } else if (type === 'web-components') {
20
23
  name = library.webComponents?.name
21
24
  description = library.webComponents?.description
22
25
  directory = 'components'
23
26
  keywords = library.webComponents?.keywords
24
27
  config = 'web-components'
25
- }
26
-
27
- else if (type === 'functions') {
28
+ } else if (type === 'functions') {
28
29
  name = library.functions?.name
29
30
  description = library.functions?.description
30
31
  directory = 'functions'
@@ -81,16 +82,12 @@ export async function generatePackageJson(type: PackageJsonType) {
81
82
  `,
82
83
  })
83
84
 
84
- if (type === 'vue-components')
85
- prettyName = 'Vue Component library'
86
- else if (type === 'web-components')
87
- prettyName = 'Web Component library'
88
- else if (type === 'functions')
89
- prettyName = 'Function Library'
85
+ if (type === 'vue-components') prettyName = 'Vue Component library'
86
+ else if (type === 'web-components') prettyName = 'Web Component library'
87
+ else if (type === 'functions') prettyName = 'Function Library'
90
88
 
91
89
  log.success(`Created ${prettyName} package.json file`)
92
- }
93
- catch (err) {
90
+ } catch (err) {
94
91
  log.error(`There was an error creating the ${prettyName} package.json`, err)
95
92
  }
96
93
  }
@@ -1,9 +1,15 @@
1
+ import type { Action as ActionType } from '@stacksjs/actions'
1
2
  import { buddyOptions, runCommand, runCommands } from '@stacksjs/cli'
2
- import { storage } from '@stacksjs/storage'
3
- import { log } from '@stacksjs/logging'
4
3
  import { err } from '@stacksjs/error-handling'
4
+ import { log } from '@stacksjs/logging'
5
5
  import * as p from '@stacksjs/path'
6
+ import { glob, storage } from '@stacksjs/storage'
6
7
  import type { ActionOptions } from '@stacksjs/types'
8
+ import { Glob } from 'bun'
9
+
10
+ type ActionPath = string // TODO: narrow this by automating its generation
11
+ type ActionName = string // TODO: narrow this by automating its generation
12
+ type Action = ActionPath | ActionName | string
7
13
 
8
14
  /**
9
15
  * Run an Action the Stacks way.
@@ -12,7 +18,23 @@ import type { ActionOptions } from '@stacksjs/types'
12
18
  * @param options The options to pass to the command.
13
19
  * @returns The result of the command.
14
20
  */
15
- export async function runAction(action: string, options?: ActionOptions) {
21
+ export async function runAction(action: Action, options?: ActionOptions) {
22
+ // check if action is a file anywhere in ./app/Actions/**/*.ts
23
+ // if it is, return and await the action
24
+ const glob = new Glob('**/*.ts')
25
+ const scanOptions = { cwd: p.userActionsPath(), onlyFiles: true }
26
+
27
+ for await (const file of glob.scan(scanOptions)) {
28
+ log.debug('file', file)
29
+ if (file === `${action}.ts` || file.endsWith(`${action}.ts`))
30
+ return ((await import(p.userActionsPath(file))).default as ActionType).handle()
31
+
32
+ // if a custom model name is used, we need to check for it
33
+ const a = await import(p.userActionsPath(file))
34
+ if (a.name === action) return await a.handle()
35
+ }
36
+
37
+ // or else, just run the action normally by assuming the action is core Action, stored in p.actionsPath
16
38
  const opts = buddyOptions()
17
39
  const path = p.relativeActionsPath(`src/${action}.ts`)
18
40
  const cmd = `bun --bun ${path} ${opts}`.trimEnd()
@@ -34,17 +56,14 @@ export async function runAction(action: string, options?: ActionOptions) {
34
56
  * @param options The options to pass to the command.
35
57
  * @returns The result of the command.
36
58
  */
37
- export async function runActions(actions: string[], options?: ActionOptions) {
38
- log.debug('runActions:', actions)
39
- log.debug('actions options:', options)
59
+ export async function runActions(actions: Action[], options?: ActionOptions) {
60
+ log.debug('runActions:', actions, options)
40
61
 
41
- if (!actions.length)
42
- return err('No actions were specified')
62
+ if (!actions.length) return err('No actions were specified')
43
63
 
44
64
  for (const action of actions) {
45
65
  log.debug(`running action "${action}"`)
46
- if (!hasAction(action))
47
- return err(`The specified action "${action}" does not exist`)
66
+ if (!hasAction(action)) return err(`The specified action "${action}" does not exist`)
48
67
  }
49
68
 
50
69
  const opts = buddyOptions()
@@ -54,13 +73,37 @@ export async function runActions(actions: string[], options?: ActionOptions) {
54
73
  ...options,
55
74
  }
56
75
 
57
- const commands = actions.map(action => `bun --bun ${p.relativeActionsPath(`src/${action}.ts`)} ${opts}`)
76
+ const commands = actions.map((action) => `bun --bun ${p.relativeActionsPath(`src/${action}.ts`)} ${opts}`)
58
77
 
59
78
  log.debug('commands:', commands)
60
79
 
61
80
  return await runCommands(commands, o)
62
81
  }
63
82
 
64
- export function hasAction(action: string) {
65
- return storage.isFile(p.actionsPath(`src/${action}.ts`))
83
+ // looks in most common locations
84
+ export function hasAction(action: Action) {
85
+ // Define patterns specifically for user actions
86
+ const userActionPatterns = [
87
+ `${action}.ts`,
88
+ `${action}`,
89
+ `Dashboard/${action}.ts`,
90
+ `Dashboard/${action}`,
91
+ `Buddy/${action}.ts`,
92
+ `Buddy/${action}`,
93
+ ]
94
+
95
+ // Define patterns specifically for core actions
96
+ const actionPatterns = [`src/${action}.ts`, `src/${action}`, `${action}.ts`, `${action}`]
97
+
98
+ // Check user actions path with its specific patterns
99
+ const userActionFiles = glob.sync(userActionPatterns.map((pattern) => p.userActionsPath(pattern)))
100
+
101
+ // Check actions path with its specific patterns
102
+ const actionFiles = glob.sync(actionPatterns.map((pattern) => p.actionsPath(pattern)))
103
+
104
+ return userActionFiles.length > 0 || actionFiles.length > 0
105
+
106
+ // TODO: need to loop through all user actions and check whether the name is a valid action name match
107
+
108
+ // return false
66
109
  }
@@ -13,8 +13,7 @@ export async function generateVsCodeCustomData() {
13
13
  data: generateComponentInfoData(),
14
14
  })
15
15
  log.success('Generated custom-elements.json for IDEs.')
16
- }
17
- catch (err) {
16
+ } catch (err) {
18
17
  log.error('There was an error generating the custom-elements.json file.', err)
19
18
  }
20
19
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from './action'
2
2
  export * from './dev'
3
3
  export * from './generate'
4
- export * from './helpers/utils'
4
+ export * from './helpers'
5
5
 
6
6
  export { commit as runCommit } from './commit'
7
7
  export { add as runAdd } from './add'
@@ -9,6 +9,7 @@ export { add as runAdd } from './add'
9
9
  // makeFactory,
10
10
  export {
11
11
  make as runMake,
12
+ makeAction,
12
13
  makeComponent,
13
14
  makeDatabase,
14
15
  makeFunction,
@@ -1,10 +1,9 @@
1
1
  import { runCommand } from '@stacksjs/cli'
2
- import { isFile } from '@stacksjs/storage'
3
- import { setEnvValue } from '@stacksjs/utils'
4
2
  import { projectPath } from '@stacksjs/path'
5
3
  import { generateAppKey } from '@stacksjs/security'
4
+ import { isFile } from '@stacksjs/storage'
5
+ import { setEnvValue } from '@stacksjs/utils'
6
6
 
7
- if (!isFile('.env'))
8
- await runCommand('cp .env.example .env', { cwd: projectPath() })
7
+ if (!isFile('.env')) await runCommand('cp .env.example .env', { cwd: projectPath() })
9
8
 
10
9
  await setEnvValue('APP_KEY', generateAppKey())
package/src/lint/fix.ts CHANGED
@@ -1,14 +1,22 @@
1
1
  import { log, parseOptions, runCommand } from '@stacksjs/cli'
2
- import { projectPath } from '@stacksjs/path'
3
2
  import { NpmScript } from '@stacksjs/enums'
3
+ import { projectPath } from '@stacksjs/path'
4
+ import { ExitCode } from '@stacksjs/types'
4
5
 
5
6
  // TODO: this should be a loader
6
7
  log.info('Ensuring Code Style...')
7
8
 
8
9
  const options = parseOptions()
9
- await runCommand(NpmScript.LintFix, {
10
+
11
+ const result = await runCommand(NpmScript.LintFix, {
10
12
  cwd: projectPath(),
11
13
  ...options,
12
14
  })
13
15
 
16
+ // console.log('rs', result.error)
17
+ // if (result.isErr()) {
18
+ // log.error('There was an error fixing your code style.', result.error)
19
+ // process.exit(1)
20
+ // }
21
+
14
22
  log.success('Linted')
package/src/lint/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import process from 'node:process'
2
- import { ExitCode } from '@stacksjs/types'
3
- import { NpmScript } from '@stacksjs/enums'
4
2
  import { log, runCommands } from '@stacksjs/cli'
3
+ import { NpmScript } from '@stacksjs/enums'
5
4
  import { projectPath } from '@stacksjs/path'
5
+ import { ExitCode } from '@stacksjs/types'
6
6
 
7
7
  log.info('Ensuring Code Style...')
8
8
 
@@ -12,14 +12,12 @@ log.info('Ensuring Code Style...')
12
12
  // await $`${NpmScript.Lint}`
13
13
  // await $`${NpmScript.LintPackageJson}`
14
14
 
15
- const result = await runCommands([
16
- NpmScript.Lint,
17
- NpmScript.LintPackageJson,
18
- ], { cwd: projectPath() })
15
+ const result = await runCommands([NpmScript.Lint, NpmScript.LintPackageJson], {
16
+ cwd: projectPath(),
17
+ })
19
18
 
20
19
  if (Array.isArray(result)) {
21
- if (result.map(r => r.isErr()).includes(true))
22
- process.exit(ExitCode.FatalError)
20
+ if (result.map((r) => r.isErr()).includes(true)) process.exit(ExitCode.FatalError)
23
21
  }
24
22
 
25
23
  log.success('Linted')
package/src/make.ts CHANGED
@@ -1,59 +1,75 @@
1
1
  import process from 'node:process'
2
2
  import { italic } from '@stacksjs/cli'
3
3
  import { log } from '@stacksjs/logging'
4
+ import { frameworkPath, path as p, projectPath, resolve } from '@stacksjs/path'
4
5
  import { createFolder, doesFolderExist, writeTextFile } from '@stacksjs/storage'
5
- import { frameworkPath, projectPath, resolve } from '@stacksjs/path'
6
6
  import type { MakeOptions } from '@stacksjs/types'
7
7
 
8
8
  export async function invoke(options: MakeOptions) {
9
- if (options.component)
10
- await makeComponent(options)
11
-
12
- if (options.database)
13
- makeDatabase(options)
14
-
15
- if (options.function)
16
- await makeFunction(options)
17
-
18
- if (options.language)
19
- await makeLanguage(options)
9
+ if (options.component) await makeComponent(options)
10
+ if (options.database) makeDatabase(options)
11
+ if (options.function) await makeFunction(options)
12
+ if (options.language) await makeLanguage(options)
20
13
 
21
14
  // if (options.migration)
22
15
  // await migration(options)
23
16
 
24
- if (options.notification)
25
- await makeNotification(options)
26
-
27
- if (options.page)
28
- await makePage(options)
29
-
30
- if (options.stack)
31
- makeStack(options)
17
+ if (options.notification) await makeNotification(options)
18
+ if (options.page) await makePage(options)
19
+ if (options.stack) makeStack(options)
32
20
  }
33
21
 
34
22
  export async function make(options: MakeOptions) {
35
23
  return invoke(options)
36
24
  }
37
25
 
26
+ export async function makeAction(options: MakeOptions) {
27
+ try {
28
+ const name = options.name
29
+ log.info('Creating your action...')
30
+ await createAction(options)
31
+ log.success(`Created ${italic(name)} action`)
32
+ } catch (error) {
33
+ log.error('There was an error creating your action', error)
34
+ process.exit()
35
+ }
36
+ }
37
+
38
38
  export async function makeComponent(options: MakeOptions) {
39
39
  try {
40
40
  const name = options.name
41
41
  log.info('Creating your component...')
42
42
  await createComponent(options)
43
43
  log.success(`Created ${italic(name)} component`)
44
- }
45
- catch (error) {
44
+ } catch (error) {
46
45
  log.error('There was an error creating your component', error)
47
46
  process.exit()
48
47
  }
49
48
  }
50
49
 
50
+ export async function createAction(options: MakeOptions) {
51
+ const name = options.name
52
+ await writeTextFile({
53
+ path: p.userActionsPath(`${name}.ts`),
54
+ data: `import { Action } from '@stacksjs/actions'
55
+
56
+ export default new Action({
57
+ name: '${name}',
58
+ description: '${name} action',
59
+
60
+ handle() {
61
+ return 'Hello World action'
62
+ },
63
+ })
64
+ `,
65
+ })
66
+ }
67
+
51
68
  export async function createComponent(options: MakeOptions) {
52
69
  const name = options.name
53
70
  await writeTextFile({
54
- path: `./components/${name}.stx`,
71
+ path: p.userComponentsPath(`${name}.stx`),
55
72
  data: `<script setup lang="ts">
56
- // eslint-disable-next-line no-console
57
73
  console.log('Hello World component created')
58
74
  </script>
59
75
 
@@ -72,16 +88,14 @@ export function makeDatabase(options: MakeOptions) {
72
88
  log.info(`Creating your ${italic(name)} database...`)
73
89
  createDatabase(options)
74
90
  log.success(`Created ${italic(name)} database`)
75
- }
76
- catch (error) {
91
+ } catch (error) {
77
92
  log.error('There was an error creating your database', error)
78
93
  process.exit()
79
94
  }
80
95
  }
81
96
 
82
97
  export function createDatabase(options: MakeOptions) {
83
- // eslint-disable-next-line no-console
84
- console.log('options', options) // wip
98
+ console.log('createDatabase options', options) // wip
85
99
  }
86
100
 
87
101
  export function factory(options: MakeOptions) {
@@ -90,15 +104,13 @@ export function factory(options: MakeOptions) {
90
104
  log.info(`Creating your ${italic(name)} factory...`)
91
105
  createDatabase(options)
92
106
  log.success(`Created ${italic(name)} factory`)
93
- }
94
- catch (error) {
107
+ } catch (error) {
95
108
  log.error('There was an error creating your factory', error)
96
109
  process.exit()
97
110
  }
98
111
  }
99
112
 
100
113
  export function createFactory(options: MakeOptions) {
101
- // eslint-disable-next-line no-console
102
114
  console.log('options', options) // wip
103
115
  }
104
116
 
@@ -108,8 +120,7 @@ export async function makeNotification(options: MakeOptions) {
108
120
  log.info(`Creating your ${italic(name)} notification...`)
109
121
  await createNotification(options)
110
122
  log.success(`Created ${italic(name)} notification`)
111
- }
112
- catch (error) {
123
+ } catch (error) {
113
124
  log.error('There was an error creating your notification', error)
114
125
  process.exit()
115
126
  }
@@ -121,8 +132,7 @@ export async function makePage(options: MakeOptions) {
121
132
  log.info('Creating your page...')
122
133
  await createPage(options)
123
134
  log.success(`Created ${name} page`)
124
- }
125
- catch (error) {
135
+ } catch (error) {
126
136
  log.error('There was an error creating your page', error)
127
137
  process.exit()
128
138
  }
@@ -131,10 +141,8 @@ export async function makePage(options: MakeOptions) {
131
141
  export async function createPage(options: MakeOptions) {
132
142
  const name = options.name
133
143
  await writeTextFile({
134
- path: `./pages/${name}.stx`,
135
- data:
136
- `<script setup lang="ts">
137
- // eslint-disable-next-line no-console
144
+ path: p.userViewsPath(`${name}.stx`),
145
+ data: `<script setup lang="ts">
138
146
  console.log('Hello World page created')
139
147
  </script>
140
148
 
@@ -153,8 +161,7 @@ export async function makeFunction(options: MakeOptions) {
153
161
  log.info('Creating your function...')
154
162
  await createFunction(options)
155
163
  log.success(`Created ${name} function`)
156
- }
157
- catch (error) {
164
+ } catch (error) {
158
165
  log.error('There was an error creating your function', error)
159
166
  process.exit()
160
167
  }
@@ -163,7 +170,7 @@ export async function makeFunction(options: MakeOptions) {
163
170
  export async function createFunction(options: MakeOptions) {
164
171
  const name = options.name
165
172
  await writeTextFile({
166
- path: `./functions/${name}.ts`,
173
+ path: p.userFunctionsPath(`${name}.ts`),
167
174
  data: `// reactive state
168
175
  const ${name} = ref(0)
169
176
 
@@ -186,8 +193,7 @@ export async function makeLanguage(options: MakeOptions) {
186
193
  log.info('Creating your translation file...')
187
194
  await createLanguage(options)
188
195
  log.success(`Created ${name} translation file`)
189
- }
190
- catch (error) {
196
+ } catch (error) {
191
197
  log.error('There was an error creating your language.', error)
192
198
  process.exit()
193
199
  }
@@ -196,7 +202,7 @@ export async function makeLanguage(options: MakeOptions) {
196
202
  export async function createLanguage(options: MakeOptions) {
197
203
  const name = options.name
198
204
  await writeTextFile({
199
- path: `./lang/${name}.yml`,
205
+ path: p.resourcesPath(`lang/${name}.yml`),
200
206
  data: `button:
201
207
  text: Copy
202
208
  `,
@@ -212,8 +218,7 @@ export function makeStack(options: MakeOptions) {
212
218
  // await spawn(`giget stacks ${path}`)
213
219
  log.success('Successfully scaffolded your project')
214
220
  log.info(`cd ${path} && bun install`)
215
- }
216
- catch (error) {
221
+ } catch (error) {
217
222
  log.error('There was an error creating your stack', error)
218
223
  process.exit()
219
224
  }
@@ -224,17 +229,14 @@ export async function createNotification(options: MakeOptions) {
224
229
  try {
225
230
  let importOption = 'EmailOptions'
226
231
 
227
- if (!doesFolderExist('notifications'))
228
- await createFolder('./notifications')
232
+ if (!doesFolderExist('notifications')) await createFolder('./notifications')
229
233
 
230
- if (options.chat)
231
- importOption = 'ChatOptions'
234
+ if (options.chat) importOption = 'ChatOptions'
232
235
 
233
- if (options.sms)
234
- importOption = 'SMSOptions'
236
+ if (options.sms) importOption = 'SMSOptions'
235
237
 
236
238
  await writeTextFile({
237
- path: `./notifications/${name}.ts`,
239
+ path: p.userNotificationsPath(`${name}.ts`),
238
240
  data: `import type { ${importOption} } from \'@stacksjs/types\'
239
241
 
240
242
  function content(): string {
@@ -249,8 +251,7 @@ function send(): ${importOption} {
249
251
  })
250
252
 
251
253
  return true
252
- }
253
- catch (error) {
254
+ } catch (error) {
254
255
  return false
255
256
  }
256
257
  }
@@ -259,6 +260,9 @@ export async function createMigration(options: MakeOptions) {
259
260
  const optionName = options.name
260
261
  // const table = options.tableName
261
262
  const table = 'dummy-name'
263
+
264
+ if (!optionName[0]) throw new Error('options.name is required and cannot be empty')
265
+
262
266
  const name = optionName[0].toUpperCase() + optionName.slice(1)
263
267
  const path = frameworkPath(`database/migrations/${name}.ts`)
264
268
 
@@ -270,53 +274,51 @@ export async function createMigration(options: MakeOptions) {
270
274
  export async function up(db: Kysely<any>): Promise<void> {
271
275
  await db.schema
272
276
  .createTable('${table}')
273
- .addColumn('id', 'integer', (col) => col.autoIncrement().primaryKey())
277
+ .addColumn('id', 'integer', col => col.autoIncrement().primaryKey())
274
278
  .execute()
275
279
  }`,
276
280
  })
277
281
 
278
282
  log.success(`Successfully created your migration file at stacks/database/migrations/${name}.ts`)
279
- }
280
- catch (error) {
283
+ } catch (error: any) {
281
284
  log.error(error)
282
285
  }
283
286
  }
284
287
 
285
288
  export async function createModel(options: MakeOptions) {
286
289
  const optionName = options.name
290
+
291
+ if (!optionName[0]) throw new Error('options.name is required and cannot be empty')
292
+
287
293
  const name = optionName[0].toUpperCase() + optionName.slice(1)
288
- const path = projectPath(`app/Models/${name}.ts`)
294
+ const path = p.userModelsPath(`${name}.ts`)
295
+
289
296
  try {
290
297
  await writeTextFile({
291
298
  path: `${path}`,
292
299
  data: `import { faker } from '@stacksjs/faker'
293
- import { validate } from '@stacksjs/validation'
300
+ import { schema } from '@stacksjs/validation'
294
301
  import type { Model } from '@stacksjs/types'
295
302
 
296
- export default <Model> {
303
+ export default {
297
304
  name: '${name}',
298
305
 
299
- searchable: true, // boolean | IndexSettings,
300
- authenticatable: true, // boolean | AuthSettings,
306
+ traits: {
307
+ useTimestamps: true,
301
308
 
302
- seeder: {
303
- count: 10,
304
- },
305
-
306
- fields: {
307
- name: {
308
- validation: validate.string().min(3).max(255),
309
- factory: () => faker.person,
309
+ useSeeder: {
310
+ count: 10,
310
311
  },
312
+ },
311
313
 
312
- // more fields here
314
+ attributes: {
315
+ // your attributes here
313
316
  },
314
- }`,
317
+ } satisfies Model`,
315
318
  })
316
319
 
317
- log.success(`Successfully created your model at app/Models/${name}.ts`)
318
- }
319
- catch (error) {
320
+ log.success(`Model created: ${italic(`app/Models/${name}.ts`)}`)
321
+ } catch (error: any) {
320
322
  log.error(error)
321
323
  }
322
324
  }
@@ -1 +1,22 @@
1
- // wip
1
+ import process from 'node:process'
2
+ import { generateMigrations, runDatabaseMigration } from '@stacksjs/database'
3
+ import { log } from '@stacksjs/logging'
4
+
5
+ // this is run and checks whether new created or update migrations need to be generated
6
+ const result = await generateMigrations()
7
+
8
+ if (result?.isErr()) {
9
+ console.error(result.error)
10
+ log.error('[stacks] generateMigrations failed', result.error)
11
+ process.exit(1)
12
+ }
13
+
14
+ const result2 = await runDatabaseMigration()
15
+
16
+ if (result2.isErr()) {
17
+ log.error('runDatabaseMigration failed')
18
+ log.error(result2.error)
19
+ process.exit(1)
20
+ }
21
+
22
+ process.exit(0)
@@ -0,0 +1,20 @@
1
+ import process from 'node:process'
2
+ import { generateMigrations, resetDatabase, runDatabaseMigration } from '@stacksjs/database'
3
+ import { log } from '@stacksjs/logging'
4
+
5
+ // first, reset the database, if it exists
6
+ const result = await resetDatabase()
7
+
8
+ if (result?.isErr()) {
9
+ console.error(result.error)
10
+ log.error('generateMigrations failed', result.error)
11
+ process.exit(1)
12
+ }
13
+
14
+ // then,generate the migrations
15
+ await generateMigrations()
16
+
17
+ // finally, migrate the database
18
+ await runDatabaseMigration()
19
+
20
+ process.exit(0)
File without changes