Skip to content

Commit

Permalink
chore: remove copy-env command (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 authored Aug 17, 2023
1 parent b79dae5 commit 6c09991
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 624 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ v

# storybook
storybook-static
build-storybook.log
build-storybook.log

# environment
!apps/api/.env
!apps/client/.env
1 change: 1 addition & 0 deletions apps/api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../.env
1 change: 0 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"format": "yarn prisma format",
"generate": "yarn prisma generate",
"typecheck": "yarn run generate && tsc --noEmit",
"copy-env": "node ../../scripts/copy-env.mjs --api",
"test:watch": "yarn vitest --watch",
"test": "yarn vitest run"
},
Expand Down
1 change: 1 addition & 0 deletions apps/client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../.env
2 changes: 1 addition & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start:proxy-experimental": "yarn next start --port 80",
"validate": "node ../../scripts/validate.mjs",
"typecheck": "yarn tsc --noEmit",
"copy-env": "node ../../scripts/copy-env.mjs --client",
"set-client-port": "node ../../scripts/set-client-port.mjs --client",
"validate-locales": "node ../../scripts/validate-locales.mjs",
"test:watch": "yarn vitest --watch",
"test": "yarn vitest run",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@casperiv/eslint-config-react": "8.0.0",
"colorette": "2.0.20",
"concurrently": "^8.2.0",
"copy": "^0.3.2",
"dotenv": "^16.3.1",
"eslint": "8.47.0",
"husky": "^8.0.3",
Expand Down
39 changes: 0 additions & 39 deletions scripts/copy-env.mjs → scripts/set-client-port.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "dotenv/config";
import process from "node:process";
import { one } from "copy";
import { join } from "node:path";
import { readFile, writeFile } from "node:fs/promises";
import { EOL } from "node:os";
Expand Down Expand Up @@ -43,47 +42,9 @@ async function addPortToClientPackageJson() {

const [, , ...args] = process.argv;
const copyToClient = hasArg("--client");
const copyToApi = hasArg("--api");

let ENV_FILE_PATH = join(process.cwd(), ".env");

if (ENV_FILE_PATH.endsWith("/apps/client/.env") || ENV_FILE_PATH.endsWith("/apps/api/.env")) {
ENV_FILE_PATH = ENV_FILE_PATH.replace(/apps\/(client|api)\//, "");
}

/**
* @param {string} distDir
*/
function copyEnv(distDir) {
try {
one(ENV_FILE_PATH, distDir, (error) => {
if (error) {
console.log({ error });
return;
}

const isClient = distDir.endsWith("client");
const isApi = distDir.endsWith("api");
const type = isClient ? "client" : isApi ? "api" : null;

if (type) {
console.log(`✅ copied .env — ${type}`);
}
});
} catch (e) {
console.log({ e });
}
}

if (copyToClient) {
const CLIENT_PACKAGE_PATH = join(process.cwd(), "apps", "client");
addPortToClientPackageJson();
copyEnv(CLIENT_PACKAGE_PATH);
}

if (copyToApi) {
const API_PACKAGE_PATH = join(process.cwd(), "apps", "api");
copyEnv(API_PACKAGE_PATH);
}

function hasArg(arg) {
Expand Down
73 changes: 17 additions & 56 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,42 @@
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"@snailycad/client#build": {
"dependsOn": [
"copy-env",
"^build"
],
"outputs": [
".next/**"
]
"dependsOn": ["set-client-port", "^build"],
"outputs": [".next/**"]
},
"@snailycad/api#build": {
"dependsOn": [
"copy-env",
"^build"
]
"dependsOn": ["set-client-port", "^build"]
},
"copy-env": {
"set-client-port": {
"cache": false,
"dependsOn": [
"^copy-env"
],
"outputs": [
".env"
]
"dependsOn": ["^set-client-port"],
"outputs": [".env"]
},
"create-images-domain": {
"dependsOn": [
"^create-images-domain"
],
"outputs": [
"next.config.mjs"
]
"dependsOn": ["^create-images-domain"],
"outputs": ["next.config.mjs"]
},
"validate-locales": {
"dependsOn": [
"^validate-locales"
]
"dependsOn": ["^validate-locales"]
},
"build": {
"dependsOn": [
"copy-env",
"create-images-domain",
"validate-locales",
"^build"
],
"outputs": [
".next/**",
"dist/**"
]
"dependsOn": ["set-client-port", "create-images-domain", "validate-locales", "^build"],
"outputs": [".next/**", "dist/**"]
},
"typecheck": {
"dependsOn": [
"^typecheck"
],
"dependsOn": ["^typecheck"],
"outputs": []
},
"test": {
"dependsOn": [
"^test"
],
"inputs": [
"src/**/*.tsx",
"src/**/*.ts",
"tests/**/*.test.ts"
],
"dependsOn": ["^test"],
"inputs": ["src/**/*.tsx", "src/**/*.ts", "tests/**/*.test.ts"],
"outputs": []
},
"watch": {
"persistent": true,
"cache": false,
"outputs": [
".next/*",
"dist/*"
]
"outputs": [".next/*", "dist/*"]
}
},
"globalDependencies": [
"**/.env"
]
}
"globalDependencies": ["**/.env"]
}
Loading

0 comments on commit 6c09991

Please sign in to comment.