-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate environment file
- Loading branch information
1 parent
cebb1fd
commit 22233bc
Showing
9 changed files
with
87 additions
and
80 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SANITY_PROJECT_ID="" | ||
SANITY_DATASET="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,6 @@ testem.log | |
Thumbs.db | ||
.vercel | ||
.angular | ||
|
||
environment.ts | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This file generates the Angular environment.ts file with the required environment variables from the .env file. | ||
|
||
const setEnv = () => { | ||
const fs = require("fs"); | ||
const writeFile = fs.writeFile; | ||
// Configure Angular `environment.ts` file path | ||
const targetPath = "./src/environments/environment.ts"; | ||
// Load node modules | ||
require("dotenv").config({ | ||
path: "./.env", | ||
}); | ||
|
||
if (!process.env["SANITY_PROJECT_ID"] || !process.env["SANITY_DATASET"]) { | ||
console.error( | ||
"Sanity project ID and dataset name are required. Go into 'app/src/environments/environment.ts' and set them." | ||
); | ||
} | ||
// `environment.ts` file structure | ||
const envConfigFile = `export const environment = { | ||
production: false, | ||
sanity: { | ||
projectId: '${process.env["SANITY_PROJECT_ID"]}', | ||
dataset: '${process.env["SANITY_DATASET"]}', | ||
apiVersion: "2024-12-12", | ||
useCdn: true, // set to false for fresh data | ||
}, | ||
}; | ||
console.log("environment:", environment); | ||
`; | ||
// const envConfigFile = `export const environment = { | ||
// SANITY_PROJECT_ID: '${process.env["SANITY_PROJECT_ID"]}', | ||
// SANITY_DATASET: '${process.env["SANITY_DATASET"]}', | ||
// production: true, | ||
// }; | ||
// `; | ||
// console.log( | ||
// "The file `environment.ts` will be written with the following content: \n" | ||
// ); | ||
writeFile(targetPath, envConfigFile, (err) => { | ||
if (err) { | ||
console.error(err); | ||
throw err; | ||
} else { | ||
console.log( | ||
`Angular environment.ts file generated correctly at ${targetPath} \n` | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
setEnv(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
SANITY_STUDIO_PROJECT_ID="" | ||
SANITY_STUDIO_DATASET="" | ||
SANITY_STUDIO_STUDIO_HOST="" #Optional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
/** | ||
* Sanity CLI Configuration | ||
* This file configures the Sanity CLI tool with project-specific settings | ||
* and customizes the Vite bundler configuration. | ||
* Learn more: https://www.sanity.io/docs/cli | ||
*/ | ||
|
||
import {defineCliConfig} from 'sanity/cli' | ||
import {projectId, dataset} from './sanity.config' | ||
|
||
const projectId = process.env.SANITY_STUDIO_PROJECT_ID || '<your project ID>' | ||
const dataset = process.env.SANITY_STUDIO_DATASET || 'production' | ||
|
||
export default defineCliConfig({ | ||
api: { | ||
projectId, | ||
dataset, | ||
}, | ||
studioHost: process.env.SANITY_STUDIO_STUDIO_HOST || '', // Visit https://www.sanity.io/docs/environment-variables to leanr more about using environment variables for local & production. | ||
autoUpdates: true, | ||
}) |