diff --git a/CHANGELOG.md b/CHANGELOG.md index c440abf6..5d69988d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v2.11.0 + +*28 apr 2023* + +- Removed license texts from fixtures, so new Apps created with the CLI don't come with unnecessary licenses anymore ([#226](https://github.com/rdkcentral/Lightning-CLI/issues/226)) +- Fixed build issue related to rollup path when using NPX. Solves issue for Metrological CLI. ([#222](https://github.com/rdkcentral/Lightning-CLI/issues/222)) +- Fixed issue where sourcemap files were not generated when using esbuild ([#228](https://github.com/rdkcentral/Lightning-CLI/issues/228)) +- Added support for CORS in `lng serve` via a new environment variable (`LNG_SERVE_CORS`) + ## v2.10.0 *15 feb 2023* diff --git a/docs/environmentvariables.md b/docs/environmentvariables.md index def55de7..873f3209 100644 --- a/docs/environmentvariables.md +++ b/docs/environmentvariables.md @@ -53,6 +53,7 @@ You can use the following environment variables to customize the behavior of the | `LNG_LIVE_RELOAD` | false | Instructs your browser to reload the location when a new app bundle is created (using `lng dev`). When the watcher resolves, `document.location.reload()` is called in the browser (tab) that serves your app. Live reload communication is driven by WebSockets. Possible value: `true`, `false`. | | `LNG_LIVE_RELOAD_HOST` | localhost | Specifies the Websocket host your application will attempt to connect to listen for livereload events. Possible values: ip or host. | | `LNG_LIVE_RELOAD_PORT` | 8991 | Specifies the port Websocket is listening on. Possible values: Any numeric value. | +| `LNG_SERVE_CORS` | false | When set to `true`, CORS is enabled by allowing all origins (Access-Control-Allow-Origin: *) and default headers (Origin, X-Requested-With, Content-Type, Accept, Range). To allow additional headers, provide comma-separated header names as the value (e.g. Authorization, X-Debug). This both enables CORS and appends the provided headers to Access-Control-Allow-Headers #### `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`. diff --git a/fixtures/js/lightning-app/src/App.js b/fixtures/js/lightning-app/src/App.js index da0ef4a9..983185cf 100644 --- a/fixtures/js/lightning-app/src/App.js +++ b/fixtures/js/lightning-app/src/App.js @@ -1,22 +1,3 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2020 Metrological - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - import { Lightning, Utils } from '@lightningjs/sdk' export default class App extends Lightning.Component { diff --git a/fixtures/ts/lightning-app/src/App.ts b/fixtures/ts/lightning-app/src/App.ts index 691fecd3..3d769e3c 100644 --- a/fixtures/ts/lightning-app/src/App.ts +++ b/fixtures/ts/lightning-app/src/App.ts @@ -1,21 +1,3 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 Metrological - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ import { Lightning, Utils } from '@lightningjs/sdk' interface AppTemplateSpec extends Lightning.Component.TemplateSpec { diff --git a/package-lock.json b/package-lock.json index bc22d56a..3bb4d530 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lightningjs/cli", - "version": "2.10.0", + "version": "2.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@lightningjs/cli", - "version": "2.10.0", + "version": "2.11.0", "license": "Apache-2", "dependencies": { "@babel/core": "^7.11.6", diff --git a/package.json b/package.json index b7025dc1..fbe2151c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Michiel van der Geest ", "license": "Apache-2", "name": "@lightningjs/cli", - "version": "2.10.0", + "version": "2.11.0", "description": "Lightning-CLI: Command Line Interface tool for a seamless Lightning App Development flow", "bin": { "lightning": "./bin/index.js", diff --git a/src/actions/serve.js b/src/actions/serve.js index 0d6a110c..b52343e9 100644 --- a/src/actions/serve.js +++ b/src/actions/serve.js @@ -36,6 +36,8 @@ module.exports = () => { process.env.LNG_SERVE_CACHE_TIME ? '-c' + process.env.LNG_SERVE_CACHE_TIME : '-c-1', process.env.LNG_SERVE_PORT ? '-p' + process.env.LNG_SERVE_PORT : false, process.env.LNG_SERVE_PROXY ? '-P' + process.env.LNG_SERVE_PROXY : false, + process.env.LNG_SERVE_CORS && process.env.LNG_SERVE_CORS !== 'false' ? process.env.LNG_SERVE_CORS === 'true' + ? '--cors' : '--cors='+ process.env.LNG_SERVE_CORS : '', ].filter(val => val) const levelsDown = isLocallyInstalled() diff --git a/src/configs/esbuild.es5.config.js b/src/configs/esbuild.es5.config.js index c6ac0df1..e51c6e6d 100644 --- a/src/configs/esbuild.es5.config.js +++ b/src/configs/esbuild.es5.config.js @@ -31,11 +31,13 @@ const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import') module.exports = (folder, globalName) => { const sourcemap = - process.env.LNG_BUILD_SOURCEMAP === 'true' - ? true + process.env.NODE_ENV === 'production' + ? 'external' : process.env.LNG_BUILD_SOURCEMAP === 'inline' ? 'inline' - : false + : process.env.LNG_BUILD_SOURCEMAP === 'false' + ? '' + : 'external' // Load .env config every time build is triggered const appVars = { diff --git a/src/configs/esbuild.es6.config.js b/src/configs/esbuild.es6.config.js index 7d100743..99b21375 100644 --- a/src/configs/esbuild.es6.config.js +++ b/src/configs/esbuild.es6.config.js @@ -29,11 +29,13 @@ const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import') module.exports = (folder, globalName) => { const sourcemap = - process.env.LNG_BUILD_SOURCEMAP === 'true' - ? true + process.env.NODE_ENV === 'production' + ? 'external' : process.env.LNG_BUILD_SOURCEMAP === 'inline' ? 'inline' - : false + : process.env.LNG_BUILD_SOURCEMAP === 'false' + ? '' + : 'external' //Load .env config every time build is triggered const appVars = { diff --git a/src/configs/rollup.es5.config.js b/src/configs/rollup.es5.config.js index 2eab6ecf..a16ffa84 100644 --- a/src/configs/rollup.es5.config.js +++ b/src/configs/rollup.es5.config.js @@ -116,6 +116,13 @@ module.exports = { output: { format: 'iife', inlineDynamicImports: true, - sourcemap: true, + sourcemap: + process.env.NODE_ENV === 'production' + ? true + : process.env.LNG_BUILD_SOURCEMAP === undefined + ? true + : process.env.LNG_BUILD_SOURCEMAP === 'false' + ? false + : process.env.LNG_BUILD_SOURCEMAP, }, } diff --git a/src/helpers/build.js b/src/helpers/build.js index a9ca3170..35db2be0 100644 --- a/src/helpers/build.js +++ b/src/helpers/build.js @@ -40,6 +40,18 @@ const findFile = (parent, filePath, depthCount = 0) => { return findFile(path.join(parent, '..'), filePath, ++depthCount) } +const findBinary = binary => { + const binaryPath = path.join(__dirname, '../..', `node_modules/.bin/${binary}`) + const npxPath = path.join(__dirname, '../../../..', `.bin/${binary}`) + return fs.existsSync(binaryPath) + ? binaryPath + : fs.existsSync(npxPath) + ? npxPath + : (() => { + throw new Error(`Required binary (${binary}) not found`) + })() +} + const removeFolder = folder => { spinner.start('Removing "' + folder.split('/').pop() + '" folder') shell.rm('-rf', folder) @@ -212,7 +224,7 @@ const bundleAppRollup = (folder, metadata, type, options) => { const levelsDown = isLocallyInstalled() ? findFile(process.cwd(), 'node_modules/.bin/rollup') - : path.join(__dirname, '../..', 'node_modules/.bin/rollup') + : findBinary('rollup') process.env.LNG_BUILD_FAIL_ON_WARNINGS === 'true' ? args.push('--failAfterWarnings') : '' return execa(levelsDown, args) .then(() => {