-
Notifications
You must be signed in to change notification settings - Fork 17
/
publishExample.mjs
82 lines (66 loc) · 2.29 KB
/
publishExample.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from "fs";
import os from "os";
import path from "path";
import shell from "shelljs";
import { fileURLToPath } from "url";
if (!shell.which("git")) {
shell.echo("Error: Git is not installed.");
shell.exit(1);
}
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJSON = JSON.parse(
fs.readFileSync(path.join(__dirname, "package.json")),
);
const directoryPath = path.join(__dirname, "test");
const repositoryUrl = "git@github.com:get-convex/convex-auth-example.git";
// Create a temporary directory
const tempDir = fs.mkdtempSync(
path.join(os.tmpdir(), "convex-auth-publish-example-"),
);
// const tempDir = "publish";
// Copy the directory to the temporary directory
shell.exec(`rsync -av --exclude 'node_modules' ${directoryPath}/ ${tempDir}/`);
// Navigate to the temporary directory
shell.cd(tempDir);
// Remove lines not belonging in example
shell.exec(
`find . -type f | xargs perl -i -pe 'if (/\\/\\/ !publish: remove/) { $_ = <>; $_ = "" }'`,
);
// Fix up package.json
shell.exec(
`perl -i -pe 's#"\\@convex-dev/auth": "file:..",#"\\@convex-dev/auth": "^${packageJSON.version}",#' package.json`,
);
shell.exec(
`perl -i -pe 's#"convex": "file:../node_modules/convex",#"convex": "^1.12.2",#' package.json`,
);
shell.exec(
`perl -i -pe 's#"react": "file:../node_modules/react",#"react": "^18.3.0",#' package.json`,
);
shell.exec(
`perl -i -pe 's#"react-dom": "file:../node_modules/react-dom",#"react-dom": "^18.3.0",#' package.json`,
);
// Remove unneeded files
shell.rm("convex/otp/FakePhone.ts");
shell.rm("convex/*.test.ts");
shell.rm("convex/test.helpers.ts");
// Initialize a new git repo
shell.exec("git init");
shell.exec("git add .");
shell.exec(
'git commit -m "Published from https://github.com/get-convex/convex-auth"',
);
// Force push to the repository for deploying to Vercel
shell.exec(`git push --force ${repositoryUrl} HEAD:vercel`);
/// Push to main
// Remove base URL handling from links
shell.exec(
`find src -type f | xargs perl -i -pe 's#\\{import\\.meta\\.env\\.BASE_URL\\}#"/"#'`,
);
// Remove unneeded Vercel config
shell.rm("vercel.json");
// Push
shell.exec("git add .");
shell.exec("git commit --amend -C HEAD");
shell.exec(`git push --force ${repositoryUrl} HEAD:main`);
// Clean up the temporary directory
shell.rm("-rf", tempDir);