|
23 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
24 | 24 | * SOFTWARE. |
25 | 25 | */ |
26 | | -const { execSync, fork } = require('child_process') |
| 26 | +const { execSync } = require('child_process') |
27 | 27 | const path = require('path') |
28 | 28 |
|
29 | 29 | const opts = { stdio: 'inherit' } |
30 | | -function buildProject() { |
31 | | - console.info('Fetching design tokens...') |
32 | | - try { |
33 | | - execSync( |
34 | | - 'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens', |
35 | | - opts |
36 | | - ) |
37 | | - } catch (error) { |
38 | | - console.error( |
39 | | - "'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens' failed", |
40 | | - error |
41 | | - ) |
42 | | - process.exit(1) |
43 | | - } |
44 | 30 |
|
45 | | - console.info('Building themes...') |
46 | | - try { |
47 | | - execSync('pnpm run build:themes', opts) |
48 | | - } catch (error) { |
49 | | - console.error("'pnpm run build:themes' failed", error) |
50 | | - process.exit(1) |
51 | | - } |
| 31 | +function format(ms) { |
| 32 | + return `${(ms / 1000).toFixed(1)}s` |
| 33 | +} |
52 | 34 |
|
53 | | - execSync('pnpm --filter @instructure/ui-icons prepare-build', opts) |
54 | | - |
55 | | - // Executes a ui-codemods script to generate a versioned components list |
56 | | - // from the ui metapackage's latest re-export file. This is required for |
57 | | - // the updateInstUIImportVersions codemod's diagnose mode. |
58 | | - execSync( |
59 | | - 'pnpm --filter @instructure/ui-codemods generate:versioned-exports', |
60 | | - opts |
61 | | - ) |
62 | | - |
63 | | - console.info('Building packages with Babel...') |
64 | | - try { |
65 | | - execSync('pnpm run build', opts) |
66 | | - } catch (error) { |
67 | | - console.error("'pnpm run build' failed", error) |
68 | | - process.exit(1) |
| 35 | +function mark(name) { |
| 36 | + console.log(`\n================================================`) |
| 37 | + console.log(`${name}...`) |
| 38 | + if (steps.length) { |
| 39 | + steps[steps.length - 1].duration = |
| 40 | + Date.now() - steps[steps.length - 1].start |
69 | 41 | } |
| 42 | + steps.push({ name, start: Date.now(), duration: 0 }) |
| 43 | +} |
70 | 44 |
|
71 | | - console.info('Generating tokens...') |
72 | | - try { |
73 | | - execSync('pnpm run build:tokens', opts) |
74 | | - } catch (error) { |
75 | | - console.error("'pnpm run build:tokens' failed", error) |
76 | | - process.exit(1) |
77 | | - } |
| 45 | +const steps = [] |
| 46 | +const bootstrapStart = Date.now() |
78 | 47 |
|
79 | | - console.info('Building TypeScript declarations...') |
80 | | - try { |
81 | | - execSync('pnpm run build:types', opts) |
82 | | - } catch (error) { |
83 | | - console.error("'pnpm run build:types' failed", error) |
84 | | - process.exit(1) |
85 | | - } |
86 | | -} |
| 48 | +mark('Deleting build artifacts') |
| 49 | +execSync(path.resolve('scripts/clean.js'), opts) |
87 | 50 |
|
88 | | -function bootstrap() { |
89 | | - execSync(path.resolve('scripts/clean.js'), opts) |
90 | | - buildProject() |
91 | | -} |
| 51 | +mark('Fetching design tokens') |
| 52 | +execSync( |
| 53 | + 'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens', |
| 54 | + opts |
| 55 | +) |
| 56 | + |
| 57 | +mark('Building themes') |
| 58 | +execSync('pnpm run build:themes', opts) |
92 | 59 |
|
93 | | -bootstrap() |
| 60 | +mark('Preparing icons') |
| 61 | +execSync('pnpm --filter @instructure/ui-icons prepare-build', opts) |
| 62 | + |
| 63 | +mark('Generating package list for codemods') |
| 64 | +execSync( |
| 65 | + 'pnpm --filter @instructure/ui-codemods generate:versioned-exports', |
| 66 | + opts |
| 67 | +) |
| 68 | + |
| 69 | +mark('Building packages with Babel') |
| 70 | +execSync('pnpm run build', opts) |
| 71 | + |
| 72 | +mark('Generating design tokens') |
| 73 | +execSync('pnpm run build:tokens', opts) |
| 74 | + |
| 75 | +mark('Building TypeScript declarations') |
| 76 | +execSync('pnpm run build:types', opts) |
| 77 | + |
| 78 | +// Log build time summary. Assumes that the build is not parallel |
| 79 | +steps[steps.length - 1].duration = Date.now() - steps[steps.length - 1].start |
| 80 | + |
| 81 | +const total = Date.now() - bootstrapStart |
| 82 | +const nameW = Math.max(...steps.map((s) => s.name.length)) |
| 83 | +const durW = Math.max( |
| 84 | + ...steps.map((s) => format(s.duration).length), |
| 85 | + format(total).length |
| 86 | +) |
| 87 | +const tableWidth = nameW + durW + 7 |
| 88 | + |
| 89 | +console.log('\n' + '='.repeat(tableWidth)) |
| 90 | +console.log(' Bootstrap Summary') |
| 91 | +console.log('='.repeat(tableWidth)) |
| 92 | +for (const s of steps) { |
| 93 | + console.log(` ${s.name.padEnd(nameW)} ${format(s.duration).padStart(durW)}`) |
| 94 | +} |
| 95 | +console.log('-'.repeat(tableWidth)) |
| 96 | +console.log(` ${'Total'.padEnd(nameW)} ${format(total).padStart(durW)}`) |
| 97 | +console.log('='.repeat(tableWidth)) |
0 commit comments