-
-
Notifications
You must be signed in to change notification settings - Fork 737
Support for monorepos based on npm/Yarn Workspaces #1567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cebd113
21cacd2
ef1d9f7
23db9a3
fcc74b1
50bc055
998e610
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"dependencies": { | ||
"colors": "^1.4.0", | ||
"fs-extra": "^9.1.0", | ||
"glob": "^7.1.6", | ||
"handlebars": "^4.7.7", | ||
"lodash": "^4.17.21", | ||
"lunr": "^2.3.9", | ||
|
@@ -37,6 +38,7 @@ | |
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/glob": "^7.1.3", | ||
"@types/lodash": "^4.14.168", | ||
"@types/lunr": "^2.3.3", | ||
"@types/marked": "^2.0.2", | ||
|
@@ -65,7 +67,7 @@ | |
], | ||
"scripts": { | ||
"pretest": "node scripts/copy_test_files.js", | ||
"test": "nyc --reporter=html --reporter=text-summary mocha --timeout=10000 'dist/test/**/*.test.js'", | ||
"test": "nyc --reporter=html --reporter=text-summary mocha --timeout=10000 'dist/test/**/*.test.js' --exclude 'dist/test/packages/**'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the |
||
"prerebuild_specs": "npm run pretest", | ||
"rebuild_specs": "node scripts/rebuild_specs.js", | ||
"build": "tsc --project .", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,128 @@ | |
|
||
const fs = require("fs-extra"); | ||
const { join } = require("path"); | ||
const { spawn } = require("child_process"); | ||
|
||
function promiseFromChildProcess(childProcess) { | ||
return new Promise(function (resolve, reject) { | ||
childProcess.on("error", function (error) { | ||
reject( | ||
new Error( | ||
childProcess.spawnargs.join(" ") + " : " + error.message | ||
) | ||
); | ||
}); | ||
childProcess.on("exit", function (code) { | ||
if (code !== 0) { | ||
reject( | ||
new Error( | ||
childProcess.spawnargs.join(" ") + | ||
" : exited with code " + | ||
code | ||
) | ||
); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const isWindows = process.platform === "win32"; | ||
const npmCommand = isWindows ? "npm.cmd" : "npm"; | ||
|
||
function ensureNpmVersion() { | ||
return Promise.resolve().then(() => { | ||
const npmProc = spawn(npmCommand, ["--version"], { | ||
stdio: ["ignore", "pipe", "inherit"], | ||
}); | ||
let npmVersion = ""; | ||
npmProc.stdout.on("data", (data) => { | ||
npmVersion += data; | ||
}); | ||
return promiseFromChildProcess(npmProc).then(() => { | ||
npmVersion = npmVersion.trim(); | ||
let firstDot = npmVersion.indexOf("."); | ||
const npmMajorVer = parseInt( | ||
npmVersion.slice(0, npmVersion.indexOf(".")) | ||
); | ||
if (npmMajorVer < 7) { | ||
throw new Error( | ||
"npm version must be at least 7, version installed is " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Installing the monorepo's deps (and gluing the inter-package deps together) requires either lerna, or yarn, or npm>7. I opted for the npm approach as I figured it's the most "vanilla" despite having been around for the least amount of time. This could run in to issues under some of your CI configs however so let's see if anything breaks and decide what to do. |
||
npmVersion | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function prepareMonorepoFolder() { | ||
return Promise.resolve() | ||
.then(() => { | ||
return promiseFromChildProcess( | ||
spawn( | ||
"git", | ||
["clone", "https://github.com/efokschaner/ts-monorepo.git"], | ||
{ | ||
cwd: join(__dirname, "../dist/test/packages"), | ||
stdio: "inherit", | ||
} | ||
) | ||
); | ||
}) | ||
.then(() => { | ||
return promiseFromChildProcess( | ||
spawn( | ||
"git", | ||
["checkout", "73bdd4c6458ad4cc3de35498e65d55a1a44a8499"], | ||
{ | ||
cwd: join( | ||
__dirname, | ||
"../dist/test/packages/ts-monorepo" | ||
), | ||
stdio: "inherit", | ||
} | ||
) | ||
); | ||
}) | ||
.then(() => { | ||
return promiseFromChildProcess( | ||
spawn(npmCommand, ["install"], { | ||
cwd: join(__dirname, "../dist/test/packages/ts-monorepo"), | ||
stdio: "inherit", | ||
}) | ||
); | ||
}) | ||
.then(() => { | ||
return promiseFromChildProcess( | ||
spawn(npmCommand, ["run", "build"], { | ||
cwd: join(__dirname, "../dist/test/packages/ts-monorepo"), | ||
stdio: "inherit", | ||
}) | ||
); | ||
}); | ||
} | ||
|
||
function prepareSinglePackageExample() { | ||
return Promise.resolve().then(() => { | ||
return promiseFromChildProcess( | ||
spawn(npmCommand, ["run", "build"], { | ||
cwd: join( | ||
__dirname, | ||
"../dist/test/packages/typedoc-single-package-example" | ||
), | ||
stdio: "inherit", | ||
}) | ||
); | ||
}); | ||
} | ||
|
||
const copy = [ | ||
"test/converter", | ||
"test/converter2", | ||
"test/renderer", | ||
"test/module", | ||
"test/packages", | ||
"test/utils/options/readers/data", | ||
]; | ||
|
||
|
@@ -20,7 +136,12 @@ const copies = copy.map((dir) => { | |
.then(() => fs.copy(source, target)); | ||
}); | ||
|
||
Promise.all(copies).catch((reason) => { | ||
console.error(reason); | ||
process.exit(1); | ||
}); | ||
Promise.all(copies) | ||
.then(ensureNpmVersion) | ||
.then(() => | ||
Promise.all([prepareMonorepoFolder(), prepareSinglePackageExample()]) | ||
) | ||
.catch((reason) => { | ||
console.error(reason); | ||
process.exit(1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running typedoc on the examples folder locally, I needed to gitignore this folder.