Skip to content

Commit

Permalink
feat: adding environment.ts generator scripts (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Sep 11, 2019
1 parent 3addc7c commit ffb04cd
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .scripts/configure.ts
@@ -0,0 +1,58 @@
// NOTE: do NOT ever put here any secure settings! (e.g. Secret Keys)
// We are using dotenv (.env) for consistency with other Platform projects
// This is Angular app and all settings will be loaded into the client browser!

import { env } from './env';
import { writeFile, unlinkSync } from 'fs';
import { argv } from 'yargs';

const environment = argv.environment;
const isProd = environment === 'prod';

const envFileContent = `// NOTE: Auto-generated file
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses 'environment.ts', but if you do
// 'ng build --env=prod' then 'environment.prod.ts' will be used instead.
// The list of which env maps to which file can be found in '.angular-cli.json'.
import { Environment } from './model';
export const environment: Environment = {
production: ${isProd}
};
`;

/*
// we always want first to remove old generated files (one of them is not needed for current build)
try {
unlinkSync(`./apps/gauzy/src/environments/environment.ts`);
} catch {}
try {
unlinkSync(`./apps/gauzy/src/environments/environment.prod.ts`);
} catch {}
const envFileDest: string = isProd ? 'environment.prod.ts' : 'environment.ts';
const envFileDestOther: string = !isProd
? 'environment.prod.ts'
: 'environment.ts';
writeFile(`./apps/gauzy/src/environments/${envFileDest}`, envFileContent, function(err) {
if (err) {
console.log(err);
} else {
console.log(`Generated Angular environment file: ${envFileDest}`);
}
});
writeFile(`./apps/gauzy/src/environments/${envFileDestOther}`, '', function(err) {
if (err) {
console.log(err);
} else {
console.log(
`Generated Second Empty Angular environment file: ${envFileDestOther}`
);
}
});
*/
17 changes: 17 additions & 0 deletions .scripts/env.ts
@@ -0,0 +1,17 @@
// NOTE: do NOT ever put here any secure settings! (e.g. Secret Keys)
// We are using dotenv (.env) for consistency with other Platform projects
// This is Angular app and all settings will be loaded into the client browser!

import { cleanEnv, num, str, bool } from 'envalid';

export type Env = Readonly<{
production: boolean;
}>;

export const env: Env = cleanEnv(
process.env,
{
production: bool({ default: false })
},
{ strict: true, dotEnvPath: __dirname + '/../.env' }
);

0 comments on commit ffb04cd

Please sign in to comment.