Skip to content

Commit f1d76ea

Browse files
paulpaul
paul
authored and
paul
committed
Proposed change to add helpfull scripts to make it easier for folks try the project locally
1 parent 9b9479d commit f1d76ea

8 files changed

+519
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
.vscode
4+
.env

copy-env.mts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
function copyEnvFile(targetDir: string): void {
5+
// Ensure targetDir is trimmed
6+
targetDir = targetDir.trim();
7+
8+
const examplePath: string = path.join(targetDir, ".env.example");
9+
const envPath: string = path.join(targetDir, ".env");
10+
11+
console.log("Attempting to copy from:", examplePath);
12+
console.log("To:", envPath);
13+
// Check if .env.example exists
14+
fs.access(examplePath, fs.constants.F_OK, (err: Error | null) => {
15+
if (err) {
16+
console.error(`.env.example file does not exist in ${targetDir}`);
17+
return;
18+
}
19+
20+
// .env.example exists, now check for .env
21+
fs.access(envPath, fs.constants.F_OK, (err: Error | null) => {
22+
if (err) {
23+
// .env file does not exist, copy .env.example to .env
24+
fs.copyFile(examplePath, envPath, (err: Error | null) => {
25+
if (err) {
26+
console.error("Error occurred:", err);
27+
return;
28+
}
29+
console.log(`.env.example has been copied to ${envPath}`);
30+
});
31+
} else {
32+
// .env file exists, no action needed
33+
console.log(
34+
`.env file already exists in ${targetDir}, no action taken.`
35+
);
36+
}
37+
});
38+
});
39+
}
40+
41+
// Get the directory path from the command line argument and trim whitespace
42+
const directoryPath: string | undefined = process.argv[2]?.trim();
43+
44+
if (directoryPath) {
45+
copyEnvFile(directoryPath);
46+
} else {
47+
console.error("Please provide a directory path as an argument.");
48+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
WEBSITE_URL=http://localhost:3000 # Add the correct ENV var for this onto your hosting platform, point it to your production website.
22
PORT=3000
33

4-
NEXT_PUBLIC_API_URL=url-of-strapi
4+
NEXT_PUBLIC_API_URL=http://localhost:1337
55
PREVIEW_SECRET=the-same-random-token-as-for-strapi

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "strapi-next-launchpad-example",
3+
"version": "1.0.0",
4+
"description": "Next.js Launchpad Example powered by Strapi",
5+
"type": "module",
6+
"scripts": {
7+
"next": "yarn dev --prefix ../next/",
8+
"strapi": "yarn dev --prefix ../strapi/",
9+
"setup:next": "cd next && yarn && node --loader ts-node/esm ../copy-env.mts ./",
10+
"setup:strapi": "cd strapi && yarn && node --loader ts-node/esm ../copy-env.mts ./",
11+
"setup": "yarn install && yarn setup:next && yarn setup:strapi",
12+
"dev": "yarn concurrently \"cd strapi && yarn develop\" \"npx wait-on http://localhost:1337 && cd next && yarn dev\"",
13+
"seed": "cd strapi && yarn strapi import -f ./data/export_20250116105447.tar.gz --force",
14+
"export": "cd strapi && yarn strapi export --no-encrypt -f ./data/export_20250116105447",
15+
"repo:upstream": "git fetch upstream && git merge upstream/main"
16+
},
17+
"dependencies": {
18+
"@types/node": "^22.5.2",
19+
"concurrently": "^8.2.2",
20+
"typescript": "^5.0.0",
21+
"wait-on": "^8.0.1"
22+
},
23+
"devDependencies": {
24+
"ts-node": "^10.9.2"
25+
}
26+
}

strapi/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ADMIN_JWT_SECRET=tobemodified
66
TRANSFER_TOKEN_SALT=tobemodified
77
JWT_SECRET=tobemodified
88

9-
STRAPI_ADMIN_CLIENT_URL=url-of-nextjs
9+
STRAPI_ADMIN_CLIENT_URL=http://localhost:3000
1010
STRAPI_ADMIN_CLIENT_PREVIEW_SECRET=a-random-token
1111

1212
CLIENT_URL=http://localhost:3000
73 Bytes
Binary file not shown.

strapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"name": "A Strapi developer"
3737
},
3838
"strapi": {
39-
"uuid": "LAUNCHPAD"
39+
"uuid": "LAUNCHPAD-LOCAL-17cde2ab-67bc-4db4-ba40-736eb124ebc1"
4040
},
4141
"engines": {
4242
"node": ">=18.0.0 <=20.x.x",

0 commit comments

Comments
 (0)