diff --git a/bun.lockb b/bun.lockb index 760f09ee34..0ff09a32ef 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/config/cli.ts b/config/cli.ts index 62d7bc04da..c407119a78 100644 --- a/config/cli.ts +++ b/config/cli.ts @@ -11,4 +11,5 @@ export default { name: 'My Custom CLI', command: 'custom-cli', // enables `custom-cli ` description: 'This is an example command to illustrate how to create your own commands. Check out `../app/commands` for more.', + deploy: true, // deploys CLI setup endpoint (./bootstrap) } satisfies BinaryConfig diff --git a/config/cloud.ts b/config/cloud.ts index c37dd75b4e..50d9d57c48 100644 --- a/config/cloud.ts +++ b/config/cloud.ts @@ -47,9 +47,6 @@ export default { timeout: 30, }, - ai: true, // deploys AI endpoints - cli: true, // deploys CLI setup endpoint (./bootstrap) - docs: true, // deploys documentation fileSystem: true, // enables file system // compute: {}, diff --git a/pkgx.yaml b/pkgx.yaml index e36db5f7b6..a82d87c75d 100644 --- a/pkgx.yaml +++ b/pkgx.yaml @@ -13,4 +13,3 @@ dependencies: stedolan.github.io/jq: ^1.7 httpie.io: ^3.2.2 rust-lang.org: ^1.74.1 # optional, for certain dev purposes only - gnu.org/coreutils: ^9.4 # nproc does not ship everywhere but is included in coreutils diff --git a/storage/framework/core/buddy/src/commands/dev.ts b/storage/framework/core/buddy/src/commands/dev.ts index 78c52bc21d..d875b1a835 100644 --- a/storage/framework/core/buddy/src/commands/dev.ts +++ b/storage/framework/core/buddy/src/commands/dev.ts @@ -12,7 +12,7 @@ import { } from '@stacksjs/actions' import { ExitCode } from '@stacksjs/types' import type { CLI, DevOptions } from '@stacksjs/types' -import { intro, log, outro, prompt, runCommand } from '@stacksjs/cli' +import { intro, log, outro, runCommand } from '@stacksjs/cli' import { libsPath } from '@stacksjs/path' export function dev(buddy: CLI) { @@ -91,39 +91,40 @@ export function dev(buddy: CLI) { } if (wantsInteractive(options)) { - const answer = await prompt.require() - .select(descriptions.select, { - options: [ - { value: 'all', label: 'All' }, - { value: 'frontend', label: 'Frontend' }, - { value: 'api', label: 'Backend' }, - { value: 'dashboard', label: 'Dashboard' }, - { value: 'desktop', label: 'Desktop' }, - { value: 'email', label: 'Email' }, - { value: 'components', label: 'Components' }, - { value: 'docs', label: 'Documentation' }, - ], - }) - - if (answer === 'components') { - await runComponentsDevServer(options) - } - else if (answer === 'api') { - await runApiDevServer(options) - } - else if (answer === 'dashboard') { - await runDashboardDevServer(options) - } - // else if (answer === 'email') - // await runEmailDevServer(options) - else if (answer === 'docs') { - await runDocsDevServer(options) - } - - else { - log.error('Invalid option during interactive mode') - process.exit(ExitCode.InvalidArgument) - } + // TODO: uncomment this when prompt is available + // const answer = await prompt.require() + // .select(descriptions.select, { + // options: [ + // { value: 'all', label: 'All' }, + // { value: 'frontend', label: 'Frontend' }, + // { value: 'api', label: 'Backend' }, + // { value: 'dashboard', label: 'Dashboard' }, + // { value: 'desktop', label: 'Desktop' }, + // { value: 'email', label: 'Email' }, + // { value: 'components', label: 'Components' }, + // { value: 'docs', label: 'Documentation' }, + // ], + // }) + // + // if (answer === 'components') { + // await runComponentsDevServer(options) + // } + // else if (answer === 'api') { + // await runApiDevServer(options) + // } + // else if (answer === 'dashboard') { + // await runDashboardDevServer(options) + // } + // // else if (answer === 'email') + // // await runEmailDevServer(options) + // else if (answer === 'docs') { + // await runDocsDevServer(options) + // } + // + // else { + // log.error('Invalid option during interactive mode') + // process.exit(ExitCode.InvalidArgument) + // } } else { diff --git a/storage/framework/core/cli/src/exec.ts b/storage/framework/core/cli/src/exec.ts index be72ceadae..953b042cc2 100644 --- a/storage/framework/core/cli/src/exec.ts +++ b/storage/framework/core/cli/src/exec.ts @@ -2,7 +2,8 @@ import process from 'node:process' import { type Result, err, handleError, ok } from '@stacksjs/error-handling' import type { CliOptions, StacksError, Subprocess } from '@stacksjs/types' import { ExitCode } from '@stacksjs/types' -import { italic, log, underline } from './' +import { italic } from './utils' +import { log } from './' /** * Execute a command. @@ -32,7 +33,7 @@ export async function exec(command: string | string[], options?: CliOptions): Pr if (!cmd) return err(handleError(`Failed to parse command: ${cmd}`, options)) - log.debug('Running exec:', italic(underline(command))) + log.debug('Running exec:', Array.isArray(command) ? command.join(' ') : command) log.debug('cmd:', cmd) log.debug('Options:', options) diff --git a/storage/framework/core/cli/src/index.ts b/storage/framework/core/cli/src/index.ts index 1dc17e709f..6b50bbd615 100644 --- a/storage/framework/core/cli/src/index.ts +++ b/storage/framework/core/cli/src/index.ts @@ -7,4 +7,4 @@ export * from './parse' export * from './exec' export * from './run' export * from './spinner' -export * from './utilities' +export * from './utils' diff --git a/storage/framework/core/cli/src/run.ts b/storage/framework/core/cli/src/run.ts index e87ab8b2fe..e52b270b52 100644 --- a/storage/framework/core/cli/src/run.ts +++ b/storage/framework/core/cli/src/run.ts @@ -1,7 +1,7 @@ import type { CliOptions, CommandError, Subprocess } from '@stacksjs/types' import type { Result } from '@stacksjs/error-handling' import { exec, execSync } from './exec' -import { italic, underline } from './utilities' +import { italic } from './utils' import { log } from './console' /** @@ -30,7 +30,7 @@ import { log } from './console' * ``` */ export async function runCommand(command: string, options?: CliOptions): Promise> { - log.debug('runCommand:', underline(italic(command))) + log.debug('runCommand:', command) log.debug('runCommand Options:', options) return await exec(command, options) diff --git a/storage/framework/core/cli/src/utilities.ts b/storage/framework/core/cli/src/utilities.ts deleted file mode 100644 index fce6b93ad4..0000000000 --- a/storage/framework/core/cli/src/utilities.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * as kolorist from 'kolorist' -export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow, ansi256, trueColor, trueColorBg, stripColors } from 'kolorist' diff --git a/storage/framework/core/cli/src/utils.ts b/storage/framework/core/cli/src/utils.ts index 599d7673b6..77199aae5b 100644 --- a/storage/framework/core/cli/src/utils.ts +++ b/storage/framework/core/cli/src/utils.ts @@ -1,3 +1,5 @@ +export * as kolorist from 'kolorist' + export { stripAnsi, centerAlign, @@ -9,3 +11,52 @@ export { getColor, colorize, } from 'consola/utils' + +export { + ansi256Bg, + bgBlack, + bgBlue, + bgCyan, + bgGray, + bgGreen, + bgLightBlue, + bgLightCyan, + bgLightGray, + bgLightGreen, + bgLightMagenta, + bgLightRed, + bgLightYellow, + bgMagenta, + bgRed, + bgWhite, + bgYellow, + black, + blue, + bold, + cyan, + dim, + gray, + green, + hidden, + inverse, + italic, + lightBlue, + lightCyan, + lightGray, + lightGreen, + lightMagenta, + lightRed, + lightYellow, + link, + magenta, + red, + reset, + strikethrough, + underline, + white, + yellow, + ansi256, + trueColor, + trueColorBg, + stripColors, +} from 'kolorist' diff --git a/storage/framework/core/config/src/config.ts b/storage/framework/core/config/src/config.ts index 81f147dbf7..c5eb0de568 100644 --- a/storage/framework/core/config/src/config.ts +++ b/storage/framework/core/config/src/config.ts @@ -10,7 +10,6 @@ export const config: StacksOptions = { export const { ai, analytics, - api, app, cache, cloud, diff --git a/storage/framework/core/config/src/defaults.ts b/storage/framework/core/config/src/defaults.ts index c9b560d8a5..1274d1f852 100644 --- a/storage/framework/core/config/src/defaults.ts +++ b/storage/framework/core/config/src/defaults.ts @@ -56,6 +56,7 @@ export default { command: 'my-custom-cli', description: 'Stacks is a full-stack framework for TypeScript.', source: p.appPath('commands'), + deploy: false, }, cache: { @@ -122,8 +123,6 @@ export default { // version: 'v1', }, - ai: false, - docs: false, fileSystem: false, }, diff --git a/storage/framework/core/logging/build.ts b/storage/framework/core/logging/build.ts index e9167f3223..1a33361ee3 100644 --- a/storage/framework/core/logging/build.ts +++ b/storage/framework/core/logging/build.ts @@ -1,6 +1,6 @@ import { log, runCommand } from '../cli/src' -const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm --external @stacksjs/types --target bun', { +const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm --external @stacksjs/types --external @stacksjs/cli --external @stacksjs/path --external consola --target bun', { cwd: import.meta.dir, }) diff --git a/storage/framework/core/logging/src/index.ts b/storage/framework/core/logging/src/index.ts index 65c52f676c..a8678ef5b3 100644 --- a/storage/framework/core/logging/src/index.ts +++ b/storage/framework/core/logging/src/index.ts @@ -1,26 +1,29 @@ import process from 'node:process' import { consola, createConsola } from 'consola' import { ExitCode } from '@stacksjs/types' -import { logger } from '@stacksjs/config' +import { logger as logConfig } from '@stacksjs/config' import { logsPath } from '@stacksjs/path' import type { Prompt } from '@stacksjs/cli' import { buddyOptions, prompt as getPrompt } from '@stacksjs/cli' -/** - * This regex checks for: - * - --verbose true or --verbose=true exactly at the end of the string ($ denotes the end of the string). - * - --verbose - followed by optional spaces at the end. - * - --verbose followed by optional spaces at the end. - * - * .trim() is used on options to ensure any trailing spaces in the entire options string do not affect the regex match. - */ -const verboseRegex = /--verbose(?!(\s*=\s*false|\s+false))(\s+|=true)?($|\s)/ -let logLevel = config.logger.level -if (verboseRegex.test(buddyOptions().trim())) - logLevel = 4 +export function logLevel() { + /** + * This regex checks for: + * - --verbose true or --verbose=true exactly at the end of the string ($ denotes the end of the string). + * - --verbose - followed by optional spaces at the end. + * - --verbose followed by optional spaces at the end. + * + * .trim() is used on options to ensure any trailing spaces in the entire options string do not affect the regex match. + */ + const verboseRegex = /--verbose(?!(\s*=\s*false|\s+false))(\s+|=true)?($|\s)/ + + if (verboseRegex.test(buddyOptions().trim())) + return 4 + return logConfig.level +} export const logger = createConsola({ - level: logLevel, + level: logLevel(), // fancy: true, // formatOptions: { // columns: 80, diff --git a/storage/framework/core/types/src/binary.ts b/storage/framework/core/types/src/binary.ts index 569032c846..bc3a6ab066 100644 --- a/storage/framework/core/types/src/binary.ts +++ b/storage/framework/core/types/src/binary.ts @@ -6,6 +6,7 @@ export interface BinaryOptions { command: string description: string source: string + deploy: boolean // path: string // TODO: add this for a configurable path where the commands are located } diff --git a/storage/framework/scripts/build b/storage/framework/scripts/build index 9c6b469898..b23d16a683 100755 --- a/storage/framework/scripts/build +++ b/storage/framework/scripts/build @@ -1,28 +1,45 @@ #!/bin/sh +# TODO: implement parallelism + # Get the script's directory script_dir=$(readlink -f $(dirname "$0")) -# Get the number of CPU cores to determine parallelism level -# Adjust this as needed or dynamically determine it -num_cores=$(nproc --all) +# Get all directories in the core path & sort them alphabetically +dirs=$(find "$script_dir/../core" -type d -maxdepth 1 | sort) + +# Check if no directories found +if [ -z "$dirs" ]; then + echo "No core packages found" + exit 1 +fi + +# Loop through each directory +for dir in $dirs; do + # Skip the ../core directory because it has no package.json + if [ "$dir" = "$script_dir/../core" ] || [ "$dir" = "$script_dir/../core/bun-create" ]; then + continue + fi -# Find all directories in the core path, excluding the ones without package.json -# and pass them to xargs to run builds in parallel -find "$script_dir/../core" -mindepth 1 -maxdepth 1 -type d ! -name 'bun-create' -print0 | xargs -0 -n 1 -P $num_cores sh -c ' -dir=$1 -echo "" -echo "🏗️ Building..." -echo "📦 $dir" + echo "" + echo "🏗️ Building..." + echo "📦 $dir" -# Change to the directory -cd $dir + # Change to the directory + cd $dir + + # Build the package + bun run build + + # Check if the build command was successful + if [ $? -ne 0 ]; then + echo "Failed to build $dir" + exit 1 + fi -# Build the package -if bun run build; then echo "✅ Build complete" -else - echo "❌ Failed to build $dir" - exit 1 -fi -' sh + echo "" + + # Change back to the original directory + cd - >/dev/null +done