Skip to content

Commit

Permalink
fix(dev-env/basic): building and running development (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatobenks authored Aug 2, 2021
1 parent d2ab7c3 commit 7baaaf2
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 294 deletions.
2 changes: 1 addition & 1 deletion core/docz-rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-progress": "^1.1.1",
"rollup-plugin-progress": "^1.1.2",
"rollup-plugin-typescript2": "^0.22.0"
},
"devDependencies": {
Expand Down
22 changes: 13 additions & 9 deletions dev-env/basic/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const watchPackage = async (name, outputDir) => {
const destinationPath = getDestinationPath(name, outputDir)
const sourceRootPath = path.join(rootPath, `core/${name}/`)
const dev = runCommand(`yarn run dev`, { cwd: sourceRootPath })

try {
await runCommand(`yarn run build`, { cwd: sourceRootPath })
} catch (err) {
Expand All @@ -65,8 +66,7 @@ const watchPackage = async (name, outputDir) => {
cpx.watch(`${sourcePath}/lib/**/*`, getDestinationPath(name, 'lib'))
)
} else {
const sync = cpx.watch(`${sourcePath}/**/*`, destinationPath)
fileWatchers.push(sync)
fileWatchers.push(cpx.watch(`${sourcePath}/**/*`, destinationPath))
}

const unsubscribers = fileWatchers.map(fileWatcher => {
Expand All @@ -81,12 +81,15 @@ const watchPackage = async (name, outputDir) => {
}
return stop
})

const stop = () => {
dev.cancel()
unsubscribers.forEach(unsub => {
unsub()
})
}

console.log('watching package: ', name)
return stop
}

Expand All @@ -97,20 +100,21 @@ const main = async () => {
for (let stopWatching of watchStoppers) {
stopWatching()
}

console.log(`\nTerminated ${watchStoppers.length} running processes\n`)
process.exit(0)
})

const build = runCommand(`yarn packages:build`, { cwd: rootPath })

watchStoppers.push(() => build.cancel())

await build
for (let package of packages) {
const stopWatchingPackage = await watchPackage(
package.name,
package.outputDir
)
console.log('watching package ', package.name)
watchStoppers.push(stopWatchingPackage)

for (const package of packages) {
watchStoppers.push(await watchPackage(package.name, package.outputDir))
}

const dev = runCommand(`yarn docz dev`, { cwd: __dirname })
watchStoppers.push(() => dev.cancel())
}
Expand Down
2 changes: 1 addition & 1 deletion dev-env/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"cpx": "^1.5.0",
"docz": "next",
"docz": "../../core/docz",
"execa": "^2.0.4",
"prop-types": "^15.7.2",
"react": "^16.8.6",
Expand Down
Loading

0 comments on commit 7baaaf2

Please sign in to comment.