Skip to content

Commit

Permalink
Set up back end to recollect information from pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryHue committed Feb 4, 2022
1 parent 14b204d commit da002a9
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/api/dependency-discovery/env.local
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
28 changes: 28 additions & 0 deletions src/api/dependency-discovery/package.json
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"
}
}
14 changes: 14 additions & 0 deletions src/api/dependency-discovery/src/dependency-list.js
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();
9 changes: 9 additions & 0 deletions src/api/dependency-discovery/src/index.js
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;
15 changes: 15 additions & 0 deletions src/api/dependency-discovery/src/router.js
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;
5 changes: 5 additions & 0 deletions src/api/dependency-discovery/src/server.js
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);
26 changes: 26 additions & 0 deletions tools/pnpm-deps-gen.sh
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

0 comments on commit da002a9

Please sign in to comment.