Skip to content

Commit

Permalink
Merge pull request #256 from rdkcentral/dev
Browse files Browse the repository at this point in the history
Release 2.14.0
  • Loading branch information
michielvandergeest authored Apr 8, 2024
2 parents 240621c + 33c4204 commit 365efe3
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
],
"eslint.alwaysShowStatus": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v2.14.0

*03 apr 2024*

- Added support for providing a custom rollup configuration ([#254](https://github.com/rdkcentral/Lightning-CLI/issues/254))
- Added support for providing a custom esbuild configuration ([#255](https://github.com/rdkcentral/Lightning-CLI/issues/255))


## v2.13.0

*26 oct 2023*
Expand Down
23 changes: 23 additions & 0 deletions docs/commands/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,26 @@ lng build --esbuild-bundler-options banner:js=//javascriptcomment banner:css=/*c
We can also specify the bundler options in the `.env` file and through commandline as `env variable`. Here the priority will be
`.env < commandline env variable < commandline options`

### Rollup Custom Config

If you prefer the rollup bundler to use the custom rollup config(user specified), you need to set the env Variable LNG_CUSTOM_ROLLUP to true. Under the hood the custom config will be merged with the default config options to generate the bundle.

Also make sure the following :

| S.No | Info | Description|
| -------- | -------- |----------
| 1 | Config Location | Project Home |
| 2 | Config File Name | `rollup.es6.config.js`(for es6)|
| | | `rollup.es5.config.js`(for es5) |
| | | |

Example custom Config file content:

```javascript
module.exports = {
input: 'src/index.js',
output: {
format: 'iife',
sourcemap: false,
},
}
2 changes: 2 additions & 0 deletions docs/environmentvariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ You can use the following environment variables to customize the behavior of the
| `LNG_BUNDLER_ESBUILD_OPTIONS` | false | Specifies the specific bundler options required for esbuild
| `LNG_BUNDLER_ROLLUP_OPTIONS` | false | Specifies the specific bundler options required for rollup
| `LNG_BUILD_MINIFY` | false | When set to `true` minifies the bundle
| `LNG_CUSTOM_ROLLUP` | false | When set to `true`, uses the custom rollup config file(rollup.{env}.config.js) located in the project home directory
| `LNG_CUSTOM_ESBUILD` | false | When set to `true`, uses the custom esbuild config file located(esbuild.{env}.config.js) in the project home directory

#### `LNG_SETTINGS_ENV`
Specifies which environment to be used. User need to have `settings.{env}.json` file in the Project home folder with different settings. This will build/dist the application with `settings.{env}.json`.
Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Michiel van der Geest <m.van.der.geest@metrological.com>",
"license": "Apache-2",
"name": "@lightningjs/cli",
"version": "2.13.0",
"version": "2.14.0",
"description": "Lightning-CLI: Command Line Interface tool for a seamless Lightning App Development flow",
"bin": {
"lightning": "./bin/index.js",
Expand Down Expand Up @@ -43,6 +43,7 @@
"commander": "^10.0.0 ",
"concat": "^1.0.3",
"core-js": "^3.6.5",
"deepmerge": "^4.3.1",
"didyoumean2": "^4.1.0",
"dotenv": "^16.0.3",
"esbuild": "^0.19.3",
Expand Down
14 changes: 13 additions & 1 deletion src/configs/esbuild.es5.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const babelPluginTransFormSpread = require('@babel/plugin-transform-spread')
const babelPluginTransFormParameters = require('@babel/plugin-transform-parameters')
const babelPluginClassProperties = require('@babel/plugin-proposal-class-properties')
const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import')
const deepMerge = require('deepmerge')

let customConfig

if (process.env.LNG_CUSTOM_ESBUILD === 'true') {
customConfig = require(path.join(process.cwd(), 'esbuild.es5.config'))
}

module.exports = (folder, globalName) => {
// Load .env config every time build is triggered
Expand All @@ -43,7 +50,7 @@ module.exports = (folder, globalName) => {
defined['process.env.NODE_ENV'] = `"${process.env.NODE_ENV}"`
const minify = process.env.LNG_BUILD_MINIFY === 'true' || process.env.NODE_ENV === 'production'

return {
let defaultConfig = {
plugins: [
alias([
{ find: '@', filter: /@\//, replace: path.resolve(process.cwd(), 'src/') },
Expand Down Expand Up @@ -117,4 +124,9 @@ module.exports = (folder, globalName) => {
].join(os.EOL),
},
}
if ('entryPoints' in customConfig) {
delete defaultConfig.entryPoints
}
const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
return finalConfig
}
16 changes: 14 additions & 2 deletions src/configs/esbuild.es6.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const babelPresetEnv = require('@babel/preset-env')
const path = require('path')
const babelPluginClassProperties = require('@babel/plugin-proposal-class-properties')
const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import')
const deepMerge = require('deepmerge')

let customConfig

if (process.env.LNG_CUSTOM_ESBUILD === 'true') {
customConfig = require(path.join(process.cwd(), 'esbuild.es6.config'))
}

module.exports = (folder, globalName) => {
//Load .env config every time build is triggered
Expand All @@ -40,8 +47,7 @@ module.exports = (folder, globalName) => {
}, {})
defined['process.env.NODE_ENV'] = `"${process.env.NODE_ENV}"`
const minify = process.env.LNG_BUILD_MINIFY === 'true' || process.env.NODE_ENV === 'production'

return {
let defaultConfig = {
plugins: [
alias([
{
Expand Down Expand Up @@ -107,4 +113,10 @@ module.exports = (folder, globalName) => {
].join(os.EOL),
},
}

if ('entryPoints' in customConfig) {
delete defaultConfig.entryPoints
}
const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
return finalConfig
}
12 changes: 11 additions & 1 deletion src/configs/rollup.es5.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ const minify = require('rollup-plugin-terser').terser
const license = require('rollup-plugin-license')
const os = require('os')
const extensions = ['.js', '.ts', '.mjs']
const deepMerge = require('deepmerge')

module.exports = {
let customConfig

if (process.env.LNG_CUSTOM_ROLLUP === 'true') {
customConfig = require(path.join(process.cwd(), 'rollup.es5.config'))
}

const defaultConfig = {
onwarn(warning, warn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
warn(warning)
Expand Down Expand Up @@ -129,3 +136,6 @@ module.exports = {
: process.env.LNG_BUILD_SOURCEMAP,
},
}

const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
module.exports = finalConfig
12 changes: 11 additions & 1 deletion src/configs/rollup.es6.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ const minify = require('rollup-plugin-terser').terser
const license = require('rollup-plugin-license')
const os = require('os')
const extensions = ['.js', '.ts']
const deepMerge = require('deepmerge')

module.exports = {
let customConfig

if (process.env.LNG_CUSTOM_ROLLUP === 'true') {
customConfig = require(path.join(process.cwd(), 'rollup.es6.config'))
}

const defaultConfig = {
onwarn(warning, warn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
warn(warning)
Expand Down Expand Up @@ -119,3 +126,6 @@ module.exports = {
: process.env.LNG_BUILD_SOURCEMAP,
},
}

const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
module.exports = finalConfig
16 changes: 13 additions & 3 deletions src/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,25 @@ const bundleAppRollup = (folder, metadata, type, options) => {
const args = [
'-c',
path.join(__dirname, `../configs/rollup.${type}.config.js`),
'--input',
path.join(process.cwd(), enterFile),
'--file',
path.join(folder, type === 'es6' ? 'appBundle.js' : 'appBundle.es5.js'),
'--name',
makeSafeAppId(metadata),
'--preserveSymlinks',
]

const rollupConfig = require(path.join(__dirname, `../configs/rollup.${type}.config.js`))
// Check if 'input' property is not present in the rollupConfig object
if (!('input' in rollupConfig)) {
//if 'input' is not present, push the input option and location of source file to the args
args.push('--input', path.join(process.cwd(), enterFile))
}

// Check if 'preserveSymlinks' property is not present in the rollupConfig object
if (!('preserveSymlinks' in rollupConfig)) {
// If 'preserveSymlinks' property is not present, push preserveSymLinks to the args
args.push('--preserveSymlinks')
}

if (options.sourcemaps === false) args.push('--no-sourcemap')

const levelsDown = isLocallyInstalled()
Expand Down

0 comments on commit 365efe3

Please sign in to comment.