From cfa6b6670276e8018156b7eca78168ef4699901c Mon Sep 17 00:00:00 2001 From: Ben Moroze Date: Fri, 15 Jan 2021 10:44:20 -0500 Subject: [PATCH] Release 10.0.0 --- CONTRIBUTING.md | 2 +- LICENSE | 2 +- README.md | 6 +- RELEASENOTES.md | 2 +- config/eslintcustom.js | 2 +- hooks/jetAfterPrepare.js | 2 +- hooks/jetInjector.js | 2 +- lib/add.js | 2 +- lib/addpcss.js | 3 +- lib/addpwa.js | 82 +++++++++++++++ lib/addsass.js | 2 +- lib/addtypescript.js | 4 +- lib/build.js | 2 +- lib/buildCommon.js | 60 +++++++---- lib/buildCommon/compileTypescript.js | 33 +++++- lib/buildCommon/copyLocalComponent.js | 2 +- lib/buildCommon/generateComponentsCache.js | 2 +- lib/buildCommon/minifyComponent.js | 117 +++++++++++---------- lib/buildCommon/optimizeComponent.js | 4 +- lib/buildComponent.js | 2 +- lib/buildHybrid.js | 4 +- lib/buildWeb.js | 4 +- lib/clean.js | 2 +- lib/config.js | 3 +- lib/configure.js | 2 +- lib/constants.js | 7 +- lib/create.js | 2 +- lib/defaultconfig.js | 3 +- lib/hookRunner.js | 2 +- lib/indexHtmlInjector.js | 59 ++++++----- lib/injectorUtil.js | 2 +- lib/list.js | 2 +- lib/main.js | 30 ------ lib/mainJsInjector.js | 2 +- lib/npmCopy.js | 36 ++----- lib/package.js | 2 +- lib/parser/dom-parser.js | 2 +- lib/parser/dom.js | 2 +- lib/parser/sax.js | 2 +- lib/pcss.js | 62 ++++------- lib/publish.js | 2 +- lib/remove.js | 2 +- lib/rjsConfigGenerator.js | 14 ++- lib/sass.js | 2 +- lib/scopes/component.js | 100 ++++++++++++++---- lib/scopes/exchange.js | 2 +- lib/scopes/pack.js | 7 +- lib/search.js | 2 +- lib/serve.js | 5 +- lib/serve/connect.js | 17 ++- lib/serve/watch.js | 2 +- lib/serveHybrid.js | 2 +- lib/serveHybridFileChangeHandler.js | 2 +- lib/serveWeb.js | 2 +- lib/serveWebFileChangeHandler.js | 2 +- lib/strip.js | 14 ++- lib/svg.js | 2 +- lib/templates/pack/component.json | 2 +- lib/templates/serviceWorkers/manifest.json | 6 ++ lib/templates/serviceWorkers/sw.txt | 31 ++++++ lib/templates/serviceWorkers/swInit.txt | 11 ++ lib/util.js | 15 +-- lib/utils.exchange.js | 2 +- lib/validations.js | 32 ++++-- oraclejet-tooling.js | 3 +- package.json | 12 +-- test/config.js | 34 +++--- test/hook.js | 14 +-- test/util.js | 30 +++--- 69 files changed, 565 insertions(+), 369 deletions(-) create mode 100644 lib/addpwa.js delete mode 100644 lib/main.js create mode 100644 lib/templates/serviceWorkers/manifest.json create mode 100644 lib/templates/serviceWorkers/sw.txt create mode 100644 lib/templates/serviceWorkers/swInit.txt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7fec753..05a8dc2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to oraclejet-tooling -*Copyright (c) 2014, 2020 Oracle and/or its affiliates +*Copyright (c) 2014, 2021 Oracle and/or its affiliates Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/* diff --git a/LICENSE b/LICENSE index 8329968..df84b66 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ # oraclejet-tooling -Copyright (c) 2020 Oracle and/or its affiliates. +Copyright (c) 2021 Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/README.md b/README.md index 42952c8..0814d7b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @oracle/oraclejet-tooling 9.2.0 +# @oracle/oraclejet-tooling 10.0.0 ## About the tooling API This tooling API contains methods to build and serve Oracle JET web and hybrid mobile apps. It is intended to be used with task running tools such as grunt or gulp. The APIs can also be invoked directly. @@ -6,7 +6,7 @@ This tooling API contains methods to build and serve Oracle JET web and hybrid m This is an open source project maintained by Oracle Corp. ## Installation -This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet920&id=homepage). +This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet1000&id=homepage). ## [Contributing](https://github.com/oracle/oraclejet-tooling/blob/master/CONTRIBUTING.md) Oracle JET is an open source project. Pull Requests are currently not being accepted. See @@ -14,5 +14,5 @@ Oracle JET is an open source project. Pull Requests are currently not being acc for details. ## [License](https://github.com/oracle/oraclejet-tooling/blob/master/LICENSE) -Copyright (c) 2020 Oracle and/or its affiliates and released under the +Copyright (c) 2021 Oracle and/or its affiliates and released under the [Universal Permissive License (UPL)](https://oss.oracle.com/licenses/upl/), Version 1.0 \ No newline at end of file diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 516ab13..7941fcf 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,6 +1,6 @@ ## Release Notes for oraclejet-tooling ## -### 9.2.0 +### 10.0.0 * No changes ### 5.2.0 diff --git a/config/eslintcustom.js b/config/eslintcustom.js index 538cfc3..ec4c194 100644 --- a/config/eslintcustom.js +++ b/config/eslintcustom.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/hooks/jetAfterPrepare.js b/hooks/jetAfterPrepare.js index 2e9e0bf..e2e2cdf 100644 --- a/hooks/jetAfterPrepare.js +++ b/hooks/jetAfterPrepare.js @@ -1,6 +1,6 @@ #!/usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/hooks/jetInjector.js b/hooks/jetInjector.js index 5d83a34..44d8d76 100644 --- a/hooks/jetInjector.js +++ b/hooks/jetInjector.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/add.js b/lib/add.js index 8d80f19..828587f 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/addpcss.js b/lib/addpcss.js index 0f7da71..7c5e75b 100644 --- a/lib/addpcss.js +++ b/lib/addpcss.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -27,7 +27,6 @@ module.exports = function () { return util.spawn('npm', ['install', `node-sass@${sassVer}`, - 'postcss-custom-properties@6.2.0', 'postcss-calc@6.0.1', 'autoprefixer@9.1.5', '--save-dev=true']); diff --git a/lib/addpwa.js b/lib/addpwa.js new file mode 100644 index 0000000..214def9 --- /dev/null +++ b/lib/addpwa.js @@ -0,0 +1,82 @@ +#! /usr/bin/env node +/** + Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ + +'use strict'; + +/** + * ## Dependencies + */ + +const fs = require('fs-extra'); +const path = require('path'); +const CONSTANTS = require('./constants'); +/** + * #addpwa + * + * @public + * @returns {Promise} + */ + +module.exports = function () { + return new Promise((resolve) => { + // eslint-disable-next-line global-require + const appName = path.basename(process.cwd()); + const appNameRegex = new RegExp('@AppName@', 'g'); + const pathToApp = path.join('src'); + const pathToIndexHtml = path.join(pathToApp, 'index.html'); + const pathToServiceWorkerTemplates = CONSTANTS.PATH_TO_PWA_TEMPLATES; + // 1. read index.html + const indexHtmlString = fs.readFileSync( + pathToIndexHtml, + { encoding: 'utf-8' } + ); + // 2. read sw.txt, replace app name token, write to app as js file + const swJsString = fs.readFileSync( + path.join(pathToServiceWorkerTemplates, 'sw.txt'), + { encoding: 'utf-8' } + ); + const pathToAppSw = path.join(pathToApp, 'sw.js'); + if (fs.pathExistsSync(pathToAppSw)) { + fs.renameSync(pathToAppSw, path.join(pathToApp, 'sw_old.js')); + } + fs.outputFileSync( + pathToAppSw, + swJsString.replace(appNameRegex, appName) + ); + // 3. read manifest.json, replace app name token, write to app + const manifestJsonString = fs.readFileSync( + path.join(pathToServiceWorkerTemplates, 'manifest.json'), + { encoding: 'utf-8' } + ); + const pathToAppManifest = path.join(pathToApp, 'manifest.json'); + if (fs.pathExistsSync(pathToAppManifest)) { + fs.renameSync(pathToAppManifest, path.join(pathToApp, 'manifest_old.json')); + } + fs.outputFileSync( + path.join(pathToApp, 'manifest.json'), + manifestJsonString.replace(appNameRegex, appName) + ); + // 4. copy swInit.txt and add it to end of body tag index.html, add + // to end of header tag in index.html and update + const swInitString = fs.readFileSync( + path.join(pathToServiceWorkerTemplates, 'swInit.txt'), + { encoding: 'utf-8' } + ); + fs.outputFileSync( + pathToIndexHtml, + indexHtmlString.replace( + new RegExp('', 'g'), + '\n' + ).replace( + new RegExp('', 'g'), + `${swInitString.replace(appNameRegex, appName)}\n` + ) + ); + resolve(); + }); +}; diff --git a/lib/addsass.js b/lib/addsass.js index 60a1730..bc9afa9 100644 --- a/lib/addsass.js +++ b/lib/addsass.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/addtypescript.js b/lib/addtypescript.js index 3603ed5..afc118a 100644 --- a/lib/addtypescript.js +++ b/lib/addtypescript.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -34,7 +34,7 @@ const path = require('path'); function installTypescipt() { return new Promise((resolve) => { util.log('Installing Typescript'); - exec(`npm install typescript@${CONSTANTS.TYPESCRIPT_VERSION} --save-dev=true`, { + exec(`npm install typescript@${CONSTANTS.TYPESCRIPT_VERSION} --save-dev --save-exact`, { env: { ...process.env, // speed up npm install when on vpn diff --git a/lib/build.js b/lib/build.js index 0c4c323..019b266 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/buildCommon.js b/lib/buildCommon.js index fc634fa..ec615b2 100644 --- a/lib/buildCommon.js +++ b/lib/buildCommon.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -13,6 +13,7 @@ const requirejs = require('requirejs'); const util = require('./util'); const config = require('./config'); const npmCopy = require('./npmCopy'); +const injectorUtil = require('./injectorUtil'); const mainJsInjector = require('./mainJsInjector'); const indexHtmlInjector = require('./indexHtmlInjector'); const svg = require('./svg'); @@ -105,15 +106,18 @@ function _copyDefaultResourcesToStaging(theme, stagingPath, themeName) { const srcBase = `${config('paths').staging.themes}/${themeName}`; const destBase = util.destPath(path.join(stagingPath, config('paths').src.styles, themeName, util.getJETVersion())); - const commonSrc = path.join(srcBase, CONSTANTS.COMMON_THEME_DIRECTORY); const defaultFontsSrc = path.join(srcBase, theme.platform, 'fonts'); const defaultImagesSrc = path.join(srcBase, theme.platform, 'images'); - const commonDest = path.join(destBase, CONSTANTS.COMMON_THEME_DIRECTORY); const defaultFontsDest = path.join(destBase, theme.platform, 'fonts'); const defaultImagesDest = path.join(destBase, theme.platform, 'images'); - fs.copySync(commonSrc, commonDest); + if (config('defaultTheme') === CONSTANTS.DEFAULT_THEME && themeName !== CONSTANTS.DEFAULT_PCSS_THEME) { + const commonSrc = path.join(srcBase, CONSTANTS.COMMON_THEME_DIRECTORY); + const commonDest = path.join(destBase, CONSTANTS.COMMON_THEME_DIRECTORY); + fs.copySync(commonSrc, commonDest); + } + fs.copySync(defaultFontsSrc, defaultFontsDest); fs.copySync(defaultImagesSrc, defaultImagesDest); } @@ -167,7 +171,7 @@ function _copyFilesExcludeScss(srcBase, destBase) { }); } } catch (err) { - util.log(err); + util.log.error(err); } } @@ -221,7 +225,7 @@ function _copyThemesToStaging(context) { const rwood = Object.assign({}, { name: 'redwood', platform: 'web', compile: false, version: util.getJETVersion() }); - if (config('defaultTheme') === CONSTANTS.DEFAULT_PCSS_THEME) { + if (opts.theme.cssGeneratedType === 'add-on' || config('defaultTheme') === CONSTANTS.DEFAULT_PCSS_THEME) { const rwsrc = _getThemeSrcPath(rwood, ext, livereload); const rwdest = _getThemeDestPath(rwood, stgPath, ext, livereload, platform, opts.destination); fs.copySync(rwsrc, rwdest); @@ -232,7 +236,7 @@ function _copyThemesToStaging(context) { if ((theme.name !== CONSTANTS.DEFAULT_THEME || theme.name !== CONSTANTS.DEFAULT_PCSS_THEME) && !livereload) { _copySrcResourcesToThemes(theme); - if (config('defaultTheme') === CONSTANTS.DEFAULT_PCSS_THEME) { + if (opts.theme.cssGeneratedType === 'add-on' || config('defaultTheme') === CONSTANTS.DEFAULT_PCSS_THEME) { _copySrcResourcesToThemes(rwood); } if (!util.getInstalledCssPackage()) { @@ -291,6 +295,7 @@ function _requireJsInvoker(context) { resolve(context); }, (err) => { util.log(err); + util.log.error(err); reject(err); }); }); @@ -314,6 +319,7 @@ function _requireJsInvokerEs5(context) { }, (err) => { context.opts.isRequireJsEs5 = false; // eslint-disable-line no-param-reassign util.log(err); + util.log.error(err); reject(err); }); }); @@ -579,11 +585,6 @@ module.exports = { }, css: function _compileCss(context) { - const theme = (context.opts.theme) ? context.opts.theme.name : config('defaultTheme'); - const csstype = (context.opts.defaultCssvars) ? context.opts.defaultCssvars : config('defaultCssvars'); - const cssVarsDestPath = path.resolve(config('paths').src.common, 'themes', theme, 'web', `_${theme}.cssvars.settings.scss`); - const pcssTheme = fs.existsSync(util.destPath(cssVarsDestPath)); - if ((context.opts.theme.compile === false && context.opts.sassCompile === false) || context.opts.nosass) { util.log('SCSS Compilation skipped...'); @@ -611,11 +612,6 @@ module.exports = { } if (!util.getInstalledCssPackage()) { - if (!pcssTheme || theme === CONSTANTS.DEFAULT_THEME) { - if (csstype === 'enabled' && theme !== CONSTANTS.DEFAULT_PCSS_THEME) { - util.log.error('Alta theme cannot have defaultCssvars:enabled in oraclejetconfig.json, enable supported only for pcss themes.'); - } - } util.log('Compiling sass...'); return new Promise((resolve, reject) => { if (context.opts.sassCompile === false && svg !== true) { @@ -658,14 +654,32 @@ module.exports = { }); }, - // Copy the standard es5-deciding main.js file for release builds (to choose the proper bundle) - copyMainJs: function _copyMainJs(context) { - util.log('Copying main.js'); + // Modify the standard es5-deciding main.js file for release builds (to choose the proper bundle) + modifyMainJs: function _copyMainJs(context) { + util.log('Modifying main.js'); const dest = _getName(context.opts.stagingPath, 'main.js'); + let mainJs = util.readFileSync(dest); + + const injectConfig = context.opts.injectPaths; + const startTag = injectConfig.startTag; + const endTag = injectConfig.endTag; + const pattern = injectorUtil.getInjectorTagsRegExp(startTag, endTag); + const lineEnding = /\r\n/.test(String(mainJs)) ? '\r\n' : '\n'; + + // actual injection + const emptyPaths = '{}'; + mainJs = mainJs.replace(pattern, () => + startTag + lineEnding + emptyPaths + lineEnding + endTag + ); + + // Need to replace the require([]) line with just one that refers to bundles + const requirePattern = /}\s*\(\s*\)\s*\)\s*;[^]*require\s*\(\s*\[[^]+\][^]+\)/gi; + const newRequireCode = "var bundle = 'bundle' + (_ojNeedsES5 ? '_es5' : '');\nrequire([bundle], function () {});}());"; + mainJs = mainJs.replace(requirePattern, newRequireCode); return new Promise((resolve) => { - fs.copySync(path.resolve(__dirname, 'main.js'), dest, { overwrite: true }); - util.log('Copy main.js finished'); + fs.outputFileSync(dest, mainJs); + util.log('Modify main.js finished'); resolve(context); }); }, @@ -922,6 +936,7 @@ module.exports = { }) .catch((err) => { util.log(err); + util.log.error(err); reject2(err); }); } @@ -930,6 +945,7 @@ module.exports = { resolve(data); }).catch((err) => { util.log(err); + util.log.error(err); reject(err); }); } // else components.length === 0 diff --git a/lib/buildCommon/compileTypescript.js b/lib/buildCommon/compileTypescript.js index d3e4a19..4b37744 100644 --- a/lib/buildCommon/compileTypescript.js +++ b/lib/buildCommon/compileTypescript.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -444,11 +444,34 @@ function _copyVComponentComponentJsonToJs({ context }) { const { pack, component } = context.opts.typescript; let files = []; if (component) { - if (util.isVComponent({ pack, component })) { - if (pack) { - files = [path.join(componentsDtBaseSrcPath, `${pack}-${component}.json`)]; + if (context.serving && util.isVComponent({ pack, component })) { + // changed component during "ojet serve", is a singleton or pack vcomponent + const componentJsonPath = path.join(componentsDtBaseSrcPath, `${pack ? `${pack}-` : ''}${component}.json`); + if (util.fsExistsSync(componentJsonPath)) { + files.push(componentJsonPath); } else { - files = [path.join(componentsDtBaseSrcPath, `${component}.json`)]; + util.log.warning(`${componentJsonPath} does not exist`); + } + } else if (!context.serving) { + // running "ojet build component" which builds a singleton or pack component + if (util.isJETPack({ pack: component })) { + // is a pack, check if it contains vcomponents + util.getVComponentsInJETPack({ pack: component }).forEach((vcomponent) => { + const componentJsonPath = path.join(componentsDtBaseSrcPath, `${component}-${vcomponent}.json`); + if (util.fsExistsSync(componentJsonPath)) { + files.push(componentJsonPath); + } else { + util.log.error(`${componentJsonPath} does not exist`); + } + }); + } else if (util.isVComponent({ component })) { + // is a singleton vcomponent + const componentJsonPath = path.join(componentsDtBaseSrcPath, `${component}.json`); + if (util.fsExistsSync(componentJsonPath)) { + files.push(componentJsonPath); + } else { + util.log.error(`${componentJsonPath} does not exist`); + } } } } else { diff --git a/lib/buildCommon/copyLocalComponent.js b/lib/buildCommon/copyLocalComponent.js index 2daa77f..87d4a54 100644 --- a/lib/buildCommon/copyLocalComponent.js +++ b/lib/buildCommon/copyLocalComponent.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/buildCommon/generateComponentsCache.js b/lib/buildCommon/generateComponentsCache.js index 1e4010e..d83c6e6 100644 --- a/lib/buildCommon/generateComponentsCache.js +++ b/lib/buildCommon/generateComponentsCache.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/buildCommon/minifyComponent.js b/lib/buildCommon/minifyComponent.js index 13e3c4c..247a449 100644 --- a/lib/buildCommon/minifyComponent.js +++ b/lib/buildCommon/minifyComponent.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -10,12 +10,12 @@ const optimizeComponent = require('./optimizeComponent'); const CONSTANTS = require('../constants'); class ComponentMinifier { - /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - */ +/** + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + */ constructor({ context, componentJson }) { this.context = context; this.componentJson = componentJson; @@ -53,12 +53,12 @@ class ComponentMinifier { class SingletonComponentMinifier extends ComponentMinifier { /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - * @param {string} options.destBase - */ + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + * @param {string} options.destBase + */ constructor({ context, componentJson, destBase }) { super({ context, componentJson }); this.baseUrl = path.join(destBase, componentJson.name, componentJson.version); @@ -76,13 +76,13 @@ class SingletonComponentMinifier extends ComponentMinifier { class PackComponentMinifier extends ComponentMinifier { /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - * @param {object} options.packComponentJson - * @param {string} options.destBase - */ + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + * @param {object} options.packComponentJson + * @param {string} options.destBase + */ constructor({ context, componentJson, packComponentJson, destBase }) { super({ context, componentJson }); this.baseUrl = path.join(destBase, packComponentJson.name, packComponentJson.version); @@ -99,13 +99,13 @@ class PackComponentMinifier extends ComponentMinifier { } class SingletonCompositeComponentMinifier extends SingletonComponentMinifier { - /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - * @param {string} destBase - */ +/** + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + * @param {string} destBase + */ constructor({ context, componentJson, destBase }) { super({ context, componentJson, destBase }); } @@ -123,14 +123,14 @@ class SingletonCompositeComponentMinifier extends SingletonComponentMinifier { } class PackCompositeComponentMinifier extends PackComponentMinifier { - /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - * @param {object} options.packComponentJson - * @param {string} options.destBase - */ +/** + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + * @param {object} options.packComponentJson + * @param {string} options.destBase + */ constructor({ context, componentJson, packComponentJson, destBase }) { super({ context, componentJson, packComponentJson, destBase }); } @@ -148,14 +148,14 @@ class PackCompositeComponentMinifier extends PackComponentMinifier { } class ResourceComponentMinifier extends PackComponentMinifier { - /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.componentJson - * @param {object} options.packComponentJson - * @param {string} options.destBase - */ +/** + * + * @param {object} options + * @param {object} options.context + * @param {object} options.componentJson + * @param {object} options.packComponentJson + * @param {string} options.destBase + */ constructor({ context, componentJson, packComponentJson, destBase }) { super({ context, componentJson, packComponentJson, destBase }); } @@ -175,11 +175,12 @@ class ResourceComponentMinifier extends PackComponentMinifier { } return config; } + /** - * - * @param {object} options - * @param {string} options.publicModule - */ + * + * @param {object} options + * @param {string} options.publicModule + */ generateRjsOptions({ publicModule }) { const { baseUrl, componentJson, destPath } = this; return { @@ -189,10 +190,10 @@ class ResourceComponentMinifier extends PackComponentMinifier { }; } /** - * - * @param {object} options - * @param {string} options.publicModule - */ + * + * @param {object} options + * @param {string} options.publicModule + */ getExtraExcludes({ publicModule }) { const { componentJson } = this; const { publicModules, pack: packName, name: componentName } = componentJson; @@ -207,13 +208,13 @@ class ResourceComponentMinifier extends PackComponentMinifier { } class PackBundlesMinifier extends ComponentMinifier { - /** - * - * @param {object} options - * @param {object} options.context - * @param {object} options.packComponentJson - * @param {string} options.destBase - */ +/** + * + * @param {object} options + * @param {object} options.context + * @param {object} options.packComponentJson + * @param {string} options.destBase + */ constructor({ context, packComponentJson, destBase }) { super({ context }); this.packComponentJson = packComponentJson; diff --git a/lib/buildCommon/optimizeComponent.js b/lib/buildCommon/optimizeComponent.js index 5310144..04cb9d2 100644 --- a/lib/buildCommon/optimizeComponent.js +++ b/lib/buildCommon/optimizeComponent.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -73,7 +73,7 @@ function optimizeComponentSetup({ separateCSS: context.opts.requireJsComponent.separateCSS, generateSourceMaps: context.opts.requireJsComponent.generateSourceMaps }; - const exclude = ['css', 'ojL10n', 'text', 'normalize', 'css-builder']; + const exclude = ['css', 'ojcss', 'ojL10n', 'text', 'normalize', 'css-builder']; if (extraExcludes) { extraExcludes.forEach((extraExclude) => { exclude.push(extraExclude); diff --git a/lib/buildComponent.js b/lib/buildComponent.js index b48c07a..11c260f 100644 --- a/lib/buildComponent.js +++ b/lib/buildComponent.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/buildHybrid.js b/lib/buildHybrid.js index 5f8b4f7..f9bb253 100644 --- a/lib/buildHybrid.js +++ b/lib/buildHybrid.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -146,11 +146,11 @@ function _runReleaseBuildTasks(context) { resolve(context); } else { hookRunner('before_release_build', context) + .then(buildCommon.modifyMainJs) .then(buildCommon.minifyLocalCca) .then(buildCommon.minifyLocalVComponents) .then(buildCommon.terser) .then(buildCommon.requireJs) - .then(buildCommon.copyMainJs) .then(buildCommon.cleanTemp) .then(buildCommon.cleanTypescript) .then(data => resolve(data)) diff --git a/lib/buildWeb.js b/lib/buildWeb.js index 2018124..c7049a0 100644 --- a/lib/buildWeb.js +++ b/lib/buildWeb.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -19,12 +19,12 @@ function _runReleaseBuildTasks(context) { } else { buildCommon.injectPathsEs5(context) .then(data => hookRunner('before_release_build', data)) + .then(buildCommon.modifyMainJs) .then(buildCommon.minifyLocalCca) .then(buildCommon.minifyLocalVComponents) .then(buildCommon.terser) .then(buildCommon.requireJs) .then(buildCommon.requireJsEs5) - .then(buildCommon.copyMainJs) .then(buildCommon.cleanTemp) .then(buildCommon.cleanTypescript) .then(data => resolve(data)) diff --git a/lib/clean.js b/lib/clean.js index d72b755..1e4e84a 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/config.js b/lib/config.js index 06089d3..ffe7299 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -89,6 +89,5 @@ function _readConfigJson() { config.set('defaultBrowser', configJson.defaultBrowser || CONSTANTS.DEFAULT_BROWSER); config.set('sassVer', configJson.sassVer || CONSTANTS.SASS_VER); config.set('defaultTheme', configJson.defaultTheme || CONSTANTS.DEFAULT_THEME); - config.set('defaultCssvars', configJson.defaultCssvars || CONSTANTS.DEFAULT_CSSVARS); return configJson; } diff --git a/lib/configure.js b/lib/configure.js index d310765..dbbbee1 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/constants.js b/lib/constants.js index 3691c3d..eb33eb2 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -17,7 +17,6 @@ module.exports = { APP_STAGED_THEMES_DIRECTORY: 'staged-themes', DEFAULT_THEME: 'alta', DEFAULT_PCSS_THEME: 'redwood', - DEFAULT_CSSVARS: 'disabled', DEFAULT_BROWSER: 'chrome', SASS_VER: '4.13.0', COMMON_THEME_DIRECTORY: 'common', @@ -53,6 +52,7 @@ module.exports = { PATH_MAPPING_VERSION_TOKEN: '#{version}', PATH_TO_HOOKS_CONFIG: 'scripts/hooks/hooks.json', TSCONFIG: 'tsconfig.json', + PATH_TO_PWA_TEMPLATES: 'node_modules/@oracle/oraclejet-tooling/lib/templates/serviceWorkers', PATH_TO_TSCONFIG_TEMPLATE: 'node_modules/@oracle/oraclejet-tooling/lib/templates/typescript/tsconfig.json', API_TASKS: { @@ -66,6 +66,7 @@ module.exports = { REMOVE: 'remove', SEARCH: 'search', ADDTYPESCRIPT: 'addtypescript', + ADDPWA: 'addpwa', PACKAGE: 'package' }, API_SCOPES: { @@ -88,5 +89,5 @@ module.exports = { COMPONENTS_DT: 'components_dt', PATH_TO_CUSTOM_TSC: '../../../oraclejet/dist/custom-tsc', PATH_TO_CUSTOM_TSC_TEMPLATES: './node_modules/@oracle/oraclejet/dist/custom-tsc/templates', - TYPESCRIPT_VERSION: '3.8.3' + TYPESCRIPT_VERSION: '4.0.2' }; diff --git a/lib/create.js b/lib/create.js index 19c569d..d10297e 100644 --- a/lib/create.js +++ b/lib/create.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/defaultconfig.js b/lib/defaultconfig.js index 780c6ea..e4a6040 100644 --- a/lib/defaultconfig.js +++ b/lib/defaultconfig.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -122,6 +122,7 @@ module.exports = { `!${paths.src.javascript}/libs/**/*debug*`, `!${paths.src.javascript}/libs/**/*debug*/**`, `!${paths.src.javascript}/main-release-paths.json`, + `!${paths.src.themes}/**`, `!${paths.staging.themes}/**`, `!${paths.src.javascript}/${paths.composites}/**`, `!${paths.src.typescript}/${paths.composites}/**`, diff --git a/lib/hookRunner.js b/lib/hookRunner.js index b4f3b3c..ef3e3a4 100644 --- a/lib/hookRunner.js +++ b/lib/hookRunner.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/indexHtmlInjector.js b/lib/indexHtmlInjector.js index 18f31f9..d8268aa 100644 --- a/lib/indexHtmlInjector.js +++ b/lib/indexHtmlInjector.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -25,6 +25,7 @@ const injectorUtil = require('./injectorUtil'); const util = require('./util'); const endOfLine = require('os').EOL; const config = require('./config'); +const CONSTANTS = require('./constants'); /** * # Injector API @@ -133,7 +134,7 @@ function _getInjectSourceContent(updatePlatformFile, platform) { return { indexHTML, document, documentDom }; } -function _getStyleLinkBase(css, theme, cssvars, buildType) { +function _getStyleLinkBase(css, theme, buildType) { const masterJson = _isUseCdn(theme.name); const linkExt = util.getThemeCssExtention(buildType, masterJson !== null); @@ -141,13 +142,26 @@ function _getStyleLinkBase(css, theme, cssvars, buildType) { // CDN // Add -platform if non web and non redwood const platform = (theme.platform === 'web' || theme.name === 'redwood') ? '' : `-${theme.platform}`; - return `${masterJson.cdns.jet.css}/${theme.name}${platform}/oj-${theme.name}${cssvars}${linkExt}`; + return { created: `${masterJson.cdns.jet.css}/${theme.name}${platform}/oj-${theme.name}${linkExt}` }; } const platform = (theme.name === 'redwood') ? 'web' : theme.platform; - return (theme.version) ? - `${css}/${theme.name}/${theme.version}/${platform}/${theme.name}${cssvars}${linkExt}` : - `${css}/${theme.name}/${platform}/${theme.name}${cssvars}${linkExt}`; + if (theme.version) { + if (theme.cssGeneratedType === 'add-on') { + return { + default: `${css}/${CONSTANTS.DEFAULT_PCSS_THEME}/${util.getJETVersion()}/${platform}/${CONSTANTS.DEFAULT_PCSS_THEME}${linkExt}`, + created: `${css}/${theme.name}/${theme.version}/${platform}/${theme.name}${linkExt}` + }; + } + if (theme.cssGeneratedType === 'combined' || theme.cssGeneratedType === '') { + return { + created: `${css}/${theme.name}/${theme.version}/${platform}/${theme.name}${linkExt}` + }; + } + } + return { + created: `${css}/${theme.name}/${platform}/${theme.name}${linkExt}` + }; } function _isUseCdn(name) { @@ -163,25 +177,15 @@ function _isUseCdn(name) { } -function _getThemeStyleLink(theme, buildType, csstype) { +function _getThemeStyleLink(theme, buildType) { const css = config('paths').src.styles; - const cssvarsValue = csstype; - const cssVarsDestPath = path.resolve(config('paths').src.common, 'themes', theme.name, 'web', `_${theme.name}.cssvars.settings.scss`); - const pcssTheme = fs.existsSync(util.destPath(cssVarsDestPath)); - const cssvars = (() => { - if (cssvarsValue === 'enabled') { - if (theme.name === 'redwood' || pcssTheme) { - return '-cssvars'; - } - } - if (cssvarsValue === 'disabled') { - return ''; - } - return util.log.error('In oraclejetconfig.json value of defaultCssvars must be [enabled or disabled]\nor\ndefaultCssvars:"enabled" supported only for pcss themes, not supported for alta themes'); - })(); - const linkBase = _getStyleLinkBase(css, theme, cssvars, buildType); + const linkBase = _getStyleLinkBase(css, theme, buildType); - return ``; + if (linkBase.default) { + return ` +`; + } + return ``; } function _getIndexHtml(indexHtml) { @@ -244,7 +248,7 @@ module.exports = } if (write) { - util.writeFileSync(indexHTML, documentDom); + util.writeFileSync(indexHTML, documentDom.toString()); } return context; @@ -264,8 +268,7 @@ module.exports = const lineEnding = /\r\n/.test(String(indexHtmlContent)) ? '\r\n' : '\n'; const theme = opts.theme; - const csstype = (opts.defaultCssvars) ? opts.defaultCssvars : config('defaultCssvars'); - const themeStyleLink = _getThemeStyleLink(theme, buildType, csstype); + const themeStyleLink = _getThemeStyleLink(theme, buildType); // two step process to help regex performance @@ -308,7 +311,7 @@ module.exports = contentAttrValue += newScriptSrc; } cspMetaTag.setAttribute('content', contentAttrValue); - util.writeFileSync(indexHtmlDestPath, documentDom); + util.writeFileSync(indexHtmlDestPath, documentDom.toString()); } return Promise.resolve(context); }, @@ -328,7 +331,7 @@ module.exports = const cdnElement = _createScriptElement(documentDom, scriptSrc); if (cdnElement) { _injectCdnBundleElement(documentDom, cdnElement); - util.writeFileSync(indexHtmlDestPath, documentDom); + util.writeFileSync(indexHtmlDestPath, documentDom.toString()); } return Promise.resolve(context); diff --git a/lib/injectorUtil.js b/lib/injectorUtil.js index 44eba17..2e63182 100644 --- a/lib/injectorUtil.js +++ b/lib/injectorUtil.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/list.js b/lib/list.js index e074cff..665352f 100644 --- a/lib/list.js +++ b/lib/list.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2efeb8b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. - Licensed under The Universal Permissive License (UPL), Version 1.0 - as shown at https://oss.oracle.com/licenses/upl/ - -*/ -// This needs to be non-ES6 -/* eslint-disable no-var, import/no-dynamic-require, global-require, prefer-arrow-callback */ - -'use strict'; - -(function () { - var _ojNeedsES5; - var bundle = 'bundle'; - - function _ojIsIE11() { - var nAgt = navigator.userAgent; // eslint-disable-line no-undef - return nAgt.indexOf('MSIE') !== -1 || !!nAgt.match(/Trident.*rv:11./); - } - _ojNeedsES5 = _ojIsIE11(); - - // eslint-disable-next-line no-undef - requirejs.config({ - baseUrl: 'js' - }); - - bundle += (_ojNeedsES5 ? '_es5' : ''); - require([bundle], function () { - }); -}()); diff --git a/lib/mainJsInjector.js b/lib/mainJsInjector.js index 4159b68..f5709c0 100644 --- a/lib/mainJsInjector.js +++ b/lib/mainJsInjector.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/npmCopy.js b/lib/npmCopy.js index 7b0ee93..5192271 100644 --- a/lib/npmCopy.js +++ b/lib/npmCopy.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -11,6 +11,7 @@ const path = require('path'); const config = require('./config'); const CONSTANTS = require('./constants'); const util = require('./util'); +const configGenerator = require('./rjsConfigGenerator'); module.exports = {}; const npmCopy = module.exports; @@ -71,11 +72,6 @@ npmCopy.getNonMappingFileList = function (buildType, platform) { cwd: `${cssSrcPrefix}redwood`, src: ['**'], dest: `${config('paths').staging.themes}/redwood/web` - }, - { - cwd: `${cssSrcPrefix}common`, - src: ['**'], - dest: `${config('paths').staging.themes}/redwood/common` } ]; } else { @@ -129,11 +125,6 @@ npmCopy.getNonMappingFileList = function (buildType, platform) { src: ['**'], dest: `${config('paths').staging.themes}/redwood/web` }, - { - cwd: `${cssSrcPrefix}common`, - src: ['**'], - dest: `${config('paths').staging.themes}/redwood/common` - }, { cwd: `${srcPrefix}@oracle/oraclejet/dist/js/libs/oj/resources/nls`, src: ['*.js'], @@ -189,13 +180,6 @@ function _processVersionToken(libName, destPath) { ? destPath.replace(CONSTANTS.PATH_MAPPING_VERSION_TOKEN, versions[libName]) : destPath; } -function _isCdnPath(libObj, useCdn, cdnUrls, buildType) { - return (useCdn === 'cdn' - && libObj.cdn !== undefined - && cdnUrls[libObj.cdn] !== undefined - && libObj[buildType].cdnPath !== undefined); -} - function _needCopyTask(buildType, libObj) { return Object.prototype.hasOwnProperty.call(libObj[buildType], 'src'); } @@ -219,9 +203,7 @@ npmCopy.renameAltaThemeFiles = function (paths) { if (config('defaultTheme') === CONSTANTS.DEFAULT_PCSS_THEME) { const redwoodfileList = { 'oj-redwood.css': 'redwood.css', - 'oj-redwood-min.css': 'redwood.min.css', - 'oj-redwood-cssvars.css': 'redwood-cssvars.css', - 'oj-redwood-cssvars-min.css': 'redwood-cssvars.min.css' + 'oj-redwood-min.css': 'redwood.min.css' }; const redwoodthemePath = path.join(paths.staging.themes, CONSTANTS.DEFAULT_PCSS_THEME); Object.keys(redwoodfileList).forEach((key) => { @@ -232,9 +214,7 @@ npmCopy.renameAltaThemeFiles = function (paths) { } else { const fileList = { 'oj-redwood.css': 'redwood.css', - 'oj-redwood-min.css': 'redwood.min.css', - 'oj-redwood-cssvars.css': 'redwood-cssvars.css', - 'oj-redwood-cssvars-min.css': 'redwood-cssvars.min.css' + 'oj-redwood-min.css': 'redwood.min.css' }; const themePath = path.join(paths.staging.themes, CONSTANTS.DEFAULT_PCSS_THEME); @@ -252,7 +232,13 @@ npmCopy.getMappingLibsList = function (buildMode, platform) { const basePath = masterJson.baseUrl; Object.keys(masterJson.libs).forEach((lib) => { const libObj = masterJson.libs[lib]; - const isCdn = _isCdnPath(libObj, masterJson.cdn, masterJson.cdns, buildType); + const isCdn = configGenerator.isCdnPath( + libObj, + masterJson.use, + masterJson.cdns, + buildType, + lib + ); // Skip copy the library if it uses cdn if (!isCdn && _needCopyTask(buildType, libObj)) { libsList.push(_getValidLibObj(buildType, lib, libObj, basePath, platform)); diff --git a/lib/package.js b/lib/package.js index 544f1e6..cd50b96 100644 --- a/lib/package.js +++ b/lib/package.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/parser/dom-parser.js b/lib/parser/dom-parser.js index 271a129..f3a602b 100644 --- a/lib/parser/dom-parser.js +++ b/lib/parser/dom-parser.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/parser/dom.js b/lib/parser/dom.js index 69bf276..704e6ce 100644 --- a/lib/parser/dom.js +++ b/lib/parser/dom.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/parser/sax.js b/lib/parser/sax.js index 981f7d2..9547da2 100644 --- a/lib/parser/sax.js +++ b/lib/parser/sax.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/pcss.js b/lib/pcss.js index 8717ac0..8d81786 100644 --- a/lib/pcss.js +++ b/lib/pcss.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -28,8 +28,18 @@ function _getDefaultPcssThemeTasks(context) { const opts = context.opts; // compile the default theme let taskArray = []; - if (opts.theme.compile) { - taskArray = taskArray.concat(_getPcssTasks(opts.theme, context)); + + if (opts.theme) { + // compile additional multi themes + if (opts.themes) { + opts.themes.forEach((singleTheme) => { + if (singleTheme.compile) { + taskArray = taskArray.concat(_getPcssTasks(singleTheme, context)); + } + }); + } else { + taskArray = taskArray.concat(_getPcssTasks(opts.theme, context)); + } } // // if svg is enabled, re-compile Alta @@ -37,15 +47,6 @@ function _getDefaultPcssThemeTasks(context) { // taskArray = taskArray.concat(_getAltaSassTasks(opts.theme, context)); // } - // compile additional multi themes - if (opts.themes) { - opts.themes.forEach((singleTheme) => { - if (singleTheme.compile) { - taskArray = taskArray.concat(_getPcssTasks(singleTheme, context)); - } - }); - } - // compile cca if (opts.sassCompile) { taskArray = taskArray.concat(_getCcaPcssTasks(context, false)); @@ -78,13 +79,13 @@ function _getPcssDest(buildType, dest, isReleaseBuild) { const isCcaSassFile = util.isCcaSassFile(dest); // Force debug extension for Cca sass files because we can't update the references easily const ext = isCcaSassFile ? util.getThemeCssExtention('debug') : util.getThemeCssExtention(buildType); - let pcssDest = util.destPath(path.join(path.dirname(dest), `${name}-cssvars${ext}`)); + let pcssDest = util.destPath(path.join(path.dirname(dest), `${name}${ext}`)); if (isCcaSassFile) { const { componentPath, subFolders } = util.getComponentPathFromThemingFileDest({ dest, isReleaseBuild }); - pcssDest = util.destPath(path.join(componentPath, subFolders, `${name}-cssvars${ext}`)); + pcssDest = util.destPath(path.join(componentPath, subFolders, `${name}${ext}`)); } return pcssDest; } @@ -116,8 +117,7 @@ function _writeCustomizedCss(postcss, gplugin, outFile, destFile, option) { from: undefined }; } - postcss(gplugin) - .process(outFile, processoption) + postcss(gplugin).process(outFile, processoption) .then((result) => { fs.ensureFileSync(destFile); fs.outputFileSync(destFile, result.css); @@ -130,7 +130,6 @@ function _writeCustomizedCss(postcss, gplugin, outFile, destFile, option) { function _getPcssTaskPromise(options, context) { const sass = require('node-sass'); // eslint-disable-line const postcss = require('postcss'); // eslint-disable-line - const customProperties = require('postcss-custom-properties'); // eslint-disable-line const pcssCalc = require('postcss-calc'); // eslint-disable-line const autoPrefix = require('autoprefixer'); // eslint-disable-line return new Promise((resolve, reject) => { @@ -142,43 +141,18 @@ function _getPcssTaskPromise(options, context) { _writePcssResultToFile(options, result); console.log(`Pcss compile\n From => ${options.file}\n To => ${options.outFile} finished..`); - // Adding current cli version number to token @jetcssversion@ in css - let cssFileContent = fs.readFileSync(options.outFile, 'utf-8'); - cssFileContent = util.regExReplace(cssFileContent, '@jetcssversion@', `v${util.getJETVersion()}`); - fs.writeFileSync(options.outFile, cssFileContent); - // compile custom property css to variable converted to value css const css = util.readFileSync(options.outFile); - const fileName = (options.outFile.indexOf('.min.') === -1) ? - path.basename(options.file, '.scss') : `${path.basename(options.file, '.scss')}.min`; - const processFile = util.destPath(path.join(path.dirname(options.outFile), `${fileName}.css`)); new Promise((resolve, reject) => { // eslint-disable-line - _writeCustomizedCss(postcss, customProperties, css, processFile); - console.log(`Pcss custom property compile\n From => ${options.outFile}\n To => ${processFile} finished..`); + _writeCustomizedCss(postcss, pcssCalc, css, options.outFile); + console.log(`Pcss calc compile\n To => ${options.outFile} finished..`); resolve(); }) - .then(() => { - _writeCustomizedCss(postcss, pcssCalc, css, options.outFile); - console.log(`Pcss calc compile\n To => ${options.outFile} finished..`); - resolve(); - }) - .then(() => { - const processedcss = util.readFileSync(processFile); - _writeCustomizedCss(postcss, pcssCalc, processedcss, processFile); - console.log(`Pcss calc compile\n To => ${processFile} finished..`); - resolve(); - }) .then(() => { const autoprefixvarscss = util.readFileSync(options.outFile); _writeCustomizedCss(postcss, autoPrefix, autoprefixvarscss, options.outFile, 'prefix'); console.log(`Pcss Autoprefixer compile\n To => ${options.outFile} finished..`); resolve(); - }) - .then(() => { - const autoprefixcss = util.readFileSync(processFile); - _writeCustomizedCss(postcss, autoPrefix, autoprefixcss, processFile, 'prefix'); - console.log(`Pcss Autoprefixer compile\n To => ${processFile} finished..`); - resolve(); }); resolve(context); } diff --git a/lib/publish.js b/lib/publish.js index 15fcd2e..5c17255 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/remove.js b/lib/remove.js index 6fbac38..5e5dd82 100644 --- a/lib/remove.js +++ b/lib/remove.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/rjsConfigGenerator.js b/lib/rjsConfigGenerator.js index 43e69e7..aed590d 100644 --- a/lib/rjsConfigGenerator.js +++ b/lib/rjsConfigGenerator.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -68,7 +68,7 @@ function _getLibPath(buildType, libObj, useCdn, cdnUrls, libName, requirejs, es5 } function _isCdnPath(libObj, useCdn, cdnUrls, buildType, libName) { - const pluginLibs = ['text', 'css', 'normalize', 'css-builder', 'ojL10n']; + const pluginLibs = ['text', 'ojcss', 'css', 'normalize', 'css-builder', 'ojL10n']; const pluginLib = (buildType === 'release' && pluginLibs.indexOf(libName) > -1); return (useCdn === 'cdn' && !pluginLib @@ -276,7 +276,11 @@ function _getLocalCcaPathMapping(buildType, requirejs, scriptsFolder) { ); // target minified directory for release builds. if (buildType === 'release') { - pathMappingObj[componentJson.name] = path.join(pathMappingObj[componentJson.name], 'min'); + // Use minified directory for all components except type: demo + if (!(Object.prototype.hasOwnProperty.call(componentJson, 'type') && + (componentJson.type === 'demo'))) { + pathMappingObj[componentJson.name] = path.join(pathMappingObj[componentJson.name], 'min'); + } } pathMappingObj[componentJson.name] = requirejs ? pathMappingObj[componentJson.name] : `'${pathMappingObj[componentJson.name]}'`; } @@ -389,5 +393,7 @@ module.exports = { const buildType = context.buildType === 'release' ? 'release' : 'debug'; const rjsConfig = _getRJsConfig(buildType, masterJson, rConfig, es5); return _getCcaRJsConfig(buildType, masterJson, rjsConfig); - } + }, + + isCdnPath: _isCdnPath }; diff --git a/lib/sass.js b/lib/sass.js index 31837eb..6f20703 100644 --- a/lib/sass.js +++ b/lib/sass.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/scopes/component.js b/lib/scopes/component.js index 8d24a54..a98bc66 100644 --- a/lib/scopes/component.js +++ b/lib/scopes/component.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -504,33 +504,91 @@ function _addToTsconfigPathMapping(componentMetadata) { */ function _shufflePackComponentResources(componentMetadata) { return new Promise((resolve) => { - const { pack, name } = componentMetadata; - if (pack) { - const pathToPack = path.join(componentsDirPath, pack); - const pathToPackComponent = path.join(pathToPack, name); - const pathToPackComponentMinFolder = path.join(pathToPackComponent, 'min'); - const pathToPackComponentTypesFolder = path.join(pathToPackComponent, 'types'); + const { pack: componentPack, name: componentName, type } = componentMetadata; + if (componentPack) { + // if component belongs to a pack and has a /min folder, + // move the folder from //min to /min/ + const pathToPack = path.join(componentsDirPath, componentPack); + const pathToPackComponentMinFolder = path.join(pathToPack, componentName, 'min'); if (util.fsExistsSync(pathToPackComponentMinFolder)) { - fs.moveSync(pathToPackComponentMinFolder, path.join(pathToPack, 'min', name)); + fs.moveSync(pathToPackComponentMinFolder, path.join(pathToPack, 'min', componentName)); } - if (util.fsExistsSync(pathToPackComponentTypesFolder) && - util.isDirectory(pathToPackComponentTypesFolder)) { - // only copy *.ts files in case a component uses the "types" folder - // for none-typescript resources - glob.sync('**/*.ts', { cwd: pathToPackComponentTypesFolder }).forEach((tsFile) => { + } + if (type !== 'pack') { + // find all *.d.ts files in the none-pack component and move them to + // /types/ if the component is in a pack and + // /types if the component is a singleton + _moveDtsFiles({ componentPack, componentName }); + } + resolve(componentMetadata); + }); +} + +/** + * ## _moveDtFiles + * + * Find all *.d.ts files in a component and move them to /types/ if + * the component is in a pack and /types if the component + * is a singleton. This is needed because not all components aggregate + * their type definition files in the single location ("types" folder) + * expected by the tooling + * @param {object} options + * @param {string} options.componentPack + * @param {string} options.componentName + * @returns {void} + */ +function _moveDtsFiles({ componentPack = '', componentName }) { + if (componentPack) { + // component is inside a pack + const componentPackRoot = path.join(componentsDirPath, componentPack); + const componentRoot = path.join(componentPackRoot, componentName); + const componentPackTypesFolder = path.join(componentPackRoot, 'types', componentName); + const componentTypesFolder = path.join(componentRoot, 'types'); + if (util.fsExistsSync(componentTypesFolder) && + util.isDirectory(componentTypesFolder)) { + // /component>/types found, move all *.d.ts in it to + // /types/ + glob.sync('**/*.d.ts', { cwd: componentTypesFolder }) + .forEach((dtsFile) => { fs.moveSync( - path.join(pathToPackComponentTypesFolder, tsFile), - path.join(pathToPack, 'types', name, tsFile) + path.join(componentTypesFolder, dtsFile), + path.join(componentPackTypesFolder, dtsFile) ); }); - // if folder only had *.ts files, delete it because all the relevant files were moved - if (!fs.readdirSync(pathToPackComponentTypesFolder).length) { - fs.removeSync(pathToPackComponentTypesFolder); - } + // if //types is empty due to move, delete + if (!fs.readdirSync(componentTypesFolder).length) { + fs.removeSync(componentTypesFolder); } } - resolve(componentMetadata); - }); + // look for *.d.ts files outside //types and copy them to + // /types/ if an equivalent file is not already present + glob.sync('**/*.d.ts', { cwd: componentRoot }) + .forEach((dtsFile) => { + const dtsFileTypesFolderPath = path.join(componentPackTypesFolder, dtsFile); + if (!fs.existsSync(dtsFileTypesFolderPath)) { + fs.moveSync( + path.join(componentRoot, dtsFile), + dtsFileTypesFolderPath + ); + } + }); + } else { + // component is a singleton + const componentRoot = path.join(componentsDirPath, componentName); + const componentTypesFolder = path.join(componentRoot, 'types'); + // look for *.d.ts files outside /types and copy them to + // /types if an equivalent file is not already present + glob.sync('**/*.d.ts', { cwd: componentRoot }) + .forEach((dtsFile) => { + const dtsFileTypesFolderPath = path.join(componentTypesFolder, dtsFile); + if (!fs.existsSync(dtsFileTypesFolderPath)) { + fs.moveSync( + path.join(componentRoot, dtsFile), + dtsFileTypesFolderPath + ); + } + }); + } } /** diff --git a/lib/scopes/exchange.js b/lib/scopes/exchange.js index ce79678..95cda4a 100644 --- a/lib/scopes/exchange.js +++ b/lib/scopes/exchange.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/scopes/pack.js b/lib/scopes/pack.js index 3980700..57bdcbd 100644 --- a/lib/scopes/pack.js +++ b/lib/scopes/pack.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -427,7 +427,10 @@ pack.publish = function (packName, options) { } // Should we build component or can we skip that initial step? - const initalPromise = hadBeenBuiltBefore ? Promise.resolve() : build('web', {}); + const initalPromise = hadBeenBuiltBefore ? Promise.resolve() : build('web', { + sassCompile: true, + pcssCompile: true + }); return initalPromise .then(() => { diff --git a/lib/search.js b/lib/search.js index a359160..9d0cfd9 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/serve.js b/lib/serve.js index 1f77aea..a0433c6 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -414,8 +414,7 @@ function _getBuildAction() { userOptions: serveConfig.userOptions, notscompile: serveConfig.notscompile, dbg: serveConfig.dbg, - optimize: serveConfig.optimize, - defaultCssvars: serveConfig.defaultCssvars + optimize: serveConfig.optimize }); return ojetBuild(config.get('platform'), buildConfig); }; diff --git a/lib/serve/connect.js b/lib/serve/connect.js index 082c4ec..2251573 100644 --- a/lib/serve/connect.js +++ b/lib/serve/connect.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -30,10 +30,21 @@ module.exports = function (opts, context) { utils.log('Starting web server.'); const connectOpts = _processCustomOptions(opts); return new Promise((resolve, reject) => { - const middlewareList = _getMiddleware(connectOpts); const app = context.express ? context.express : express(); - middlewareList.forEach((middleware) => { + const defaultMiddleware = _getMiddleware(connectOpts); + const customMiddleware = Array.isArray(context.middleware) ? context.middleware : null; + const customPreMiddleware = context.preMiddleware || []; + const customPostMiddleware = context.postMiddleware || []; + + let appMiddleware; + if (customMiddleware) { + appMiddleware = customMiddleware; + } else { + appMiddleware = [...customPreMiddleware, ...defaultMiddleware, ...customPostMiddleware]; + } + + appMiddleware.forEach((middleware) => { let middlewareArray = middleware; if (!util.isArray(middlewareArray)) { middlewareArray = [middlewareArray]; diff --git a/lib/serve/watch.js b/lib/serve/watch.js index 328bfca..980ea90 100644 --- a/lib/serve/watch.js +++ b/lib/serve/watch.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/serveHybrid.js b/lib/serveHybrid.js index 072dd3d..2f86471 100644 --- a/lib/serveHybrid.js +++ b/lib/serveHybrid.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/serveHybridFileChangeHandler.js b/lib/serveHybridFileChangeHandler.js index fb9e342..44aebcb 100644 --- a/lib/serveHybridFileChangeHandler.js +++ b/lib/serveHybridFileChangeHandler.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/serveWeb.js b/lib/serveWeb.js index 9ffe38b..91e145a 100644 --- a/lib/serveWeb.js +++ b/lib/serveWeb.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/serveWebFileChangeHandler.js b/lib/serveWebFileChangeHandler.js index 2b255f8..6416f71 100644 --- a/lib/serveWebFileChangeHandler.js +++ b/lib/serveWebFileChangeHandler.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/strip.js b/lib/strip.js index f3d5d8a..4c66bad 100644 --- a/lib/strip.js +++ b/lib/strip.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -18,14 +18,12 @@ _.union = require('lodash.union'); _.difference = require('lodash.difference'); function _getGitIgnore() { - let content = []; - try { - content = util.readFileSync(util.destPath('.gitignore')); - } catch (e) { - util.log.warning('No .gitignore file found. No files will be cleaned'); - return []; + const pathTogGitIgnore = util.destPath('.gitignore'); + if (util.fsExistsSync(pathTogGitIgnore)) { + return util.readFileSync(pathTogGitIgnore).split(/\r?\n/); } - return content.split(/\r?\n/); + util.log.warning('No .gitignore file found. No files will be cleaned'); + return []; } function _getCleanFileList(ignoreList) { diff --git a/lib/svg.js b/lib/svg.js index 56bf339..5775dea 100644 --- a/lib/svg.js +++ b/lib/svg.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/templates/pack/component.json b/lib/templates/pack/component.json index 84f89c0..5debb97 100644 --- a/lib/templates/pack/component.json +++ b/lib/templates/pack/component.json @@ -1,7 +1,7 @@ { "name": "@pack@", "version": "1.0.0", - "jetVersion": "9.2.0", + "jetVersion": "10.0.0", "type": "pack", "displayName": "A user friendly, translatable name of the pack.", "description": "A translatable high-level description for the pack.", diff --git a/lib/templates/serviceWorkers/manifest.json b/lib/templates/serviceWorkers/manifest.json new file mode 100644 index 0000000..d16fdfc --- /dev/null +++ b/lib/templates/serviceWorkers/manifest.json @@ -0,0 +1,6 @@ +{ + "name": "@AppName@", + "start_url": "index.html", + "display": "standalone", + "orientation": "portrait" +} \ No newline at end of file diff --git a/lib/templates/serviceWorkers/sw.txt b/lib/templates/serviceWorkers/sw.txt new file mode 100644 index 0000000..74b4a15 --- /dev/null +++ b/lib/templates/serviceWorkers/sw.txt @@ -0,0 +1,31 @@ +const CACHE_NAME = '@AppName@'; +const resourcesToCache = [ + 'index.html', + 'manifest.json', + 'js/', + 'css/' +]; + +// install service worker and cache resources defined in resourcesToCache +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME).then(cache => ( + cache.addAll(resourcesToCache) + )) + ); +}); + +// return response from cache if there's a match +// otherwise fetch from server and add it to cache +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then((response) => { + return response || fetch(event.request).then((response) => { + return caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, response.clone()); + return response; + }); + }); + }) + ); +}); diff --git a/lib/templates/serviceWorkers/swInit.txt b/lib/templates/serviceWorkers/swInit.txt new file mode 100644 index 0000000..a5a8704 --- /dev/null +++ b/lib/templates/serviceWorkers/swInit.txt @@ -0,0 +1,11 @@ + diff --git a/lib/util.js b/lib/util.js index 2e8d148..6598167 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -678,7 +678,7 @@ util.getJETVersion = () => { }; util.getInstalledCssPackage = () => { - let getPackageJson = path.resolve('./node_modules/postcss-custom-properties'); + let getPackageJson = path.resolve('./node_modules/postcss-calc'); getPackageJson = fs.existsSync(getPackageJson); return getPackageJson; }; @@ -1358,6 +1358,7 @@ function _validateProtocol(requestedProtocol, secure) { // eslint-disable-line */ util.getLibVersionsObj = () => { const versionsObj = { + ojcss: _getVersionFromNpm('oraclejet'), ojs: _getVersionFromNpm('oraclejet'), ojL10n: _getVersionFromNpm('oraclejet'), ojtranslations: _getVersionFromNpm('oraclejet'), @@ -2034,7 +2035,7 @@ util.getLocalCompositeComponentJsonPaths = ({ built = false }) => { * @returns {boolean} true if the host application * is written in typescript */ -util.isTypescriptApplicaiton = () => ( +util.isTypescriptApplication = () => ( util.fsExistsSync(CONSTANTS.TSCONFIG) ); @@ -2127,7 +2128,7 @@ util.getExchangeComponentPathMappings = ({ context }) => { * @returns {boolean} true if should not run Typescript tasks, * false otherwise */ -util.shouldNotRunTypescriptTasks = context => !util.isTypescriptApplicaiton() || +util.shouldNotRunTypescriptTasks = context => !util.isTypescriptApplication() || !!context.opts.notscompile; /** @@ -2138,7 +2139,7 @@ util.shouldNotRunTypescriptTasks = context => !util.isTypescriptApplicaiton() || */ util.getSourceScriptsFolder = () => { const configPaths = util.getConfiguredPaths(); - return util.isTypescriptApplicaiton() ? + return util.isTypescriptApplication() ? configPaths.src.typescript : configPaths.src.javascript; }; @@ -2335,7 +2336,7 @@ util.pointTypescriptPathMappingsToStaging = ({ context, pathMappings }) => { * @param {boolean} options.isLocal */ util.addComponentToTsconfigPathMapping = ({ component, isLocal }) => { - if (util.isTypescriptApplicaiton()) { + if (util.isTypescriptApplication()) { const configPaths = util.getConfiguredPaths(); const tsconfigJsonPath = path.join('.', CONSTANTS.TSCONFIG); const tsconfigJson = util.readJsonAndReturnObject(tsconfigJsonPath); @@ -2362,7 +2363,7 @@ util.addComponentToTsconfigPathMapping = ({ component, isLocal }) => { * @param {string} options.component */ util.removeComponentFromTsconfigPathMapping = ({ component }) => { - if (util.isTypescriptApplicaiton()) { + if (util.isTypescriptApplication()) { const tsconfigJsonPath = path.join('.', CONSTANTS.TSCONFIG); const tsconfigJson = util.readJsonAndReturnObject(tsconfigJsonPath); const pathMapping = `${component}/*`; diff --git a/lib/utils.exchange.js b/lib/utils.exchange.js index 840a630..5f899e4 100644 --- a/lib/utils.exchange.js +++ b/lib/utils.exchange.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ diff --git a/lib/validations.js b/lib/validations.js index 78b3408..fd37161 100644 --- a/lib/validations.js +++ b/lib/validations.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -155,7 +155,9 @@ function _getValidThemeObject(themeStr, platform) { themeObj.platform = platform; themeObj.compile = _setSassCompile(themeObj); } - themeObj.version = _getThemeVersion(themeObj.name); + const THEME_DATA = _getThemeInfo(themeObj.name); + themeObj.version = THEME_DATA.versionNumber(); + themeObj.cssGeneratedType = THEME_DATA.generatedType(); return themeObj; } @@ -245,17 +247,31 @@ function _processThemesOption(options, platform) { return undefined; } -function _getThemeVersion(themeName) { - if (themeName === CONSTANTS.DEFAULT_THEME || themeName === CONSTANTS.DEFAULT_PCSS_THEME) { - return util.getJETVersion(); - } +function _getThemeInfo(themeName) { const themeJsonPath = util.destPath(path.join(config('paths').src.common, config('paths').src.themes, themeName, 'theme.json')); let themeJson; if (_checkPathExist(themeJsonPath)) { themeJson = fs.readJsonSync(themeJsonPath); - return Object.prototype.hasOwnProperty.call(themeJson, 'version') ? themeJson.version : ''; } - return ''; + + return { + versionNumber: () => { + if (themeName === CONSTANTS.DEFAULT_THEME || themeName === CONSTANTS.DEFAULT_PCSS_THEME) { + return util.getJETVersion(); + } + if (themeJson) { + return Object.prototype.hasOwnProperty.call(themeJson, 'version') ? themeJson.version : ''; + } + return ''; + }, + + generatedType: () => { + if (themeJson) { + return Object.prototype.hasOwnProperty.call(themeJson, 'generatedFileType') ? themeJson.generatedFileType : ''; + } + return ''; + } + }; } function _getDefaultPlatform() { diff --git a/oraclejet-tooling.js b/oraclejet-tooling.js index 9d5bd43..9d582f4 100644 --- a/oraclejet-tooling.js +++ b/oraclejet-tooling.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -36,6 +36,7 @@ const CONSTANTS = require('./lib/constants'); CONSTANTS.API_TASKS.REMOVE, CONSTANTS.API_TASKS.SEARCH, CONSTANTS.API_TASKS.ADDTYPESCRIPT, + CONSTANTS.API_TASKS.ADDPWA, 'serve', 'strip' ].forEach((name) => { diff --git a/package.json b/package.json index 58ce8c4..f7225a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oracle/oraclejet-tooling", - "version": "9.2.0", + "version": "10.0.0", "license": "UPL-1.0", "description": "Programmatic API to build and serve Oracle JET web and mobile applications", "keywords": [ @@ -20,19 +20,19 @@ "lodash.isfunction": "^3.0.8", "lodash.remove": "^4.7.0", "lodash.union": "^4.6.0", - "lodash.mergewith": "^4.6.0", + "lodash.mergewith": "^4.6.2", "requirejs": "^2.2.0", "terser": "^4.3.2", "gaze": "^1.1.2", "express": "~4.17.1", "connect-livereload": "^0.6.0", - "tiny-lr": "^1.0.3", - "serve-static": "^1.11.1", - "serve-index": "^1.8.0", + "tiny-lr": "^1.0.5", + "serve-static": "~1.13.0", + "serve-index": "~1.9.1", "open": "6.4.0", "svgo": "~1.2.2", "archiver": "^2.1.1", - "extract-zip": "^1.6.6", + "extract-zip": "^1.6.8", "form-data": "^2.3.2", "underscore": "^1.10.2" }, diff --git a/test/config.js b/test/config.js index d402315..920b137 100644 --- a/test/config.js +++ b/test/config.js @@ -1,40 +1,40 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ */ -var assert = require('assert'); +const assert = require('assert'); const ojet = require('../oraclejet-tooling'); const _ = require('lodash'); -describe("Config Test", () => { - it("should init empty config", () => { +describe('Config Test', () => { + it('should init empty config', () => { ojet.config(); assert(_.isEmpty(ojet.config())); }); - it("should init non-empty config", () => { - ojet.config("name", "test1"); - assert(ojet.config("name") === "test1"); + it('should init non-empty config', () => { + ojet.config('name', 'test1'); + assert(ojet.config('name') === 'test1'); }); - it("should get config", () => { - assert(ojet.config("name"), "test1"); + it('should get config', () => { + assert(ojet.config('name'), 'test1'); }); - it("should get entire config", () => { - assert(ojet.config(), {"name":"test1"}); + it('should get entire config', () => { + assert(ojet.config(), { name: 'test1' }); }); - it("should set config", () => { - ojet.config("value", "123"); - assert(ojet.config("value"), "123"); + it('should set config', () => { + ojet.config('value', '123'); + assert(ojet.config('value'), '123'); }); - it("should overwrite config", () => { - ojet.config("value", "1234"); - assert(ojet.config("value"), "1234"); + it('should overwrite config', () => { + ojet.config('value', '1234'); + assert(ojet.config('value'), '1234'); }); }); diff --git a/test/hook.js b/test/hook.js index d1a1e03..145b6d2 100644 --- a/test/hook.js +++ b/test/hook.js @@ -1,11 +1,11 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ */ -var assert = require('assert'); -var hooks = require('../lib/hookRunner'); +const assert = require('assert'); +const hooks = require('../lib/hookRunner'); const hookList = [ 'after_app_create', @@ -21,19 +21,19 @@ const hookList = [ 'before_serve' ]; -describe("Hooks Test", () => { +describe('Hooks Test', () => { before(() => { process.env.NODE_ENV = 'test'; - }); + }); hookList.forEach((element) => { it(`should have a ${element} hook`, () => { - hooks(element, {platform: "web", opts: {theme: "alta"}, buildType: "dev"}); + hooks(element, {platform: 'web', opts: {theme: 'alta'}, buildType: 'dev'}); assert(process.env, element); }); }); - it ('should not terminate invalid hooks', () => { + it('should not terminate invalid hooks', () => { assert.doesNotThrow(() => { hooks('before_build'); }); diff --git a/test/util.js b/test/util.js index a64b10c..a3bcf1d 100644 --- a/test/util.js +++ b/test/util.js @@ -1,33 +1,33 @@ /** - Copyright (c) 2015, 2020, Oracle and/or its affiliates. + Copyright (c) 2015, 2021, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ */ -var assert = require('assert'); -var path = require('path'); -var ojetUtil = require('../lib/util'); -var _ = require('lodash'); +const assert = require('assert'); +const path = require('path'); +const ojetUtil = require('../lib/util'); +const _ = require('lodash'); const util = require('../lib/util'); -describe("Util Test", () => { - it("should have templatePath", () => { - var template = util.templatePath(''); - assert(template === path.resolve("../oraclejet-tooling")); +describe('Util Test', () => { + it('should have templatePath', () => { + const template = util.templatePath(''); + assert(template === path.resolve('../oraclejet-tooling')); }); - it("should have destPath", () => { - var template = util.destPath('test1'); - assert(template === path.resolve("test1")); + it('should have destPath', () => { + const template = util.destPath('test1'); + assert(template === path.resolve('test1')); }); - describe("Config Test", () => { - it("should expect false for isCCaSassFile", () => { + describe('Config Test', () => { + it('should expect false for isCCaSassFile', () => { assert(ojetUtil.isCcaSassFile('testApp/staged-themes/alta/web/alta.css') === false); }); - it("should expect true for isCCaSassFile", () => { + it('should expect true for isCCaSassFile', () => { assert(ojetUtil.isCcaSassFile('jet-composites/mytheme.css') == true); }); });