5htp 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "5htp",
3
3
  "description": "5-HTP, scientifically called 5-Hydroxytryptophan, is the precursor of happiness neurotransmitter.",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-cli.git",
7
7
  "license": "MIT",
8
8
  "bin": {
9
- "5htp": "cli/index.ts"
9
+ "5htp": "src/index.ts"
10
10
  },
11
11
  "engines": {
12
12
  "node": ">=16.1.0",
@@ -42,7 +42,6 @@
42
42
  "@types/universal-analytics": "^0.4.5",
43
43
  "@types/webpack-env": "^1.16.2",
44
44
  "@types/ws": "^7.4.7",
45
- "5htp-core": "^0.0.2",
46
45
  "babel-loader": "^8.2.2",
47
46
  "babel-plugin-transform-imports": "^2.0.0",
48
47
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
@@ -90,5 +89,8 @@
90
89
  "@types/nodemailer": "^6.4.4",
91
90
  "@types/prompts": "^2.0.14",
92
91
  "@types/webpack-env": "^1.16.2"
93
- }
92
+ },
93
+ "peerDependencies": {
94
+ "5htp-core": "^0.0.4"
95
+ }
94
96
  }
@@ -32,7 +32,7 @@ export const run = () => new Promise<void>(async () => {
32
32
  });
33
33
 
34
34
  // Allow the dev servet to fetch the frameworg node modules
35
- fs.createSymlinkSync( cli.paths.core.root + '/node_modules', cli.paths.app.bin + '/node_modules', 'dir' );
35
+ //fs.createSymlinkSync( cli.paths.core.cli + '/node_modules', cli.paths.app.bin + '/node_modules', 'dir' );
36
36
 
37
37
  multiCompiler.watch({
38
38
 
@@ -51,7 +51,8 @@ export default function createCommonConfig( side: TAppSide, mode: TCompileMode )
51
51
  resolveLoader: {
52
52
  // Recherche des loaders dans framework/node_modules (psinon, webpack cherche dans le projet)
53
53
  modules: [
54
- cli.paths.core.root + '/node_modules'
54
+ cli.paths.core.root + '/node_modules',
55
+ cli.paths.core.cli + '/node_modules',
55
56
  ],
56
57
  mainFields: ['loader', 'main'],
57
58
  },
package/src/index.ts CHANGED
@@ -7,21 +7,18 @@
7
7
  // Npm
8
8
  import { Logger } from "tslog";
9
9
  import cp from 'child_process';
10
- import fs from 'fs-extra';
11
10
 
12
11
  // Libs
13
12
  import Paths from './paths';
14
- import ConfigParser from '5htp-core/src/server/app/config';
15
-
16
- // Types from core
13
+ import ConfigParser from './utils/config';
17
14
 
18
15
  /*----------------------------------
19
16
  - TYPES
20
17
  ----------------------------------*/
21
18
 
22
- type TCliCommand = {
19
+ type TCliCommand = () => Promise<{
23
20
  run: () => Promise<void>
24
- }
21
+ }>
25
22
 
26
23
  export type TAppSide = 'server' | 'client'
27
24
 
@@ -65,9 +62,10 @@ export class CLI {
65
62
  - COMMANDS
66
63
  ----------------------------------*/
67
64
  // Les importations asynchrones permettent d'accéder à l'instance de cli via un import
65
+ // WARN: We load commands asynchonously, so the aliases are applied before the file is imported
68
66
  public commands: { [name: string]: TCliCommand } = {
69
- "dev": require('./commands/dev'),
70
- "build": require('./commands/build'),
67
+ "dev": () => import('./commands/dev'),
68
+ "build": () => import('./commands/build'),
71
69
  }
72
70
 
73
71
  public start() {
@@ -125,8 +123,10 @@ export class CLI {
125
123
  if (this.commands[command] === undefined)
126
124
  throw new Error(`Command ${command} does not exists.`);
127
125
 
126
+ const runner = await this.commands[command]();
127
+
128
128
  // Running
129
- this.commands[command].run().then(() => {
129
+ runner.run().then(() => {
130
130
 
131
131
  console.info(`Command ${command} finished.`);
132
132
 
package/src/paths.ts CHANGED
@@ -46,9 +46,9 @@ export default class Paths {
46
46
  }
47
47
 
48
48
  public core = {
49
+ cli: path.resolve(__dirname, '..'),
49
50
  root: this.coreRoot,
50
51
  src: this.coreRoot + '/src',
51
- realRoot: path.resolve(__dirname, '..'),
52
52
  pages: this.coreRoot + '/src/client/pages',
53
53
  }
54
54
 
@@ -148,7 +148,7 @@ export default class Paths {
148
148
 
149
149
  public applyAliases() {
150
150
 
151
- const aliases = new TsAlias( this.core.root + '/cli' );
151
+ const aliases = new TsAlias( this.core.cli );
152
152
 
153
153
  console.log('Applying Aliases ...', aliases);
154
154
 
@@ -0,0 +1,41 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ /*
6
+ WARNING: This file SHOULDN'T import deps from the project
7
+ Because it's imported by the CLI, which should be independant of the app escept for loading config
8
+ */
9
+
10
+ // Npm
11
+ import fs from 'fs-extra';
12
+ import yaml from 'yaml';
13
+
14
+ /*----------------------------------
15
+ - LOADE
16
+ ----------------------------------*/
17
+ export default class ConfigParser {
18
+
19
+ public constructor(
20
+ public appDir: string,
21
+ public envName?: string
22
+ ) {
23
+
24
+ }
25
+
26
+ private loadYaml( filepath: string ) {
27
+ console.info(`Loading config ${filepath}`);
28
+ const rawConfig = fs.readFileSync(filepath, 'utf-8');
29
+ return yaml.parse(rawConfig);
30
+ }
31
+
32
+ public env() {
33
+ const envFile = this.appDir + '/env' + (this.envName === undefined ? '' : '.' + this.envName) + '.yaml';
34
+ return this.loadYaml( envFile );
35
+ }
36
+
37
+ public identity() {
38
+ const identityFile = this.appDir + '/identity.yaml';
39
+ return this.loadYaml( identityFile );
40
+ }
41
+ }