nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

feat(options): use the 'nsconfig.json' file to set tns options

Open bgrand-ch opened this issue 5 years ago • 4 comments

PR Checklist

  • [x] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages.
  • [ ] There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
  • [x] You have signed the CLA.
  • [x] All existing tests are passing: https://github.com/NativeScript/nativescript-cli/blob/master/CONTRIBUTING.md#contribute-to-the-code-base
  • [ ] Tests for the changes are included.

What is the current behavior?

Tns options are to be written each time to build, run, deploy, debug and test an Android and iOS application.

What is the new behavior?

In addition to the current behavior, all tns options can be defined in the nsconfig.json file.

In the nsconfig.json file, you need to add the tnsOptions key with android and ios subkeys.

Option names are unchanged, they are those of the documentation of the CLI.

Example

nsconfig.json

{
    "tnsOptions": {
        "android": {
            "copyTo": "./_build/android",
            "keyStorePath": "./keys/android.keystore",
            "keyStoreAlias": "my_ns_project",
            "release": true,
            "aab": true,
            "env": {
                "uglify": true
            }
        }
    }
}

CLI

tns build android --nsconfig --key-store-password "my_pwd" --key-store-alias-password "my_pwd"

(see the original idea)

Fixes/Implements/Closes

Fixes

bgrand-ch avatar Apr 14 '20 23:04 bgrand-ch

@DimitarTachev @rosen-vladimirov Hello, I am at your disposal for any changes. Have a nice day 😊

bgrand-ch avatar Apr 28 '20 14:04 bgrand-ch

Hi @elvticc - I have wanted something like this for a long time! With the recent introduction of nativescript.config.ts I think we can go a step further, and allow setting many of CLI configuration there, including the options.

import { NativeScriptConfig } from '@nativescript/core'

export default {
  id: 'org.nativescript.app',
  // ...
  cli: {
    packageManager: 'yarn',
    android: {
      copyTo: './_build/android'
    }
  },
} as NativeScriptConfig

The syntax/api is subject to change, merely just a quick example of what I imagined.

rigor789 avatar Sep 08 '20 18:09 rigor789

Hi @rigor789, I will update this to include the new nativescript.config.ts file and preserve backward compatibility with the nsconfig.json file. I will try with all the options 👍 I'll be back soon.

bgrand-ch avatar Sep 09 '20 06:09 bgrand-ch

@elvticc the CLI should automatically fall back to nsconfig when there is no new config found. The logic has been extracted to project-config-service which you can inject wherever and read values, or the whole config.

I think in options.ts we can inject/resolve the config service:

const projectConfig = injector.resolve('projectConfigService')
// add guards if it's not set/found etc.
const cliOptions = projectConfig.getValue('cli') // I think this should work, and return the object

// do any processing of the options (can probably be enclosed in a function within `options.ts`)
// just an example, doesn't have to be called this - or even called this way
this.argv = this.processConfigOptions(cliOptions)

// probably better to just have a single line that calls a function that 
// does all the config fetching, manipulation and setting argv

Other than that, I think we want these to be used by default - and provide a flag to opt-out? --skip-config (don't like that name, but can't think of anything at the moment)

If you want to to work on this together, feel free to ping me - I'm usually available

rigor789 avatar Sep 09 '20 08:09 rigor789