@orion-js/core 3.1.12 → 3.1.22

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.
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const safe_1 = __importDefault(require("colors/safe"));
7
7
  const execute_1 = __importDefault(require("../helpers/execute"));
8
8
  const writeIndex_1 = __importDefault(require("../start/watchAndCompile/writeIndex"));
9
- const writeEnvFile_1 = require("../start/watchAndCompile/writeEnvFile");
10
9
  const compile_1 = require("./compile");
11
- async function default_1({ output, envPath }) {
10
+ async function default_1({ output }) {
12
11
  if (!output) {
13
12
  output = './build';
14
13
  }
@@ -17,7 +16,6 @@ async function default_1({ output, envPath }) {
17
16
  console.log(safe_1.default.bold('Compiling your app...'));
18
17
  (0, compile_1.compile)({ output });
19
18
  (0, writeIndex_1.default)({ basePath: output });
20
- (0, writeEnvFile_1.writeEnvFile)({ basePath: output, envPath, createDtsFile: false });
21
19
  console.log(safe_1.default.bold('Build created'));
22
20
  }
23
21
  exports.default = default_1;
package/lib/index.js CHANGED
@@ -14,8 +14,6 @@ const test_1 = __importDefault(require("./test"));
14
14
  require("./handleErrors");
15
15
  const version_1 = __importDefault(require("./version"));
16
16
  require("dotenv/config");
17
- const init_1 = __importDefault(require("./env/init"));
18
- const add_1 = __importDefault(require("./env/add"));
19
17
  const program = new commander_1.Command();
20
18
  const run = function (action) {
21
19
  return async function (...args) {
@@ -32,25 +30,13 @@ program
32
30
  .description('Run the Orionjs app')
33
31
  .option('--shell', 'Opens a shell in Chrome developer tools')
34
32
  .option('--clean', 'Build the typescript project from scratch')
35
- .option('--env-path <path>', 'Specify the env file name')
36
33
  .action(run(start_1.default));
37
34
  program.command('test').allowUnknownOption().description('Deprecated command').action(run(test_1.default));
38
35
  program
39
36
  .command('build')
40
37
  .description('Compiles an Orionjs app and exports it to a simple nodejs app')
41
38
  .option('-o, --output [output]', 'Output directory')
42
- .option('--env-path <path>', 'Specify the env file name')
43
39
  .action(run(build_1.default));
44
- program
45
- .command('env-init')
46
- .description('Creates a new encrypted env file')
47
- .option('--env-path <path>', 'Specify the env file name')
48
- .action(run(init_1.default));
49
- program
50
- .command('env-add')
51
- .description('Adds a new environment to the encrypted env file')
52
- .option('--env-path <path>', 'Specify the env file name')
53
- .action(run(add_1.default));
54
40
  program
55
41
  .command('create')
56
42
  .description('Creates a new Orionjs project')
@@ -36,7 +36,6 @@ function getRunner(options) {
36
36
  return {
37
37
  restart,
38
38
  stop,
39
- envPath: options.envPath,
40
39
  basePath: `${process.cwd()}/.orion/build`
41
40
  };
42
41
  }
@@ -9,7 +9,6 @@ const getConfigPath_1 = require("./getConfigPath");
9
9
  const reports_1 = require("./reports");
10
10
  const safe_1 = __importDefault(require("colors/safe"));
11
11
  const writeIndex_1 = __importDefault(require("./writeIndex"));
12
- const writeEnvFile_1 = require("./writeEnvFile");
13
12
  function getHost(runner) {
14
13
  const reportWatchStatusChanged = (diagnostic) => {
15
14
  if (diagnostic.category !== 3)
@@ -28,7 +27,6 @@ function getHost(runner) {
28
27
  }
29
28
  }
30
29
  (0, writeIndex_1.default)({ basePath: runner.basePath });
31
- (0, writeEnvFile_1.writeEnvFile)({ basePath: runner.basePath, envPath: runner.envPath, createDtsFile: true });
32
30
  runner.restart();
33
31
  }
34
32
  };
@@ -3,52 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeEnvFile = exports.getDts = exports.watchEnvFile = void 0;
7
- const getConfig_1 = require("../../env/add/getConfig");
8
- const writeFile_1 = __importDefault(require("../../helpers/writeFile"));
6
+ exports.watchEnvFile = void 0;
9
7
  const chokidar_1 = __importDefault(require("chokidar"));
10
8
  const safe_1 = __importDefault(require("colors/safe"));
11
- const getFileContents_1 = __importDefault(require("../../helpers/getFileContents"));
9
+ const env_1 = require("@orion-js/env");
10
+ const envFilePath = process.env.ORION_ENV_FILE_PATH;
11
+ const dtsFilePath = './app/env.d.ts';
12
12
  const watchEnvFile = async (runner) => {
13
- if (!runner.envPath)
13
+ if (!envFilePath)
14
14
  return;
15
- const filePath = runner.envPath;
16
- chokidar_1.default.watch(filePath, { ignoreInitial: true }).on('change', async () => {
17
- (0, exports.writeEnvFile)({
18
- envPath: runner.envPath,
19
- basePath: runner.basePath,
20
- createDtsFile: true
21
- });
15
+ (0, env_1.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
16
+ chokidar_1.default.watch(envFilePath, { ignoreInitial: true }).on('change', async () => {
22
17
  console.log(safe_1.default.bold(`=> Environment file changed. Restarting...`));
18
+ (0, env_1.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
23
19
  runner.restart();
24
20
  });
25
21
  };
26
22
  exports.watchEnvFile = watchEnvFile;
27
- const getDts = config => {
28
- const keys = [...Object.keys(config.cleanKeys), ...Object.keys(config.encryptedKeys)];
29
- return `declare module '@orion-js/env' {
30
- export const env: {
31
- ${keys.map(key => ` ${key}: string;`).join('\n')}
32
- }
33
- }
34
- `;
35
- };
36
- exports.getDts = getDts;
37
- const writeEnvFile = async ({ basePath, envPath, createDtsFile }) => {
38
- const filePath = `${basePath}/env.js`;
39
- if (!envPath) {
40
- (0, writeFile_1.default)(filePath, `global.__orion_env__ = null`);
41
- return;
42
- }
43
- const config = (0, getConfig_1.getConfig)(envPath);
44
- const configJSON = JSON.stringify(config, null, 2);
45
- if (createDtsFile) {
46
- const currentFile = (0, getFileContents_1.default)('./app/env.d.ts');
47
- const dts = (0, exports.getDts)(config);
48
- if (currentFile !== dts) {
49
- (0, writeFile_1.default)('./app/env.d.ts', dts);
50
- }
51
- }
52
- (0, writeFile_1.default)(filePath, `global.__orion_env__ = ${configJSON}`);
53
- };
54
- exports.writeEnvFile = writeEnvFile;
@@ -21,7 +21,6 @@ moduleAlias.addAlias('app', path)
21
21
  const indexPath = `${basePath}/index.js`;
22
22
  (0, writeFile_1.default)(indexPath, `"use strict";
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- require("./env");
25
24
  require("./moduleAlias");
26
25
  require("./app");
27
26
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/core",
3
- "version": "3.1.12",
3
+ "version": "3.1.22",
4
4
  "main": "index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "upgrade-interactive": "yarn upgrade-interactive"
17
17
  },
18
18
  "dependencies": {
19
- "@orion-js/crypto": "^3.1.12",
19
+ "@orion-js/env": "^3.1.22",
20
20
  "chokidar": "3.5.3",
21
21
  "colors": "^1.4.0",
22
22
  "commander": "^8.3.0",
@@ -34,7 +34,7 @@
34
34
  "engines": {
35
35
  "node": ">=14.0.0"
36
36
  },
37
- "gitHead": "a6b82a931bea3179dfac4099579096c4f7a780bb",
37
+ "gitHead": "51b5af5952a486e40392381f769c69cfdfdc7b5e",
38
38
  "devDependencies": {
39
39
  "@shelf/jest-mongodb": "^2.1.0",
40
40
  "@types/prompts": "^2.0.14"
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encryptValue = void 0;
4
- const crypto_1 = require("@orion-js/crypto");
5
- const encryptValue = (key, value, config) => {
6
- if (key.startsWith('_')) {
7
- const newKey = key.replace(/^_/, '');
8
- config.cleanKeys[newKey] = value;
9
- return;
10
- }
11
- config.encryptedKeys[key] = crypto_1.asymmetric.encrypt(config.publicKey, value);
12
- };
13
- exports.encryptValue = encryptValue;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfig = void 0;
7
- const getFileContents_1 = __importDefault(require("../../helpers/getFileContents"));
8
- const yaml_1 = __importDefault(require("yaml"));
9
- const getConfig = (envPath) => {
10
- const configFile = (0, getFileContents_1.default)(envPath);
11
- if (!configFile) {
12
- throw new Error('No config file found');
13
- }
14
- return yaml_1.default.parse(configFile);
15
- };
16
- exports.getConfig = getConfig;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getParams = void 0;
7
- const prompts_1 = __importDefault(require("prompts"));
8
- const getParams = async (config) => {
9
- const response = await (0, prompts_1.default)([
10
- {
11
- type: 'text',
12
- name: 'key',
13
- message: 'Key'
14
- },
15
- {
16
- type: 'text',
17
- name: 'value',
18
- message: 'Value'
19
- }
20
- ]);
21
- return {
22
- key: response.key,
23
- value: response.value
24
- };
25
- };
26
- exports.getParams = getParams;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const encryptValue_1 = require("./encryptValue");
7
- const getConfig_1 = require("./getConfig");
8
- const getParams_1 = require("./getParams");
9
- const yaml_1 = __importDefault(require("yaml"));
10
- const writeFile_1 = __importDefault(require("../../helpers/writeFile"));
11
- const sortObjectByKeys = (object) => {
12
- const sorted = {};
13
- Object.keys(object)
14
- .sort()
15
- .forEach(key => {
16
- sorted[key] = object[key];
17
- });
18
- return sorted;
19
- };
20
- async function envAdd({ envPath }) {
21
- if (!envPath) {
22
- envPath = '.env.local.yml';
23
- }
24
- const config = (0, getConfig_1.getConfig)(envPath);
25
- const { key, value } = await (0, getParams_1.getParams)(config);
26
- if (!value)
27
- return;
28
- (0, encryptValue_1.encryptValue)(key, value, config);
29
- // sort keys alphabetically
30
- config.cleanKeys = sortObjectByKeys(config.cleanKeys);
31
- config.encryptedKeys = sortObjectByKeys(config.encryptedKeys);
32
- const text = yaml_1.default.stringify(config);
33
- (0, writeFile_1.default)(envPath, text);
34
- }
35
- exports.default = envAdd;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const crypto_1 = require("@orion-js/crypto");
7
- const yaml_1 = __importDefault(require("yaml"));
8
- const writeFile_1 = __importDefault(require("../../helpers/writeFile"));
9
- async function envInit({ envPath }) {
10
- if (!envPath) {
11
- envPath = '.env.local.yml';
12
- }
13
- const keypair = crypto_1.asymmetric.generateKeys();
14
- const envFile = {
15
- version: '1.0',
16
- publicKey: keypair.encryptKey,
17
- cleanKeys: {},
18
- encryptedKeys: {}
19
- };
20
- const text = yaml_1.default.stringify(envFile);
21
- (0, writeFile_1.default)(envPath, text);
22
- console.log('');
23
- console.log(`Environment file created. You need to use the following key to decrypt the environment variables:`);
24
- console.log('');
25
- console.log(keypair.decryptKey);
26
- console.log('');
27
- }
28
- exports.default = envInit;