forked from Seneca-CDOT/telescope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up back end to recollect information from pnpm
- Loading branch information
Showing
8 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Environment variables needed if you want to run `npm run dev` | ||
# and run the server locally, outside of Docker. For all the various | ||
# ways we run this using Docker, the env is defined by one of the | ||
# config/env.* files in the root. This requires that the other | ||
# services are running, particularly the login and users services. | ||
DEP_DISCOVERY_PORT=10500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "dependency-discovery", | ||
"private": true, | ||
"version": "0.1.0", | ||
"description": "A dependency graph compilation service for Telescope", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node src/server.js", | ||
"dev": "env-cmd -f env.local nodemon src/server.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Seneca-CDOT/telescope.git" | ||
}, | ||
"author": "", | ||
"license": "BSD-2-Clause", | ||
"bugs": { | ||
"url": "https://github.com/Seneca-CDOT/telescope/issues" | ||
}, | ||
"homepage": "https://github.com/Seneca-CDOT/telescope#readme", | ||
"dependencies": { | ||
"@senecacdot/satellite": "^1.x" | ||
}, | ||
"devDependencies": { | ||
"env-cmd": "10.1.0", | ||
"nodemon": "2.0.15" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { readFile } = require('fs/promises'); | ||
const { join } = require('path'); | ||
const { cwd } = require('process'); | ||
|
||
async function getDependencies() { | ||
const dependencies = await readFile(join(cwd(), 'deps.txt'), 'utf8'); | ||
|
||
// The order of the alternatives is important! | ||
// The regex engine will favor the first pattern on an alternation | ||
// even if the other alternatives are subpatterns | ||
return dependencies.split(/\r\n|\n|\r/).filter((line) => line !== ''); | ||
} | ||
|
||
module.exports = getDependencies(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { Satellite } = require('@senecacdot/satellite'); | ||
|
||
const dependenciesRoute = require('./router'); | ||
|
||
const service = new Satellite(); | ||
|
||
service.router.use('/', dependenciesRoute); | ||
|
||
module.exports = service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { Router } = require('@senecacdot/satellite'); | ||
const dependencyList = require('./dependency-list'); | ||
|
||
const router = Router(); | ||
|
||
router.get('/projects', async (req, res, next) => { | ||
try { | ||
res.set('Cache-Control', 'max-age=3600'); | ||
res.status(200).json(await dependencyList); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const service = require('.'); | ||
|
||
const port = parseInt(process.env.DEP_DISCOVERY_PORT || 10500, 10); | ||
|
||
service.start(port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# First regex can be read as the following: | ||
# .*\.pnpm\/(@?[^@]+).* | ||
# We use the literal .pnpm to find the start of the package name | ||
# After that, we use the pattern "@?[^@]+" to search for the name | ||
# that appears first, instead of ".+". | ||
# | ||
# Sometimes we could have foo@1.0.0_bar@1.0.0, in which case we want | ||
# to capture foo. With ".+", we could capture foo@1.0.0_bar. | ||
# Instead, we search for the string of characters that do not include | ||
# "@", which translates to "[^@]+". However, some package names include | ||
# @ at the start, so we cover that case, as well. | ||
|
||
set -e | ||
|
||
option=$1 | ||
filename=$2 | ||
|
||
if [[ $# -eq 2 && $option = "-o" && $filename ]]; then | ||
echo "Start collecting dependencies" | ||
pnpm list -w -r --parseable --depth=0 | sed -n -r -e "s|.*\.pnpm/(@?[^@]+).*|\1|p" -e "s/+/\//" | sort -u > $filename | ||
echo "Dependencies collected" | ||
else | ||
echo "command usage: $BASH_SOURCE -o filename" | ||
fi |