Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Feb 11, 2024
1 parent 188962c commit c21ef72
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 82 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions config/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export default {
name: 'My Custom CLI',
command: 'custom-cli', // enables `custom-cli <command> <options>`
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
3 changes: 0 additions & 3 deletions config/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
1 change: 0 additions & 1 deletion pkgx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 35 additions & 34 deletions storage/framework/core/buddy/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions storage/framework/core/cli/src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export * from './parse'
export * from './exec'
export * from './run'
export * from './spinner'
export * from './utilities'
export * from './utils'
4 changes: 2 additions & 2 deletions storage/framework/core/cli/src/run.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -30,7 +30,7 @@ import { log } from './console'
* ```
*/
export async function runCommand(command: string, options?: CliOptions): Promise<Result<Subprocess, CommandError>> {
log.debug('runCommand:', underline(italic(command)))
log.debug('runCommand:', command)
log.debug('runCommand Options:', options)

return await exec(command, options)
Expand Down
2 changes: 0 additions & 2 deletions storage/framework/core/cli/src/utilities.ts

This file was deleted.

51 changes: 51 additions & 0 deletions storage/framework/core/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * as kolorist from 'kolorist'

export {
stripAnsi,
centerAlign,
Expand All @@ -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'
1 change: 0 additions & 1 deletion storage/framework/core/config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const config: StacksOptions = {
export const {
ai,
analytics,
api,
app,
cache,
cloud,
Expand Down
3 changes: 1 addition & 2 deletions storage/framework/core/config/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -122,8 +123,6 @@ export default {
// version: 'v1',
},

ai: false,
docs: false,
fileSystem: false,
},

Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/logging/build.ts
Original file line number Diff line number Diff line change
@@ -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,
})

Expand Down
31 changes: 17 additions & 14 deletions storage/framework/core/logging/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions storage/framework/core/types/src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
55 changes: 36 additions & 19 deletions storage/framework/scripts/build
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c21ef72

Please sign in to comment.