|
| 1 | +#! /usr/bin/env node |
| 2 | +/* eslint-disable no-console */ |
| 3 | + |
| 4 | +/* |
| 5 | + * The MIT License (MIT) |
| 6 | + * |
| 7 | + * Copyright (c) 2015 - present Instructure, Inc. |
| 8 | + * |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in all |
| 17 | + * copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | + * SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +/** |
| 29 | + * bootstrap-lite.js |
| 30 | + * |
| 31 | + * A lightweight validation script optimized for AI tools to quickly validate |
| 32 | + * code changes without doing full builds. This is much faster than full bootstrap. |
| 33 | + * |
| 34 | + * PREREQUISITES: |
| 35 | + * - You must run full `npm run bootstrap` at least once before using this script |
| 36 | + * - This script is for validating changes in an already-bootstrapped repository |
| 37 | + * - It won't work on a clean repository as it depends on existing build artifacts |
| 38 | + * |
| 39 | + * What it does: |
| 40 | + * 1. Check TypeScript references consistency |
| 41 | + * 2. Build TypeScript types (.d.ts files) - also validates types during build |
| 42 | + * - Uses TypeScript's incremental build cache for speed (rebuilds only changed files) |
| 43 | + * 3. Optional: Run linting on changed files |
| 44 | + * |
| 45 | + * What it skips (vs full bootstrap): |
| 46 | + * - Clean step |
| 47 | + * - Babel builds (transpilation to lib/ and es/) |
| 48 | + * - Icon generation |
| 49 | + * - Token generation |
| 50 | + * |
| 51 | + * Options: |
| 52 | + * --force Bypass TypeScript build cache and rebuild all types from scratch |
| 53 | + * --lint Run linting on changed files |
| 54 | + */ |
| 55 | + |
| 56 | +const { execSync } = require('child_process') |
| 57 | +const chalk = require('chalk') |
| 58 | + |
| 59 | +const opts = { stdio: 'inherit' } |
| 60 | + |
| 61 | +function log(message, type = 'info') { |
| 62 | + const prefix = { |
| 63 | + info: chalk.blue('ℹ'), |
| 64 | + success: chalk.green('✓'), |
| 65 | + warning: chalk.yellow('⚠'), |
| 66 | + error: chalk.red('✖') |
| 67 | + }[type] |
| 68 | + console.log(`${prefix} ${message}`) |
| 69 | +} |
| 70 | + |
| 71 | +function runStep(name, command) { |
| 72 | + log(`${name}...`, 'info') |
| 73 | + const startTime = Date.now() |
| 74 | + try { |
| 75 | + execSync(command, opts) |
| 76 | + const elapsed = ((Date.now() - startTime) / 1000).toFixed(2) |
| 77 | + log(`${name} completed in ${elapsed}s`, 'success') |
| 78 | + return true |
| 79 | + } catch { |
| 80 | + log(`${name} failed`, 'error') |
| 81 | + return false |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +function bootstrapLite() { |
| 86 | + const startTime = Date.now() |
| 87 | + log('Starting bootstrap-lite (fast validation for AI tools)...', 'info') |
| 88 | + console.log('') |
| 89 | + |
| 90 | + // Step 1: Check TypeScript references consistency |
| 91 | + if ( |
| 92 | + !runStep( |
| 93 | + 'Checking TypeScript references', |
| 94 | + 'node scripts/checkTSReferences.js' |
| 95 | + ) |
| 96 | + ) { |
| 97 | + process.exit(1) |
| 98 | + } |
| 99 | + console.log('') |
| 100 | + |
| 101 | + // Step 2: Build TypeScript types |
| 102 | + // This generates .d.ts files AND validates types (build fails if type errors exist) |
| 103 | + log('Building TypeScript types (this also validates types)...', 'info') |
| 104 | + const args = process.argv.slice(2) |
| 105 | + const forceRebuild = args.includes('--force') |
| 106 | + const buildCommand = forceRebuild |
| 107 | + ? 'tsc -b tsconfig.references.json --force' |
| 108 | + : 'npm run build:types' |
| 109 | + |
| 110 | + if (forceRebuild) { |
| 111 | + log('Force rebuild enabled - bypassing TypeScript build cache', 'warning') |
| 112 | + } |
| 113 | + |
| 114 | + if (!runStep('Building TypeScript types', buildCommand)) { |
| 115 | + process.exit(1) |
| 116 | + } |
| 117 | + console.log('') |
| 118 | + |
| 119 | + // Step 3: Optional - Lint changed files only |
| 120 | + if (args.includes('--lint')) { |
| 121 | + if (!runStep('Linting changed files', 'npm run lint:changes')) { |
| 122 | + log('Linting failed but continuing...', 'warning') |
| 123 | + } |
| 124 | + console.log('') |
| 125 | + } |
| 126 | + |
| 127 | + const totalTime = ((Date.now() - startTime) / 1000).toFixed(2) |
| 128 | + console.log('') |
| 129 | + log(`✨ bootstrap-lite completed successfully in ${totalTime}s!`, 'success') |
| 130 | + console.log('') |
| 131 | + log( |
| 132 | + 'Note: This builds types but skips Babel transpilation. For full builds, run: npm run bootstrap', |
| 133 | + 'info' |
| 134 | + ) |
| 135 | +} |
| 136 | + |
| 137 | +bootstrapLite() |
0 commit comments