Skip to content

Commit 08f65f2

Browse files
authored
chore(devcontainer): automatically add keys (#123)
1 parent 77cab2e commit 08f65f2

File tree

6 files changed

+50
-37
lines changed

6 files changed

+50
-37
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/typescript-node/.devcontainer/base.Dockerfile
22

33
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
4-
ARG VARIANT="16-bullseye"
4+
ARG VARIANT="16"
55
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
66

77
# [Optional] Uncomment this section to install additional OS packages.
88
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
99
&& apt-get -y install --no-install-recommends fontconfig redis-server
1010

1111
# [Optional] Uncomment if you want to install an additional version of node using nvm
12-
# ARG EXTRA_NODE_VERSION=10
12+
# ARG EXTRA_NODE_VERSION=16
1313
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
1414

1515
# [Optional] Uncomment if you want to install more global node packages

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// Use 'postCreateCommand' to run commands after the container is created.
5252
"postCreateCommand": "/workspaces/statsify/.devcontainer/install.sh",
5353

54-
"postStartCommand": "sudo /etc/init.d/redis-server start",
54+
"postStartCommand": "sudo /etc/init.d/redis-server start && yarn scripts create-key --noninteractive",
5555

5656
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
5757
"remoteUser": "node",

.devcontainer/install.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
echo 'export STATSIFY="/worspaces/statsify"' >> ~/.zshrc
2-
echo 'export PATH="$STATSIFY/scripts:$PATH"' >> ~/.zshrc
31
echo 'alias c=clear' >> ~/.zshrc
42
cargo install git-cliff
53
yarn install

.eslintrc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"root": true,
33
"parser": "@typescript-eslint/parser",
44
"parserOptions": {
5-
"ecmaVersion": 2020,
6-
"sourceType": "module",
7-
"warnOnUnsupportedTypeScriptVersion": false,
8-
"project": "./tsconfig.eslint.json"
5+
"ecmaVersion": "latest"
6+
},
7+
"env": {
8+
"commonjs": true,
9+
"es2022": true,
10+
"node": true
911
},
10-
"ignorePatterns": ["apps/scripts/**"],
1112
"plugins": ["@typescript-eslint"],
1213
"overrides": [
1314
{
@@ -70,4 +71,4 @@
7071
}
7172
]
7273
}
73-
}
74+
}

apps/scripts/src/create-key.mjs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,46 @@ async function createKey({ name, key, role, limit }) {
2020

2121
const roles = ['user', 'admin'];
2222

23+
async function getUserPreferences() {
24+
if (process.argv.includes('--noninteractive')) {
25+
return {
26+
name: 'TESTKEY',
27+
key: 'TESTKEY',
28+
role: 'admin',
29+
limit: 120,
30+
};
31+
} else {
32+
return await inquirer.prompt([
33+
{
34+
type: 'input',
35+
name: 'name',
36+
message: 'What is your name?',
37+
},
38+
{
39+
type: 'input',
40+
name: 'key',
41+
message: 'What is the api key?',
42+
default: () => randomUUID(),
43+
},
44+
{
45+
type: 'list',
46+
name: 'role',
47+
message: 'What is the role of the api key?',
48+
choices: roles,
49+
default: 'admin',
50+
},
51+
{
52+
type: 'number',
53+
name: 'limit',
54+
message: 'What is the limit for requests per minute?',
55+
default: 120,
56+
},
57+
]);
58+
}
59+
}
60+
2361
async function bootstrap() {
24-
const { name, key, role, limit } = await inquirer.prompt([
25-
{
26-
type: 'input',
27-
name: 'name',
28-
message: 'What is your name?',
29-
},
30-
{
31-
type: 'input',
32-
name: 'key',
33-
message: 'What is the api key?',
34-
default: () => randomUUID(),
35-
},
36-
{
37-
type: 'list',
38-
name: 'role',
39-
message: 'What is the role of the api key?',
40-
choices: roles,
41-
default: 'admin',
42-
},
43-
{
44-
type: 'number',
45-
name: 'limit',
46-
message: 'What is the limit for requests per minute?',
47-
default: 120,
48-
},
49-
]);
62+
const { name, key, role, limit } = await getUserPreferences();
5063

5164
await createKey({ name, key, role, limit });
5265

tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"esModuleInterop": true,
55
"experimentalDecorators": true,
66
"importsNotUsedAsValues": "error",
7+
"strictPropertyInitialization": false,
78
"moduleResolution": "Node",
89
"module": "CommonJS",
910
"skipDefaultLibCheck": true,

0 commit comments

Comments
 (0)