Compare commits
2 Commits
5be7b84972
...
hydrators-
| Author | SHA1 | Date | |
|---|---|---|---|
| 5947dcdc86 | |||
| f0aca17a0a |
@@ -61,7 +61,7 @@ const makeApp = ({routes, processTitle}: MakeAppArgs) => {
|
|||||||
console.log("DEBUG: trying pattern, match result =", match);
|
console.log("DEBUG: trying pattern, match result =", match);
|
||||||
if (match) {
|
if (match) {
|
||||||
console.log("match", match);
|
console.log("match", match);
|
||||||
const resp = await pr.handler(req);
|
const resp = await pr.handler(req, match.params);
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
|
|||||||
|
|
||||||
const handler: InternalHandler = async (
|
const handler: InternalHandler = async (
|
||||||
expressRequest: ExpressRequest,
|
expressRequest: ExpressRequest,
|
||||||
|
params: Record<string, string>,
|
||||||
): Promise<Result> => {
|
): Promise<Result> => {
|
||||||
const method = massageMethod(expressRequest.method);
|
const method = massageMethod(expressRequest.method);
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
|
|||||||
pattern: route.path,
|
pattern: route.path,
|
||||||
path: expressRequest.originalUrl,
|
path: expressRequest.originalUrl,
|
||||||
method,
|
method,
|
||||||
parameters: { one: 1, two: 2 },
|
parameters: params,
|
||||||
request: expressRequest,
|
request: expressRequest,
|
||||||
user: auth.user,
|
user: auth.user,
|
||||||
session: new Session(auth.session, auth.user),
|
session: new Session(auth.session, auth.user),
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ export type Call = {
|
|||||||
pattern: string;
|
pattern: string;
|
||||||
path: string;
|
path: string;
|
||||||
method: Method;
|
method: Method;
|
||||||
parameters: object;
|
parameters: Record<string, string>;
|
||||||
request: ExpressRequest;
|
request: ExpressRequest;
|
||||||
user: User;
|
user: User;
|
||||||
session: Session;
|
session: Session;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InternalHandler = (req: ExpressRequest) => Promise<Result>;
|
export type InternalHandler = (req: ExpressRequest, params: Record<string, string>) => Promise<Result>;
|
||||||
|
|
||||||
export type Handler = (call: Call) => Promise<Result>;
|
export type Handler = (call: Call) => Promise<Result>;
|
||||||
export type ProcessedRoute = {
|
export type ProcessedRoute = {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ echo working dir: $PWD
|
|||||||
|
|
||||||
# exit 0
|
# exit 0
|
||||||
|
|
||||||
tar cvf - $(cat "$PWD/file-list" | grep -v '^#') | (cd "$here" && tar xf -)
|
tar cvf - $(cat "$PWD/file-list" | grep -v '^#' | sed 's/^?//') | (cd "$here" && tar xf -)
|
||||||
|
|
||||||
echo "$ref" > .diachron-version
|
echo "$ref" > "$here/.diachron-version"
|
||||||
|
|
||||||
echo "Now, run the command ./sync.sh"
|
echo "Now, run the command ./sync.sh"
|
||||||
|
|||||||
@@ -187,6 +187,21 @@ framework. When you create or delete a file that is part of the project
|
|||||||
(not a scratch file or generated output), you must update `file-list` to
|
(not a scratch file or generated output), you must update `file-list` to
|
||||||
match. Keep it sorted alphabetically.
|
match. Keep it sorted alphabetically.
|
||||||
|
|
||||||
|
Entries can have a `?` prefix (e.g. `?backend/app.ts`). These are
|
||||||
|
**sample files** -- starter code that `bootstrap.sh` copies into a new
|
||||||
|
project but that `upgrade.sh` will not overwrite. Once the user has the
|
||||||
|
file, it belongs to them. On upgrade, new sample files that don't exist
|
||||||
|
yet in the project are copied in; existing ones are left untouched.
|
||||||
|
|
||||||
|
Unprefixed entries are **framework-owned** and are always replaced on
|
||||||
|
upgrade. When adding a new file to `file-list`, decide which category
|
||||||
|
it belongs to:
|
||||||
|
|
||||||
|
- Framework-owned (no prefix): infrastructure scripts, framework
|
||||||
|
library code, build tooling, config that must stay in sync.
|
||||||
|
- Sample (`?` prefix): application starter code the user is expected
|
||||||
|
to edit (routes, handlers, services, types, package.json, etc.).
|
||||||
|
|
||||||
## Things to avoid
|
## Things to avoid
|
||||||
|
|
||||||
- Do not introduce `.env` files or `dotenv` without checking with the
|
- Do not introduce `.env` files or `dotenv` without checking with the
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ if ! git -C "$cached_repo" rev-parse --verify "$ref^{commit}" >/dev/null 2>&1; t
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read file-list
|
# Read file-list (strip ? prefix from sample entries)
|
||||||
files=()
|
files=()
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
[[ -z "$line" ]] && continue
|
[[ -z "$line" ]] && continue
|
||||||
files+=("$line")
|
files+=("${line#\?}")
|
||||||
done < "$DIR/file-list"
|
done < "$DIR/file-list"
|
||||||
|
|
||||||
# Check out upstream into a temp directory
|
# Check out upstream into a temp directory
|
||||||
|
|||||||
21
file-list
21
file-list
@@ -1,27 +1,32 @@
|
|||||||
# please keep this file sorted alphabetically
|
# please keep this file sorted alphabetically
|
||||||
|
#
|
||||||
|
# Files prefixed with ? are sample/starter files. bootstrap.sh copies them
|
||||||
|
# into a new project, but upgrade.sh will not overwrite them if the user has
|
||||||
|
# already modified or replaced them. Unprefixed files are framework-owned
|
||||||
|
# and are always replaced on upgrade.
|
||||||
|
|
||||||
.gitignore
|
.gitignore
|
||||||
.go-version
|
.go-version
|
||||||
DIACHRON.md
|
DIACHRON.md
|
||||||
backend/.gitignore
|
backend/.gitignore
|
||||||
backend/.npmrc
|
backend/.npmrc
|
||||||
backend/app.ts
|
?backend/app.ts
|
||||||
backend/build.sh
|
backend/build.sh
|
||||||
backend/check-deps.ts
|
backend/check-deps.ts
|
||||||
backend/check.sh
|
backend/check.sh
|
||||||
backend/diachron
|
backend/diachron
|
||||||
backend/generated
|
backend/generated
|
||||||
backend/group.ts
|
?backend/group.ts
|
||||||
backend/handlers.spec.ts
|
?backend/handlers.spec.ts
|
||||||
backend/handlers.ts
|
?backend/handlers.ts
|
||||||
backend/package.json
|
?backend/package.json
|
||||||
backend/pnpm-workspace.yaml
|
backend/pnpm-workspace.yaml
|
||||||
backend/routes.ts
|
?backend/routes.ts
|
||||||
backend/run.sh
|
backend/run.sh
|
||||||
backend/services.ts
|
?backend/services.ts
|
||||||
backend/show-config.sh
|
backend/show-config.sh
|
||||||
backend/tsconfig.json
|
backend/tsconfig.json
|
||||||
backend/types.ts
|
?backend/types.ts
|
||||||
backend/watch.sh
|
backend/watch.sh
|
||||||
bootstrap.sh
|
bootstrap.sh
|
||||||
cmd
|
cmd
|
||||||
|
|||||||
50
upgrade.sh
50
upgrade.sh
@@ -62,11 +62,17 @@ echo "Upgrading: $old_ref -> $new_ref"
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Read current file-list (files to remove)
|
# Read current file-list (files to remove)
|
||||||
|
# Entries prefixed with ? are sample files -- we don't remove those on upgrade.
|
||||||
old_files=()
|
old_files=()
|
||||||
|
old_samples=()
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
[[ -z "$line" ]] && continue
|
[[ -z "$line" ]] && continue
|
||||||
old_files+=("$line")
|
if [[ "$line" == \?* ]]; then
|
||||||
|
old_samples+=("${line#\?}")
|
||||||
|
else
|
||||||
|
old_files+=("$line")
|
||||||
|
fi
|
||||||
done < "$DIR/file-list"
|
done < "$DIR/file-list"
|
||||||
|
|
||||||
# Clone and checkout new version into a temp directory
|
# Clone and checkout new version into a temp directory
|
||||||
@@ -76,25 +82,44 @@ git -C "$tmpdir/diachron" checkout --quiet "$new_ref"
|
|||||||
|
|
||||||
# Read new file-list (files to add)
|
# Read new file-list (files to add)
|
||||||
new_files=()
|
new_files=()
|
||||||
|
new_samples=()
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
[[ -z "$line" ]] && continue
|
[[ -z "$line" ]] && continue
|
||||||
new_files+=("$line")
|
if [[ "$line" == \?* ]]; then
|
||||||
|
new_samples+=("${line#\?}")
|
||||||
|
else
|
||||||
|
new_files+=("$line")
|
||||||
|
fi
|
||||||
done < "$tmpdir/diachron/file-list"
|
done < "$tmpdir/diachron/file-list"
|
||||||
|
|
||||||
# Remove old framework files
|
# Remove old framework files (not samples -- those belong to the user)
|
||||||
for f in "${old_files[@]}"; do
|
for f in "${old_files[@]}"; do
|
||||||
git -C "$DIR" rm -rf --quiet --ignore-unmatch "$f"
|
git -C "$DIR" rm -rf --quiet --ignore-unmatch "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Copy in new framework files
|
# Copy in new framework files
|
||||||
(cd "$tmpdir/diachron" && tar cvf - "${new_files[@]}") | (cd "$DIR" && tar xf -)
|
(cd "$tmpdir/diachron" && tar cf - "${new_files[@]}") | (cd "$DIR" && tar xf -)
|
||||||
|
|
||||||
# Stage them
|
# Stage them
|
||||||
for f in "${new_files[@]}"; do
|
for f in "${new_files[@]}"; do
|
||||||
git -C "$DIR" add "$f"
|
git -C "$DIR" add "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Handle sample files: copy only if the user doesn't already have them
|
||||||
|
samples_added=()
|
||||||
|
samples_skipped=()
|
||||||
|
for f in "${new_samples[@]}"; do
|
||||||
|
if [ -e "$DIR/$f" ]; then
|
||||||
|
samples_skipped+=("$f")
|
||||||
|
else
|
||||||
|
# New sample that doesn't exist yet -- copy it in
|
||||||
|
(cd "$tmpdir/diachron" && tar cf - "$f") | (cd "$DIR" && tar xf -)
|
||||||
|
git -C "$DIR" add "$f"
|
||||||
|
samples_added+=("$f")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Update version marker
|
# Update version marker
|
||||||
echo "$new_ref" > "$DIR/.diachron-version"
|
echo "$new_ref" > "$DIR/.diachron-version"
|
||||||
git -C "$DIR" add "$DIR/.diachron-version"
|
git -C "$DIR" add "$DIR/.diachron-version"
|
||||||
@@ -102,6 +127,23 @@ git -C "$DIR" add "$DIR/.diachron-version"
|
|||||||
echo "=== Upgrade staged: $old_ref -> $new_ref ==="
|
echo "=== Upgrade staged: $old_ref -> $new_ref ==="
|
||||||
echo ""
|
echo ""
|
||||||
echo "Framework files have been removed, replaced, and staged."
|
echo "Framework files have been removed, replaced, and staged."
|
||||||
|
|
||||||
|
if [ ${#samples_added[@]} -gt 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo "New sample files added:"
|
||||||
|
for f in "${samples_added[@]}"; do
|
||||||
|
echo " + $f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#samples_skipped[@]} -gt 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo "Sample files skipped (you already have these):"
|
||||||
|
for f in "${samples_skipped[@]}"; do
|
||||||
|
echo " ~ $f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Next steps:"
|
echo "Next steps:"
|
||||||
echo " 1. Review: git diff --cached"
|
echo " 1. Review: git diff --cached"
|
||||||
|
|||||||
Reference in New Issue
Block a user