Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/qvac-cli/src/bundle-sdk/bare-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function runBarePack (options) {

const majorVersion = await detectBarePackMajorVersion(barePackBin, entryPath)
const platformFlag = majorVersion < 2 ? '--target' : '--host'
logger.verbose(
logger.debug(
`📦 Detected bare-pack v${majorVersion} (using ${platformFlag})`
)

Expand All @@ -66,10 +66,10 @@ export async function runBarePack (options) {
entryPath
]

logger.verbose(`\n📦 Running: ${barePackBin} ${args.join(' ')}`)
logger.debug(`\n📦 Running: ${barePackBin} ${args.join(' ')}`)

const proc = spawn(barePackBin, args, {
stdio: logLevel === 'quiet' ? 'ignore' : 'inherit'
stdio: logLevel === 'silent' ? 'ignore' : 'inherit'
})

proc.on('close', (code) => {
Expand Down
58 changes: 29 additions & 29 deletions packages/qvac-cli/src/bundle-sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,42 @@ export async function bundleSdk (options = {}) {
const pearWorkerEntryPath = path.join(outputDir, 'worker.pear.entry.mjs')
const bundlePath = path.join(outputDir, 'worker.bundle.js')

let logLevel = 'normal'
if (options.quiet) logLevel = 'quiet'
else if (options.verbose) logLevel = 'verbose'
let logLevel = 'info'
if (options.quiet) logLevel = 'silent'
else if (options.verbose) logLevel = 'debug'

const logger = createLogger(logLevel)

logger.log('🔧 QVAC SDK Worker Bundler\n')
logger.info('🔧 QVAC SDK Worker Bundler\n')

const configPath = findConfigFile(projectRoot, options.configPath)

let config = {}
if (configPath) {
logger.log(`📄 Config: ${path.relative(projectRoot, configPath)}`)
logger.info(`📄 Config: ${path.relative(projectRoot, configPath)}`)
config = await loadConfig(configPath)
} else {
logger.log('📄 Config: (none)')
logger.log('⚠️ No config file found — continuing with defaults.')
logger.log(
logger.info('📄 Config: (none)')
logger.warn('No config file found — continuing with defaults.')
logger.info(
' To customize bundling, create one of:\n' +
CONFIG_CANDIDATES.map((c) => ` - ${c}`).join('\n') +
'\n'
)
}

const sdkName = await resolveSdkName(projectRoot)
logger.log(`📦 SDK: ${sdkName}`)
logger.info(`📦 SDK: ${sdkName}`)

const importsMapPath = resolveImportsMapPath(projectRoot, sdkName)

const pluginSpecifiers = resolvePluginSpecifiers(config, sdkName, logger)
logger.log(`\n📦 Plugins to include (${pluginSpecifiers.length}):`)
logger.info(`\n📦 Plugins to include (${pluginSpecifiers.length}):`)
for (const spec of pluginSpecifiers) {
const label = parseBuiltinSpecifier(spec, sdkName)
? '✓ built-in'
: '⊕ custom'
logger.log(` ${label}: ${spec}`)
logger.info(` ${label}: ${spec}`)
}

const hosts =
Expand All @@ -104,10 +104,10 @@ export async function bundleSdk (options = {}) {

await fsp.mkdir(outputDir, { recursive: true })

logger.log('\n📝 Generating worker entry...')
logger.info('\n📝 Generating worker entry...')
const workerEntry = generateWorkerEntry(pluginSpecifiers, sdkName)
await fsp.writeFile(entryPath, workerEntry, 'utf8')
logger.log(` Created: ${path.relative(projectRoot, entryPath)}`)
logger.info(` Created: ${path.relative(projectRoot, entryPath)}`)

const pearWorker =
typeof config.pearWorker === 'string' && config.pearWorker.length > 0
Expand All @@ -125,13 +125,13 @@ export async function bundleSdk (options = {}) {
pearWorkerImport
)
await fsp.writeFile(pearWorkerEntryPath, pearWorkerEntry, 'utf8')
logger.log(` Created: ${path.relative(projectRoot, pearWorkerEntryPath)}`)
logger.log(` Using: ${path.relative(projectRoot, importsMapPath)}`)
logger.info(` Created: ${path.relative(projectRoot, pearWorkerEntryPath)}`)
logger.info(` Using: ${path.relative(projectRoot, importsMapPath)}`)

logger.log('\n🔨 Bundling with bare-pack...')
logger.log(` Hosts: ${hosts.join(', ')}`)
logger.info('\n🔨 Bundling with bare-pack...')
logger.debug(` Hosts: ${hosts.join(', ')}`)
if (deferModules.length > 0) {
logger.log(` Deferred: ${deferModules.join(', ')}`)
logger.debug(` Deferred: ${deferModules.join(', ')}`)
}

await runBarePack({
Expand All @@ -147,8 +147,8 @@ export async function bundleSdk (options = {}) {

const stats = await fsp.stat(bundlePath)
const sizeKB = (stats.size / 1024).toFixed(1)
logger.log(`\n✅ Bundle created: ${path.relative(projectRoot, bundlePath)}`)
logger.log(` Size: ${sizeKB} KB`)
logger.info(`\n✅ Bundle created: ${path.relative(projectRoot, bundlePath)}`)
logger.info(` Size: ${sizeKB} KB`)

const manifestResult = await generateAddonsManifest({
bundlePath,
Expand All @@ -158,23 +158,23 @@ export async function bundleSdk (options = {}) {
})

const elapsed = ((Date.now() - startTime) / 1000).toFixed(2)
logger.log(`\n🎉 Done in ${elapsed}s!\n`)
logger.log('Generated files:')
logger.log(
logger.info(`\n🎉 Done in ${elapsed}s!\n`)
logger.info('Generated files:')
logger.info(
' - qvac/worker.entry.mjs (standalone worker with RPC + lifecycle)'
)
logger.log(
logger.info(
' - qvac/worker.pear.entry.mjs (Pear worker entrypoint: plugins + app worker)'
)
logger.log(
logger.info(
' - qvac/worker.bundle.js (mobile bundle for Expo/React Native BareKit)'
)
logger.log(' - qvac/addons.manifest.json\n')
logger.log(
logger.info(' - qvac/addons.manifest.json\n')
logger.info(
'Pear apps: Spawn qvac/worker.pear.entry.mjs as your worker entrypoint'
)
logger.log('Mobile: Expo plugin auto-configures worker.bundle.js')
logger.log(
logger.info('Mobile: Expo plugin auto-configures worker.bundle.js')
logger.info(
'Standalone: Import qvac/worker.entry.mjs for full worker with RPC\n'
)

Expand Down
10 changes: 5 additions & 5 deletions packages/qvac-cli/src/bundle-sdk/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function extractBarePackHeader (packed) {
export async function generateAddonsManifest (options) {
const { bundlePath, outputDir, projectRoot, logger } = options

logger.log('\n📦 Generating addons manifest...')
logger.info('\n📦 Generating addons manifest...')

const bundleJsText = await fsp.readFile(bundlePath, 'utf8')
const packed = extractPackedString(bundleJsText)
Expand Down Expand Up @@ -183,7 +183,7 @@ export async function generateAddonsManifest (options) {
}
}
} catch (err) {
logger.verbose(` ⚠️ Could not read ${pkgName}/package.json: ${err.message}`)
logger.warn(` Could not read ${pkgName}/package.json: ${err.message}`)
}
}

Expand All @@ -204,11 +204,11 @@ export async function generateAddonsManifest (options) {
const manifestPath = path.join(outputDir, 'addons.manifest.json')
await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n')

logger.log(` Found ${packageNames.size} packages in bundle graph`)
logger.log(
logger.info(` Found ${packageNames.size} packages in bundle graph`)
logger.info(
` Identified ${addons.length} native addons: ${addons.join(', ') || '(none)'}`
)
logger.log(` Wrote ${manifestPath}`)
logger.info(` Wrote ${manifestPath}`)

return { manifestPath, addons }
}
6 changes: 3 additions & 3 deletions packages/qvac-cli/src/bundle-sdk/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function resolvePluginSpecifiers (config, sdkName, logger) {
const allBuiltins = BUILTIN_SUFFIXES.map((suffix) =>
buildBuiltinSpecifier(sdkName, suffix)
)
logger.log('⚠️ No plugins specified — bundling ALL built-in plugins.')
logger.log(" For smaller bundles, add a 'plugins' array to qvac.config.*\n")
logger.warn('No plugins specified — bundling ALL built-in plugins.')
logger.info(" For smaller bundles, add a 'plugins' array to qvac.config.*\n")
plugins = allBuiltins
}

Expand Down Expand Up @@ -57,7 +57,7 @@ export function resolvePluginSpecifiers (config, sdkName, logger) {
}

if (customPlugins.length > 0) {
logger.log(`📦 Custom plugins: ${customPlugins.join(', ')}`)
logger.info(`📦 Custom plugins: ${customPlugins.join(', ')}`)
}

return [...resolved, ...customPlugins]
Expand Down
43 changes: 32 additions & 11 deletions packages/qvac-cli/src/logger.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
/**
* Creates a logger with the specified log level.
* @param {"quiet" | "normal" | "verbose"} logLevel
*/
export function createLogger (logLevel) {
const LOG_LEVELS = {
silent: 0,
error: 1,
warn: 2,
info: 3,
debug: 4
}

export function createLogger (level = 'info') {
if (!(level in LOG_LEVELS)) {
const validLevels = Object.keys(LOG_LEVELS).join(', ')
console.warn(`Invalid log level "${level}", falling back to "info". Valid levels: ${validLevels}`)
}

const currentLevel = LOG_LEVELS[level] ?? LOG_LEVELS.info
Comment thread
opaninakuffo marked this conversation as resolved.

return {
log (message, level = 'normal') {
if (logLevel === 'quiet' && level !== 'quiet') return
if (level === 'verbose' && logLevel !== 'verbose') return
console.log(message)
error (message) {
if (currentLevel >= LOG_LEVELS.error) {
console.error(message)
}
},
verbose (message) {
if (logLevel === 'verbose') {
warn (message) {
if (currentLevel >= LOG_LEVELS.warn) {
console.warn(message)
}
},
info (message) {
if (currentLevel >= LOG_LEVELS.info) {
console.log(message)
}
},
debug (message) {
if (currentLevel >= LOG_LEVELS.debug) {
console.debug(message)
}
}
}
}
Loading