@stacksjs/actions 0.58.71 → 0.58.73

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/dist/src/build.js CHANGED
@@ -45,6 +45,7 @@ function hasAction(action) {
45
45
  import process from "process";
46
46
  import {log as log2} from "@stacksjs/logging";
47
47
  import {Action, NpmScript} from "@stacksjs/enums";
48
+ import {runCommand as runCommand2} from "@stacksjs/cli";
48
49
  import {runNpmScript} from "@stacksjs/utils";
49
50
  import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
50
51
  async function invoke(options) {
@@ -60,6 +61,8 @@ async function invoke(options) {
60
61
  await generateIdeHelpers(options);
61
62
  else if (options?.componentMeta)
62
63
  await generateComponentMeta(options);
64
+ else if (options?.coreSymlink)
65
+ await generateCoreSymlink();
63
66
  }
64
67
  function generate(options) {
65
68
  return invoke(options);
@@ -128,10 +131,13 @@ function generateMigrations() {
128
131
  log2.success("Successfully updated migrations");
129
132
  }
130
133
  function generatePkgxConfig() {
131
- log2.success("Successfully generated `./pkgx.yaml` based on your configs");
134
+ log2.success("Successfully generated `./pkgx.yaml` based on your config");
132
135
  }
133
136
  async function generateSeeder() {
134
137
  }
138
+ async function generateCoreSymlink() {
139
+ await runCommand2(`ln -s ${frameworkPath()} ${projectPath2(".stacks")}`);
140
+ }
135
141
 
136
142
  // src/build.ts
137
143
  import {log as log3} from "@stacksjs/logging";
@@ -6,7 +6,7 @@ import {log} from "@stacksjs/logging";
6
6
  import {customElementsDataPath} from "@stacksjs/path";
7
7
  import {writeTextFile} from "@stacksjs/storage";
8
8
 
9
- // /home/runner/work/stacks/stacks/config/library.ts
9
+ // ../../../../config/library.ts
10
10
  var library_default = {
11
11
  name: "hello-world",
12
12
  owner: "@stacksjs",
@@ -45,6 +45,7 @@ function hasAction(action) {
45
45
  import process from "process";
46
46
  import {log as log2} from "@stacksjs/logging";
47
47
  import {Action, NpmScript} from "@stacksjs/enums";
48
+ import {runCommand as runCommand2} from "@stacksjs/cli";
48
49
  import {runNpmScript} from "@stacksjs/utils";
49
50
  import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
50
51
  async function invoke(options) {
@@ -60,6 +61,8 @@ async function invoke(options) {
60
61
  await generateIdeHelpers(options);
61
62
  else if (options?.componentMeta)
62
63
  await generateComponentMeta(options);
64
+ else if (options?.coreSymlink)
65
+ await generateCoreSymlink();
63
66
  }
64
67
  function generate(options) {
65
68
  return invoke(options);
@@ -128,10 +131,13 @@ function generateMigrations() {
128
131
  log2.success("Successfully updated migrations");
129
132
  }
130
133
  function generatePkgxConfig() {
131
- log2.success("Successfully generated `./pkgx.yaml` based on your configs");
134
+ log2.success("Successfully generated `./pkgx.yaml` based on your config");
132
135
  }
133
136
  async function generateSeeder() {
134
137
  }
138
+ async function generateCoreSymlink() {
139
+ await runCommand2(`ln -s ${frameworkPath()} ${projectPath2(".stacks")}`);
140
+ }
135
141
  export {
136
142
  invoke,
137
143
  generateWebTypes,
@@ -142,6 +148,7 @@ export {
142
148
  generateMigrations,
143
149
  generateLibEntries,
144
150
  generateIdeHelpers,
151
+ generateCoreSymlink,
145
152
  generateComponentMeta,
146
153
  generate
147
154
  };
@@ -10,7 +10,7 @@ import {writeTextFile} from "@stacksjs/storage";
10
10
  import {determineResetPreset} from "@stacksjs/utils";
11
11
  import {ExitCode} from "@stacksjs/types";
12
12
 
13
- // /home/runner/work/stacks/stacks/config/library.ts
13
+ // ../../../../config/library.ts
14
14
  var library_default = {
15
15
  name: "hello-world",
16
16
  owner: "@stacksjs",
@@ -71,7 +71,7 @@ async function createLibraryEntryPoint(type) {
71
71
  await createFunctionLibraryEntryPoint();
72
72
  }
73
73
  async function createVueLibraryEntryPoint(type = "vue-components") {
74
- log.info("Creating Vue Component Library Entry Point...");
74
+ log.info("Ensuring Component Library Entry Point...");
75
75
  await writeTextFile({
76
76
  path: libraryEntryPath(type),
77
77
  data: generateEntryPointData(type)
@@ -82,7 +82,7 @@ async function createVueLibraryEntryPoint(type = "vue-components") {
82
82
  log.success("Created Vue Component Library Entry Point");
83
83
  }
84
84
  async function createWebComponentLibraryEntryPoint(type = "web-components") {
85
- log.info("Creating Web Component Library Entry Point...");
85
+ log.info("Ensuring Web Component Library Entry Point...");
86
86
  await writeTextFile({
87
87
  path: libraryEntryPath(type),
88
88
  data: generateEntryPointData(type)
@@ -93,7 +93,7 @@ async function createWebComponentLibraryEntryPoint(type = "web-components") {
93
93
  log.success("Created Web Component Library Entry Point");
94
94
  }
95
95
  async function createFunctionLibraryEntryPoint(type = "functions") {
96
- log.info("Creating Function Library Entry Point...");
96
+ log.info("Ensuring Function Library Entry Point...");
97
97
  await writeTextFile({
98
98
  path: libraryEntryPath(type),
99
99
  data: generateEntryPointData(type)
@@ -6,7 +6,7 @@ import {log} from "@stacksjs/logging";
6
6
  import {customElementsDataPath} from "@stacksjs/path";
7
7
  import {writeTextFile} from "@stacksjs/storage";
8
8
 
9
- // /home/runner/work/stacks/stacks/config/library.ts
9
+ // ../../../../config/library.ts
10
10
  var library_default = {
11
11
  name: "hello-world",
12
12
  owner: "@stacksjs",
@@ -8,7 +8,7 @@ import {writeTextFile} from "@stacksjs/storage";
8
8
  import {determineResetPreset} from "@stacksjs/utils";
9
9
  import {ExitCode} from "@stacksjs/types";
10
10
 
11
- // /home/runner/work/stacks/stacks/config/library.ts
11
+ // ../../../../config/library.ts
12
12
  var library_default = {
13
13
  name: "hello-world",
14
14
  owner: "@stacksjs",
@@ -69,7 +69,7 @@ async function createLibraryEntryPoint(type) {
69
69
  await createFunctionLibraryEntryPoint();
70
70
  }
71
71
  async function createVueLibraryEntryPoint(type = "vue-components") {
72
- log.info("Creating Vue Component Library Entry Point...");
72
+ log.info("Ensuring Component Library Entry Point...");
73
73
  await writeTextFile({
74
74
  path: libraryEntryPath(type),
75
75
  data: generateEntryPointData(type)
@@ -80,7 +80,7 @@ async function createVueLibraryEntryPoint(type = "vue-components") {
80
80
  log.success("Created Vue Component Library Entry Point");
81
81
  }
82
82
  async function createWebComponentLibraryEntryPoint(type = "web-components") {
83
- log.info("Creating Web Component Library Entry Point...");
83
+ log.info("Ensuring Web Component Library Entry Point...");
84
84
  await writeTextFile({
85
85
  path: libraryEntryPath(type),
86
86
  data: generateEntryPointData(type)
@@ -91,7 +91,7 @@ async function createWebComponentLibraryEntryPoint(type = "web-components") {
91
91
  log.success("Created Web Component Library Entry Point");
92
92
  }
93
93
  async function createFunctionLibraryEntryPoint(type = "functions") {
94
- log.info("Creating Function Library Entry Point...");
94
+ log.info("Ensuring Function Library Entry Point...");
95
95
  await writeTextFile({
96
96
  path: libraryEntryPath(type),
97
97
  data: generateEntryPointData(type)
@@ -4,7 +4,7 @@ import {log} from "@stacksjs/logging";
4
4
  import {writeTextFile} from "@stacksjs/storage";
5
5
  import {packageJsonPath} from "@stacksjs/path";
6
6
 
7
- // /home/runner/work/stacks/stacks/config/library.ts
7
+ // ../../../../config/library.ts
8
8
  var library_default = {
9
9
  name: "hello-world",
10
10
  owner: "@stacksjs",
@@ -4,7 +4,7 @@ import {log} from "@stacksjs/logging";
4
4
  import {customElementsDataPath} from "@stacksjs/path";
5
5
  import {writeTextFile} from "@stacksjs/storage";
6
6
 
7
- // /home/runner/work/stacks/stacks/config/library.ts
7
+ // ../../../../config/library.ts
8
8
  var library_default = {
9
9
  name: "hello-world",
10
10
  owner: "@stacksjs",
package/dist/src/index.js CHANGED
@@ -84,6 +84,7 @@ async function runDocsDevServer(options) {
84
84
  import process from "process";
85
85
  import {log as log3} from "@stacksjs/logging";
86
86
  import {Action as Action2, NpmScript} from "@stacksjs/enums";
87
+ import {runCommand as runCommand2} from "@stacksjs/cli";
87
88
  import {runNpmScript} from "@stacksjs/utils";
88
89
  import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
89
90
  async function invoke(options) {
@@ -99,6 +100,8 @@ async function invoke(options) {
99
100
  await generateIdeHelpers(options);
100
101
  else if (options?.componentMeta)
101
102
  await generateComponentMeta(options);
103
+ else if (options?.coreSymlink)
104
+ await generateCoreSymlink();
102
105
  }
103
106
  function generate(options) {
104
107
  return invoke(options);
@@ -167,10 +170,13 @@ function generateMigrations() {
167
170
  log3.success("Successfully updated migrations");
168
171
  }
169
172
  function generatePkgxConfig() {
170
- log3.success("Successfully generated `./pkgx.yaml` based on your configs");
173
+ log3.success("Successfully generated `./pkgx.yaml` based on your config");
171
174
  }
172
175
  async function generateSeeder() {
173
176
  }
177
+ async function generateCoreSymlink() {
178
+ await runCommand2(`ln -s ${frameworkPath()} ${projectPath2(".stacks")}`);
179
+ }
174
180
 
175
181
  // src/examples.ts
176
182
  import process2 from "process";
@@ -568,6 +574,7 @@ export {
568
574
  generateMigrations,
569
575
  generateLibEntries,
570
576
  generateIdeHelpers,
577
+ generateCoreSymlink,
571
578
  generateComponentMeta,
572
579
  generate,
573
580
  createPage,
@@ -86,6 +86,7 @@ async function runDocsDevServer(options) {
86
86
  import process from "process";
87
87
  import {log as log3} from "@stacksjs/logging";
88
88
  import {Action as Action2, NpmScript} from "@stacksjs/enums";
89
+ import {runCommand as runCommand2} from "@stacksjs/cli";
89
90
  import {runNpmScript} from "@stacksjs/utils";
90
91
  import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
91
92
  async function invoke(options) {
@@ -101,6 +102,8 @@ async function invoke(options) {
101
102
  await generateIdeHelpers(options);
102
103
  else if (options?.componentMeta)
103
104
  await generateComponentMeta(options);
105
+ else if (options?.coreSymlink)
106
+ await generateCoreSymlink();
104
107
  }
105
108
  function generate(options) {
106
109
  return invoke(options);
@@ -169,10 +172,13 @@ function generateMigrations() {
169
172
  log3.success("Successfully updated migrations");
170
173
  }
171
174
  function generatePkgxConfig() {
172
- log3.success("Successfully generated `./pkgx.yaml` based on your configs");
175
+ log3.success("Successfully generated `./pkgx.yaml` based on your config");
173
176
  }
174
177
  async function generateSeeder() {
175
178
  }
179
+ async function generateCoreSymlink() {
180
+ await runCommand2(`ln -s ${frameworkPath()} ${projectPath2(".stacks")}`);
181
+ }
176
182
 
177
183
  // src/examples.ts
178
184
  import process2 from "process";
@@ -51,4 +51,8 @@ if (options?.dependencies || options?.all)
51
51
  await runAction(Action.UpgradeDeps, options);
52
52
  if (options?.bun || options?.all)
53
53
  await runAction(Action.UpgradeBun, options);
54
+ if (options?.shell || options?.all)
55
+ await runAction(Action.UpgradeShell, options);
56
+ if (options?.binary || options?.all)
57
+ await runAction(Action.UpgradeBinary, options);
54
58
  process.exit(ExitCode.InvalidArgument);
@@ -7,7 +7,7 @@ import {projectPath} from "@stacksjs/path";
7
7
  import * as storage from "@stacksjs/storage";
8
8
  import {NpmScript} from "@stacksjs/enums";
9
9
  // package.json
10
- var version = "0.58.71";
10
+ var version = "0.58.73";
11
11
 
12
12
  // src/upgrade.ts
13
13
  function checkForUncommittedChanges(options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
- "version": "0.58.71",
4
+ "version": "0.58.73",
5
5
  "description": "The Stacks actions.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
@@ -0,0 +1,24 @@
1
+ import process from 'node:process'
2
+ import { runCommand } from '@stacksjs/cli'
3
+ import { findStacksProjects } from '@stacksjs/utils'
4
+
5
+ const projects = await findStacksProjects(undefined, { quiet: true })
6
+
7
+ // eslint-disable-next-line no-console
8
+ console.log('projects', projects)
9
+
10
+ // need to loop over the projects and then trigger `buddy ports` for each project (which returns a list of ports)
11
+ for (const project of projects) {
12
+ // eslint-disable-next-line no-console
13
+ console.log('project', project)
14
+ // this right now causes a loop of the same project
15
+ const ports = await runCommand(`buddy ports --project ${project}`)
16
+ // eslint-disable-next-line no-console
17
+ console.log('proj', project)
18
+ // eslint-disable-next-line no-console
19
+ console.log('ports', ports)
20
+ }
21
+
22
+ process.exit(0)
23
+ // then we can check if the port is in use and if it is, we can prompt the user to kill the process or to auto assign a new port
24
+ // if the port is not in use, we can start the project
package/src/dev/api.ts CHANGED
@@ -8,7 +8,7 @@ const options = parseOptions()
8
8
  log.debug('Running API dev server via', `bunx vite --config ${p.vitePath('src/api.ts')}`, options)
9
9
 
10
10
  serve({
11
- port: config.app.ports?.api, // defaults to 3999
11
+ port: config.ports?.api, // defaults to 3008
12
12
  })
13
13
 
14
14
  // the reason we start a Vite dev server next is because we need the Bun server proxied by vite
@@ -0,0 +1,21 @@
1
+ import process from 'node:process'
2
+ import { findStacksProjects } from '@stacksjs/utils'
3
+ import { log } from '@stacksjs/logging'
4
+ import { parseOptions } from 'stacks/cli'
5
+
6
+ try {
7
+ const options = parseOptions()
8
+ const projects = await findStacksProjects(undefined, options)
9
+
10
+ if (projects.length > 0) {
11
+ log.info('Found Projects:')
12
+ // eslint-disable-next-line no-console
13
+ projects.forEach(project => console.log(` - ${project}`))
14
+ process.exit()
15
+ }
16
+
17
+ log.info('No Stacks Projects found.')
18
+ }
19
+ catch (error: any) {
20
+ log.error('Error searching for Stacks projects:', error)
21
+ }
@@ -1,89 +1,25 @@
1
+ import { readdir } from 'node:fs/promises'
1
2
  import { path as p } from '@stacksjs/path'
2
- import { storage } from '@stacksjs/storage'
3
- import { env as e, enums } from '@stacksjs/env'
4
3
  import { logger } from '@stacksjs/logging'
5
- import { envKeys } from '../../../../env'
6
-
7
- log.debug('Generating type Action types...')
8
-
9
- // generate ./storage/framework/types/env.d.ts file from .env
10
- const envTypes = `
11
- // This file is auto-generated by Stacks. Do not edit this file manually.
12
- // If you want to edit Action types, please edit the app/Actions/* validations
13
- //
14
- // For more information, please visit: https://stacksjs.org/docs
15
-
16
- declare module 'bun' {
17
- namespace env {
18
- ${envKeys.map((key) => {
19
- let type: string | undefined = typeof e[key]
20
- let value: string | boolean | number | undefined = e[key]
21
-
22
- if (!value) {
23
- if (enums[key]) {
24
- type = enums[key]?.map(item => `'${item}'`).join(' | ')
25
- value = enums[key]?.[0] // default to the first enum value
26
- }
27
- else {
28
- switch (type) {
29
- case 'number':
30
- value = '0'
31
- break
32
- case 'boolean':
33
- value = false
34
- break
35
- default:
36
- value = ''
37
- }
38
- }
39
- }
40
-
41
- type = 'string'
42
- if (typeof value === 'string') {
43
- if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
44
- type = 'boolean'
45
- }
46
- else if (!Number.isNaN(Number.parseFloat(value)) && Number.isFinite(Number(value))) {
47
- type = 'number'
48
- }
49
- else if (enums[key]) {
50
- // @ts-expect-error enums[key] is defined
51
- type = enums[key].map(item => `'${item}'`).join(' | ')
52
- }
53
- }
54
-
55
- else if (typeof value === 'number') {
56
- type = 'number'
57
- }
58
-
59
- else if (typeof value === 'boolean') {
60
- type = 'boolean'
61
- }
4
+ import { storage } from '@stacksjs/storage'
62
5
 
63
- return `const ${key}: ${type}`
64
- }).join('\n ')}
65
- }
66
- }
67
- `
6
+ logger.log('Generating action types...')
68
7
 
69
- await storage.writeFile(p.frameworkPath('types/env.d.ts'), envTypes)
8
+ const domain = 'Actions'
70
9
 
71
- logger.log(' - ./storage/framework/env.ts')
10
+ const files = await readdir(p.appPath(domain), { recursive: true })
72
11
 
73
- // generate ./storage/framework/env.ts file based on Bun.env
74
- const env = `
75
- // This file is auto-generated by Stacks. Do not edit this file manually.
76
- // If you want to change the environment variables, please edit the .env file.
12
+ const validActions = `// This file is auto-generated by Stacks. Do not edit this file manually.
13
+ // If you wish to rename an action, please do so by editing the file name.
77
14
  //
78
15
  // For more information, please visit: https://stacksjs.org/docs
79
16
 
80
- export const envKeys = [
81
- ${envKeys.map(key => `'${key}'`).join(',\n ')}
82
- ] as const
83
-
84
- export type EnvKey = typeof envKeys[number]
17
+ export type ActionPath = ${
18
+ files
19
+ .filter(file => file.endsWith('.ts'))
20
+ .map(value => `'${domain}/${value.replace('.ts', '')}'`)
21
+ .join(' | ')
22
+ }
85
23
  `
86
24
 
87
- await storage.writeFile(p.frameworkPath('env.ts'), env)
88
-
89
- logger.log(' - ./storage/framework/env.d.ts')
25
+ await storage.writeFile(p.frameworkPath('types/actions.d.ts'), validActions)
@@ -1 +1,44 @@
1
- // TODO: generate Caddyfile for the core app
1
+ import os from 'node:os'
2
+ import { logger } from '@stacksjs/logging'
3
+ import { findStacksProjects } from '@stacksjs/utils'
4
+
5
+ logger.log('Generating Local Reverse Proxy...')
6
+
7
+ const options = { quiet: true }
8
+ const projects = await findStacksProjects(os.homedir(), options)
9
+
10
+ // TODO: need to generate one caddyfile that can be used for all projects on the system (each projects gets its own *.localhost domain)
11
+ // TODO: need to create a watcher
12
+ // TODO: need to create an action that can be run to add a new project
13
+ // TODO: need to an action that checks whether there are an env port clashes aross projects
14
+
15
+ // eslint-disable-next-line no-console
16
+ console.log(projects)
17
+
18
+ // const caddyfile = `stacksjs.localhost {
19
+ // route {
20
+ // @
21
+
22
+ // @libs {
23
+ // path /libs/*
24
+ // }
25
+
26
+ // handle @libs {
27
+ // reverse_proxy localhost:3003
28
+ // }
29
+
30
+ // @api {
31
+ // path /api/*
32
+ // }
33
+
34
+ // handle @api {
35
+ // reverse_proxy localhost:3999
36
+ // }
37
+
38
+ // handle {
39
+ // reverse_proxy localhost:3000
40
+ // }
41
+ // }
42
+ // }`
43
+
44
+ // await storage.writeFile(p.frameworkPath('types/actions.d.ts'), caddyfile)
@@ -4,7 +4,7 @@ import { writeTextFile } from '@stacksjs/storage'
4
4
  import { projectPath } from '@stacksjs/path'
5
5
  import { cli } from '@stacksjs/config'
6
6
 
7
- log.info('Creating Vue Component Library Entry Point...')
7
+ log.info('Ensuring Component Library Entry Point...')
8
8
 
9
9
  if (!cli.command) {
10
10
  log.error('No command defined in the CLI configuration')
@@ -2,6 +2,7 @@ import process from 'node:process'
2
2
  import { log } from '@stacksjs/logging'
3
3
  import { Action, NpmScript } from '@stacksjs/enums'
4
4
  import type { GeneratorOptions } from '@stacksjs/types'
5
+ import { runCommand } from '@stacksjs/cli'
5
6
  import { runNpmScript } from '@stacksjs/utils'
6
7
  import { frameworkPath, projectPath } from '@stacksjs/path'
7
8
  import { runAction } from '../helpers'
@@ -26,6 +27,9 @@ export async function invoke(options?: GeneratorOptions) {
26
27
 
27
28
  else if (options?.componentMeta)
28
29
  await generateComponentMeta(options)
30
+
31
+ else if (options?.coreSymlink)
32
+ await generateCoreSymlink()
29
33
  }
30
34
 
31
35
  export function generate(options: GeneratorOptions) {
@@ -124,9 +128,13 @@ export function generatePkgxConfig() {
124
128
  // write the yaml string to a file in your project root
125
129
  // files.put(projectPath('./pkgx.yaml'), yamlStr)
126
130
 
127
- log.success('Successfully generated `./pkgx.yaml` based on your configs')
131
+ log.success('Successfully generated `./pkgx.yaml` based on your config')
128
132
  }
129
133
 
130
134
  export async function generateSeeder() {
131
135
  // await seed()
132
136
  }
137
+
138
+ export async function generateCoreSymlink() {
139
+ await runCommand(`ln -s ${frameworkPath()} ${projectPath('.stacks')}`)
140
+ }
@@ -0,0 +1,3 @@
1
+ import { generateCoreSymlink } from '@stacksjs/actions'
2
+
3
+ await generateCoreSymlink()
@@ -30,7 +30,7 @@ export async function createLibraryEntryPoint(type: LibraryType) {
30
30
  }
31
31
 
32
32
  export async function createVueLibraryEntryPoint(type: LibraryType = 'vue-components') {
33
- log.info('Creating Vue Component Library Entry Point...')
33
+ log.info('Ensuring Component Library Entry Point...')
34
34
 
35
35
  await writeTextFile({
36
36
  path: libraryEntryPath(type),
@@ -44,7 +44,7 @@ export async function createVueLibraryEntryPoint(type: LibraryType = 'vue-compon
44
44
  }
45
45
 
46
46
  export async function createWebComponentLibraryEntryPoint(type: LibraryType = 'web-components') {
47
- log.info('Creating Web Component Library Entry Point...')
47
+ log.info('Ensuring Web Component Library Entry Point...')
48
48
 
49
49
  await writeTextFile({
50
50
  path: libraryEntryPath(type),
@@ -58,7 +58,7 @@ export async function createWebComponentLibraryEntryPoint(type: LibraryType = 'w
58
58
  }
59
59
 
60
60
  export async function createFunctionLibraryEntryPoint(type: LibraryType = 'functions') {
61
- log.info('Creating Function Library Entry Point...')
61
+ log.info('Ensuring Function Library Entry Point...')
62
62
 
63
63
  await writeTextFile({
64
64
  path: libraryEntryPath(type),
@@ -0,0 +1,43 @@
1
+ import process from 'node:process'
2
+ import { path } from '@stacksjs/path'
3
+ import { runCommand } from '@stacksjs/cli'
4
+ import { log } from '@stacksjs/logging'
5
+ import { fs, storage } from '@stacksjs/storage'
6
+
7
+ /**
8
+ * Move the `stacks` binary to the user's home directory.
9
+ */
10
+
11
+ const source = path.buddyPath('dist/stacks')
12
+ const destination = path.homeDir('.stacks/bin/stacks')
13
+ const destinationDir = path.homeDir('.stacks/bin/')
14
+
15
+ log.info('Upgrading `stacks`...')
16
+
17
+ // ensure the latest binary is generated
18
+ const result = await runCommand('bun compile.ts', { cwd: path.buddyPath() })
19
+
20
+ if (result.isErr()) {
21
+ log.error('There was an error compiling the binary', result.error)
22
+ process.exit()
23
+ }
24
+
25
+ // Check if the source exists (it should be, because bun compile.ts was successful)
26
+ if (await storage.exists(source)) {
27
+ try {
28
+ log.info('Updating Binary...')
29
+ log.info(`Source: ${source}`) // TODO: should be debug
30
+ log.info(`Destination: ${destination}`) // TODO: should be debug
31
+
32
+ await fs.ensureDir(destinationDir) // Ensure the destination directory exists
33
+ await fs.move(source, destination, { overwrite: true })
34
+
35
+ log.success('Binary Latest Version Is Used')
36
+ }
37
+ catch (err: any) {
38
+ log.error(err)
39
+ }
40
+ }
41
+ else {
42
+ log.error(`Binary source not found: ${source}`)
43
+ }
@@ -16,6 +16,12 @@ if (options?.dependencies || options?.all)
16
16
  if (options?.bun || options?.all)
17
17
  await runAction(Action.UpgradeBun, options)
18
18
 
19
+ if (options?.shell || options?.all)
20
+ await runAction(Action.UpgradeShell, options)
21
+
22
+ if (options?.binary || options?.all)
23
+ await runAction(Action.UpgradeBinary, options)
24
+
19
25
  process.exit(ExitCode.InvalidArgument)
20
26
 
21
27
  // TODO: also update CI files & configurations, and other files, possibly (taze?)
@@ -0,0 +1,64 @@
1
+ import process from 'node:process'
2
+ import { $ } from 'bun'
3
+ import { path as p } from 'stacks/path'
4
+ import { log } from 'stacks/logging'
5
+ import { ExitCode } from 'stacks/types'
6
+ import { writeFile } from 'stacks/storage'
7
+ import { italic, runCommand } from 'stacks/cli'
8
+
9
+ const homePath = (await $`echo $HOME`.text()).trim()
10
+ const zshrcPath = p.join(homePath, '.zshrc')
11
+ const pluginPath = p.shellPath('src/buddy.plugin.zsh')
12
+ const customPath = p.join(homePath, '.oh-my-zsh/custom/plugins/buddy/')
13
+
14
+ log.info(`Setting up Oh My Zsh via ${zshrcPath}...`)
15
+ $.cwd(p.dirname(zshrcPath))
16
+ let data = await $`cat ${p.basename(zshrcPath)}`.text()
17
+
18
+ // Manipulate the data
19
+ const pluginLineRegex = /^(?!#).*plugins=\(([^)]+)\)/m // ensure it's not a comment
20
+ const match = data.match(pluginLineRegex)
21
+
22
+ if (match) {
23
+ // Split the captured group by any whitespace and filter out empty strings
24
+ const plugins = match[1]?.split(/\s+/).filter(Boolean)
25
+ if (!plugins) {
26
+ log.error('Maybe the plugins line in your .zshrc file could not be found? If this continues being an issue, please reach out to us on Discord.')
27
+ process.exit(ExitCode.FatalError)
28
+ }
29
+
30
+ // 2. Add buddy to the list of plugins if it's not already there
31
+ if (!plugins.includes('buddy')) {
32
+ plugins.push('buddy')
33
+ // Trim each plugin name and ensure it's formatted correctly
34
+ const formattedPlugins = plugins.map(plugin => plugin.trim()).join('\n ')
35
+ const newPluginLine = `plugins=(\n ${formattedPlugins}\n)`
36
+ // Replace the old plugin line with the new one
37
+ data = data.replace(pluginLineRegex, newPluginLine)
38
+ // Write the data back to the file
39
+ await writeFile(zshrcPath, data)
40
+
41
+ // need to copy plugin to ~/.oh-my-zsh/custom/plugins
42
+ log.info(`Copying buddy zsh plugin ${pluginPath} to ${customPath}...`)
43
+
44
+ // create customPath if it doesn't exist
45
+ await runCommand(`mkdir -p ${customPath}`)
46
+ await runCommand(`cp -rf ${pluginPath} ${customPath}`)
47
+ // await runCommand(`source ${customPath}/src/buddy.plugin.zsh`)
48
+
49
+ log.success('Copied buddy zsh plugin')
50
+ }
51
+ else {
52
+ log.info('Buddy is already set up') // in other words, it is integrated in their shell
53
+ log.info('Ensuring `buddy` is updated...')
54
+ await runCommand(`cp -rf ${pluginPath} ${customPath}`)
55
+ log.success('Updated buddy zsh plugin to latest version')
56
+ }
57
+ }
58
+
59
+ log.success('Oh My Zsh Setup Complete')
60
+ log.info(italic('To see changes reflect, you may need to open a new terminal window'))
61
+
62
+ // if using the vscode terminal, show the message
63
+ if (process.env.TERM_PROGRAM === 'vscode')
64
+ log.info('⌘⇧P terminal.create.new.terminal')