Skip to content
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

feat: create a shared /lib folder for the extensions #41

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ RUN npm run build

# Build hooks/adopted-probe
FROM node:18-alpine AS builder-09
WORKDIR /builder/src/extensions/lib
ADD ./src/extensions/lib/package.json ./src/extensions/lib/package-lock.json ./
RUN npm ci
COPY ./src/extensions/lib .
WORKDIR /builder/src/extensions/hooks/adopted-probe
ADD ./src/extensions/hooks/adopted-probe/package.json ./src/extensions/hooks/adopted-probe/package-lock.json ./
RUN npm ci
Expand Down Expand Up @@ -134,16 +138,20 @@ RUN npm ci
COPY ./src/extensions/hooks/gp-tokens .
RUN npm run build

# Build hooks/gp-tokens
# Build hooks/directus-users
FROM node:18-alpine AS builder-18
WORKDIR /builder/src/extensions/hooks/directus-users
ADD ./src/extensions/hooks/directus-users/package.json ./src/extensions/hooks/directus-users/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/directus-users .
RUN npm run build

# Build hooks/gp-tokens
# Build hooks/location-verrides
FROM node:18-alpine AS builder-19
WORKDIR /builder/src/extensions/lib
ADD ./src/extensions/lib/package.json ./src/extensions/lib/package-lock.json ./
RUN npm ci
COPY ./src/extensions/lib .
WORKDIR /builder/src/extensions/hooks/location-overrides
ADD ./src/extensions/hooks/location-overrides/package.json ./src/extensions/hooks/location-overrides/package-lock.json ./
RUN npm ci
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Add tests to extension:
# From the extension folder call:
original_dir=$PWD
npm i --save-dev chai @types/chai mocha @types/mocha sinon @types/sinon ts-node
jq --tab '.compilerOptions.module = "ESNext"' tsconfig.json > temp.json && mv temp.json tsconfig.json
jq 'del(.compilerOptions.rootDir) | .compilerOptions.module = "ESNext" | .include = ["./src/**/*.ts", "../../lib/*.ts"]' tsconfig.json > temp.json && mv temp.json tsconfig.json
jq --tab '.scripts.test = "TS_NODE_TRANSPILE_ONLY=true mocha"' package.json > temp.json && mv temp.json package.json
mkdir test
while [[ $PWD != */extensions ]]; do cd ..; done
Expand Down
3 changes: 3 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ directories=$(find ./src -type d -name "node_modules" -prune -o -type f -name "p
echo "Extensions directories:"
echo "$directories"

# /lib directory should be installed first
directories="./src/extensions/lib $directories"

for dir in $directories; do
(
echo "Directory: $dir"
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/hooks/adopted-probe/src/validate-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from 'axios';
import { createError } from '@directus/errors';
import { Fields } from './index.js';
import { City, geonamesCache, getKey } from './geonames-cache.js';
import { normalizeCityName } from './normalize-city.js';
import { normalizeCityName } from '../../../lib/normalize-city.js';
import { EventContext } from '@directus/types';
import { getProbes, getUser } from './repositories/directus.js';

Expand Down
6 changes: 3 additions & 3 deletions src/extensions/hooks/adopted-probe/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"rootDir": "./src"
"isolatedModules": true
},
"include": [
"./src/**/*.ts"
"./src/**/*.ts",
"../../lib/*.ts"
]
}
15 changes: 0 additions & 15 deletions src/extensions/hooks/location-overrides/src/normalize-city.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createError } from '@directus/errors';
import axios from 'axios';
import ipaddr from 'ipaddr.js';
import type { Fields } from './index.js';
import { normalizeCityName } from './normalize-city.js';
import { normalizeCityName } from '../../../lib/normalize-city.js';

type City = {
lng: string;
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/hooks/location-overrides/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"rootDir": "./src",
"module": "ESNext"
},
"include": [
"./src/**/*.ts"
"./src/**/*.ts",
"../../lib/*.ts"
]
}
24 changes: 24 additions & 0 deletions src/extensions/lib/package-lock.json

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

17 changes: 17 additions & 0 deletions src/extensions/lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "lib",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo 'No tests for that folder'",
"build": "echo 'No build step for that folder'"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"any-ascii": "^0.3.2"
}
}
Loading