Skip to content

Commit

Permalink
feat: print products as their finished
Browse files Browse the repository at this point in the history
  • Loading branch information
just-paja committed Mar 23, 2023
1 parent 17b3442 commit 27e25bd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
21 changes: 21 additions & 0 deletions packages/isolate/IsolatedProject.mjs
Expand Up @@ -9,6 +9,7 @@ import { extractPackageName, padScope } from './names.mjs'
export class IsolatedProject extends Project {
constructor(root, { reporter } = {}) {
super(root)
this.handlers = {}
this.isolated = {}
this.mappedPackages = null
this.onProgress = null
Expand Down Expand Up @@ -58,13 +59,30 @@ export class IsolatedProject extends Project {
addProduct(productPath) {
if (!this.products.includes(productPath)) {
this.products.push(productPath)
this.announce('productAdded', { productPath })
}
}

addTemp(tempPath) {
this.temp.push(tempPath)
}

announce(event, props) {
const handlers = this.handlers[event]
if (handlers) {
for (const handler of handlers) {
handler(props)
}
}
}

on(event, handler) {
if (!this.handlers[event]) {
this.handlers[event] = []
}
this.handlers[event].push(handler)
}

async createDistDir() {
await mkdir(this.distPath, { recursive: true })
}
Expand All @@ -77,6 +95,9 @@ export class IsolatedProject extends Project {
fn: async () => {
await this.isolatePackage(pkg, options)
},
after: () => {
this.announce('packageIsolated', pkg)
},
}))
)
await this.cleanup()
Expand Down
3 changes: 3 additions & 0 deletions packages/isolate/JobRunner.mjs
Expand Up @@ -61,6 +61,9 @@ export class JobRunner {
this.startJob(job)
await job.fn.call()
this.finishJob(job)
if (job.after) {
await job.after.call()
}
}
}
}
8 changes: 7 additions & 1 deletion packages/isolate/cli.mjs
@@ -1,6 +1,12 @@
import childProcess from 'child_process'

export const log = (message, { padding = 0, newline = true } = {}) => {
export const log = (
message,
{ clear = false, padding = 0, newline = true } = {}
) => {
if (clear) {
process.stdout.write('\r')
}
if (padding) {
process.stdout.write(Array(padding).fill(' ').join(''))
}
Expand Down
18 changes: 10 additions & 8 deletions packages/isolate/isolate.mjs
Expand Up @@ -20,15 +20,17 @@ async function isolatePackages(argv) {
const project = new IsolatedProject(root, { reporter: jobRunner })
const available = await project.filterPackages(argv)
const toIsolate = await resolvePackages(available, argv.packages)
let products = []
project.on('productAdded', ({ productPath }) => {
products.push(productPath)
})
project.on('packageIsolated', () => {
products.map(productPath =>
log(relative(process.cwd(), productPath), { clear: true, padding: 2 })
)
products = []
})
await project.isolatePackages(toIsolate)

if (project.products.length > 0) {
log('Created:')
project.products
.map(archive => relative(process.cwd(), archive))
.sort((a, b) => a.localeCompare(b))
.forEach(archive => log(` ${archive}`))
}
}

function findMatchingPackage(available, pkg) {
Expand Down

0 comments on commit 27e25bd

Please sign in to comment.