docker-react 0.0.1-alpha.0 → 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -2
- package/dist/options.d.ts +6 -0
- package/dist/options.js +1 -0
- package/dist/prep.d.ts +2 -0
- package/dist/prep.js +51 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
# Docker React
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CLI & base image to deploy React applications with docker containers.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- [ ]
|
|
8
|
-
- [ ]
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
- [ ]
|
|
7
|
+
- [ ] Configuration
|
|
8
|
+
- [ ] Command-line arguments
|
|
9
|
+
- [ ] Configuration file
|
|
10
|
+
- [ ] Lightweight nginx docker container
|
|
11
|
+
- [ ] CLI
|
|
12
|
+
- [ ] Runtime environment variable injection & validation
|
|
13
|
+
- [ ] Javascript
|
|
14
|
+
- [ ] HTML
|
|
15
|
+
- [ ] Hash file for cache invalidation
|
|
16
|
+
- [ ] Application initialization
|
|
17
|
+
- [ ] `index.html` file modification
|
|
18
|
+
- [ ] `Dockerfile` generation
|
|
19
|
+
- [ ] Schema and types generation
|
|
12
20
|
- [ ] Support for serving at a path
|
|
13
|
-
- [ ] Application initialisations
|
|
14
21
|
|
|
15
22
|
## Supported Tooling
|
|
16
23
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function cli(): void;
|
|
1
|
+
export declare function cli(args: string[]): void;
|
package/dist/index.js
CHANGED
package/dist/options.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/prep.d.ts
ADDED
package/dist/prep.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
const ENVIRONMENT_DEFINITION_FILE_NAME = 'window.env.js';
|
|
5
|
+
export function addPrepCommand(program) {
|
|
6
|
+
return program
|
|
7
|
+
.command('prep')
|
|
8
|
+
.description('Prepare the application for serving')
|
|
9
|
+
.option('-e, --environment [string]', 'The environment to run preparation over', 'docker')
|
|
10
|
+
.option('-s, --schema [string]', 'The path to the schema file')
|
|
11
|
+
.option('-d, --destination [string', 'The path to the destination')
|
|
12
|
+
.action((options) => {
|
|
13
|
+
const { environment, schema = './joi.schema.js', destination = './', } = options;
|
|
14
|
+
generateEnvironmentFile(environment, schema, destination);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function validateEnvironmentVariables(schema, environmentVariables) {
|
|
18
|
+
const joiResult = schema.validate(environmentVariables, {
|
|
19
|
+
allowUnknown: true,
|
|
20
|
+
abortEarly: false,
|
|
21
|
+
stripUnknown: true,
|
|
22
|
+
});
|
|
23
|
+
if (joiResult.error) {
|
|
24
|
+
throw new Error(joiResult.error.message);
|
|
25
|
+
}
|
|
26
|
+
return joiResult.value;
|
|
27
|
+
}
|
|
28
|
+
async function generateEnvironmentFile(environment, schemaPath, destinationPath) {
|
|
29
|
+
// For local environments attempt to load from `.env` files if available.
|
|
30
|
+
if (environment === 'local') {
|
|
31
|
+
const result = dotenv.config();
|
|
32
|
+
if (result.error) {
|
|
33
|
+
throw result.error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Perform environment variable validation.
|
|
37
|
+
const schemaLocation = path.join(process.cwd(), schemaPath);
|
|
38
|
+
console.log(`Attempting to load schema from ${schemaLocation}`);
|
|
39
|
+
const providedSchema = await import(schemaLocation);
|
|
40
|
+
// const envSchema = baseSchema.concat(providedSchema);
|
|
41
|
+
const envSchema = providedSchema.default;
|
|
42
|
+
console.log('Validating environment variables');
|
|
43
|
+
const validatedWindowVariables = validateEnvironmentVariables(envSchema, process.env);
|
|
44
|
+
// Prepare file and calculate hash
|
|
45
|
+
console.log('Attempting to generate environment file.');
|
|
46
|
+
const mappedWindowVariables = Object.entries(validatedWindowVariables).map((entry) => `${entry[0]}:'${entry[1]}'`);
|
|
47
|
+
const windowVariablesToBeWrittenToFile = `window.env={${mappedWindowVariables}};`;
|
|
48
|
+
const envFileDestination = path.join(destinationPath, ENVIRONMENT_DEFINITION_FILE_NAME);
|
|
49
|
+
console.log(`Writing window env file to ${envFileDestination}`);
|
|
50
|
+
await fs.writeFile(envFileDestination, windowVariablesToBeWrittenToFile, 'utf8');
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docker-react",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
4
|
"description": "Tooling to deploy React applications with docker containers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,12 @@
|
|
|
27
27
|
"homepage": "https://github.com/danielemery/docker-react#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@danielemeryau/prettier-config": "^0.0.6",
|
|
30
|
+
"@types/node": "^16.0.0",
|
|
30
31
|
"typescript": "^4.5.4"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^8.3.0",
|
|
35
|
+
"dotenv": "^10.0.0",
|
|
36
|
+
"joi": "^17.5.0"
|
|
31
37
|
}
|
|
32
38
|
}
|