tusharmath / node-config-ts

A simple node configuration manager
61 stars 31 forks source link

Question: what is the right way to package the config into dist folder #61

Closed agorina closed 4 years ago

agorina commented 4 years ago

I am new to the node/ts development, and I am trying to set up a project that run on Azure app server. It expects all the distribution files packaged in the dist folder. Here is my local set up and it all works well, but it does not when it gets published to the Azure because config folder is not picked up:

- config
- dist
    |-...(everything from src)
- src

My tsconfig:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "allowJs": true,
    "sourceMap": true,
    "outDir": "dist",
    "rootDir": "src",
    "esModuleInterop": true,
    "declaration": true,
    "noEmitOnError": true,
    "importHelpers": true,
    "strict": true,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src/**/*",
    "config/**/*",
    "node_modules/node-config-ts/global.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

and package.json

....
  "scripts": {
    "postinstall": "node-config-ts",
    "build": "tsc",
    "local": "tsc-watch --onSuccess \"node -r dotenv/config ./dist/app.js\"",
    "test": "source ~/.az-creds; node -r dotenv/config ./dist/app.js",
    "start": "node ./dist/app.js"
  },

...

Any help is very much appreciated.

agorina commented 4 years ago

I found the solution. Thank you.

tusharmath commented 4 years ago

Great!

cosminonea commented 3 years ago

@agorina what was the solution?

agorina commented 3 years ago

It was a while ago, so I do not remember what exactly solved it, but here is our new set up:

Project folder structure:

- build
       Lsrc
- config
- src
``

tsconfig.json

{ "compilerOptions": { "target": "ES2019", "module": "commonjs", "resolveJsonModule": true, "allowJs": true, "sourceMap": true, "outDir": "build", "esModuleInterop": true, "experimentalDecorators": true, "declaration": true, "moduleResolution": "node", "noEmitOnError": true, "importHelpers": true, "noImplicitAny": false, "strict": true, "strictNullChecks": true, "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true, "composite": true }, "include": [ "src/*/", "test/*/", "config/Config.d.ts" ], "exclude": [ "node_modules" ] }

package.json

"scripts": { "config": "node-config-ts", "copy:sql": "cpy '*/.sql.yaml' '../build/src/' --cwd=src --parents", "lint": "npx eslint .", "coverage": "nyc --reporter=text npm test", "coverage:ci": "nyc --temp-dir=./coverage-report/raw --reporter=cobertura --report-dir=./coverage-report npm run test:ci", "test": "mocha --recursive --require ts-node/register --require dotenv/config --colors test/*/.ts --dbConfig.database=faro_db_test --auth.enable=false --auth.mockUser.id=123 --auth.mockUser.tenant=sample_tenant", "test:ci": "mocha --timeout 12000 --recursive --require ts-node/register --require dotenv/config --reporter mocha-junit-reporter --reporter-options mochaFile=./test-output/test-results.xml", "start": "node --max-http-header-size=16000 ./build/src/server.js", "start:dev": "tsc-watch --onSuccess \"node --max-http-header-size=16000 --require dotenv/config ./build/src/server.js\"", "build": "tsc && npm run copy:sql && rm -rf ./build/test", "release:patch": "npm version patch -m \"Upgrade to %s during CI [skip ci]\" --force " },

...

"files": [
"/build",
"/config"

],



And it all works now. Hope this helps.