diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eef58bd..4b0b07a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to ojet-cli -*Copyright (c) 2014, 2021 Oracle and/or its affiliates +*Copyright (c) 2014, 2022 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 42b900a..8f546c0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ # ojet-cli -Copyright (c) 2021 Oracle and/or its affiliates. +Copyright (c) 2022 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 6449074..818c975 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @oracle/ojet-cli 11.1.0 +# @oracle/ojet-cli 12.0.0 ## About the module This module contains a command line interface for Oracle JET web and hybrid mobile application development. @@ -64,11 +64,11 @@ Or view help on adding a plugin: ojet help add plugin ``` -For more information on the Oracle JET CLI, refer to the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet1110&id=homepage). +For more information on the Oracle JET CLI, refer to the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet1200&id=homepage). ## [Contributing](https://github.com/oracle/ojet-cli/blob/master/CONTRIBUTING.md) Oracle JET is an open source project. Pull Requests are currently not being accepted. See [CONTRIBUTING](https://github.com/oracle/ojet-cli/blob/master/CONTRIBUTING.md) for details. ## [License](https://github.com/oracle/ojet-cli/blob/master/LICENSE) -Copyright (c) 2021 Oracle and/or its affiliates and released under the +Copyright (c) 2022 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 113ab7e..b101ebb 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,16 @@ ## Release Notes for ojet-cli ## +### 12.0.0 + +* Add optional 'stripList' property to oraclejetconfig.json to allow providing the list of files/directories to delete instead of using .gitignore +* Add optional '--ci' flag to restore to use npm ci instead of the default npm install +* The third party library 'svgo' by oraclejet-tooling was updated. If you run into problems during an 'ojet build' surrounding 'svgo', ensure that you have version svgo 2.7.0+ installed in your application's node_modules. If in the rare case you have an svgMin section in your oraclejetconfig.json, its plugin section may need to be updated per the svgo 2.7.0 documentation +* Custom hooks have been added to run before/after package creation +* Webpack support has been expanded to both debug and release builds +* Added --installer option/installer property for oraclejetconfig.json +* Updated default typescript version to 4.5.4 +* Remove obsolete "generatorVersion" from oraclejetconfig.json + ### 11.1.0 * ojs/ojcss is supported as a name for the ojcss plugin diff --git a/bin/ojet b/bin/ojet index 88c5f22..f1b2389 100644 --- a/bin/ojet +++ b/bin/ojet @@ -4,7 +4,7 @@ const argv = require('minimist')(process.argv.slice(2)); const tasks = require('../lib/tasks'); -const utils = require('../lib/utils'); +const utils = require('../lib/util/utils'); // Extract commands const commands = [...argv._]; // Delete commands leaving only options diff --git a/common/component.js b/common/component.js index 2e1b184..423f3d1 100644 --- a/common/component.js +++ b/common/component.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,8 +8,9 @@ const fs = require('fs-extra'); const path = require('path'); -const CONSTANTS = require('../util/constants'); -const paths = require('../util/paths'); +const constants = require('../lib/util/constants'); +const paths = require('../lib/util/paths'); +const utils = require('../lib/util/utils'); const commonMessages = require('./messages'); module.exports = { @@ -23,43 +24,51 @@ module.exports = { * @param {object} utils object with helper methods * @returns {Promise} */ - writeComponentTemplate: function _writeComponentTemplate(generator, utils) { + writeComponentTemplate: function _writeComponentTemplate(generator) { return new Promise((resolve) => { const componentName = _getComponentName(generator); - const componentTemplateSrc = _getComponentTemplatePath(generator, utils); + const componentTemplateSrc = _getComponentTemplatePath(generator); const componentThemeTemplateSrc = _getComponentThemeTemplatePath('theme'); - const componentDestDirectory = _getComponentDestPath(generator, utils); + const componentDestDirectory = _getComponentDestPath(generator); const pack = generator.options.pack; // avoid overwrite component if (fs.existsSync(componentDestDirectory)) { utils.log.error(`Component with name '${componentName}' already exists.`); } - if (_isVComponent(generator, utils) && !utils.isTypescriptApplication()) { + if (_isVComponent(generator) && !utils.isTypescriptApplication()) { utils.log.error('Cannot create a vcomponent in a Javascript application. Please run \'ojet add typescript\' to add Typescript support to your application.'); } fs.ensureDirSync(componentDestDirectory); fs.copySync(componentTemplateSrc, componentDestDirectory); - fs.copySync(componentThemeTemplateSrc, componentDestDirectory); - // Copy theming template for composit components - if (utils.validCustomProperties()) { - const componentTemplateScssSrc = _getComponentThemeTemplatePath('pcss'); - fs.copySync(componentTemplateScssSrc, componentDestDirectory); + if (_isResourceComponent(generator)) { + const fileContent = constants.RESOURCE_COMPONENT_INDEX_FILE_CONTENT; + fs.writeFileSync(path.join(componentDestDirectory, `index.${utils.isTypescriptApplication() ? 'ts' : 'js'}`), fileContent); } else { - const componentTemplateCssSrc = _getComponentThemeTemplatePath('css'); - fs.copySync(componentTemplateCssSrc, componentDestDirectory); + // Only copy theming files for none-resource components + fs.copySync(componentThemeTemplateSrc, componentDestDirectory); + // Copy theming template for composit components + if (utils.validCustomProperties()) { + const componentTemplateScssSrc = _getComponentThemeTemplatePath('pcss'); + fs.copySync(componentTemplateScssSrc, componentDestDirectory); + } else { + const componentTemplateCssSrc = _getComponentThemeTemplatePath('css'); + fs.copySync(componentTemplateCssSrc, componentDestDirectory); + } } // replace tokens in template files and file names - _renameComponentTemplatePrefix(generator, utils); - _replaceComponentTemplateToken(generator, utils, pack); + _renameComponentTemplatePrefix(generator); + _replaceComponentTemplateToken(generator, pack); + _filterTsxTemplates(generator, componentDestDirectory); if (pack) { // update pack info - _updatePackInfo({ generator, utils, pack }); - } else if (_isVComponent(generator, utils)) { + _updatePackInfo({ generator, pack }); + } else if (_isVComponent(generator)) { // remove pack metadata from vcomponent template - _stripPackFromVComponet({ generator, utils, pack }); + _stripPackFromVComponent({ generator, pack }); } + // if in a typescript app, create path mapping in tsconfig.json - _addComponentToTsconfigPathMapping(generator, utils); + _addComponentToTsconfigPathMapping(generator); resolve(); }); }, @@ -73,34 +82,35 @@ module.exports = { * @param {object} generator object with build options * @param {object} utils object with helper methods */ - validateComponentName: (generator, utils) => { + validateComponentName: (generator) => { const componentName = _getComponentName(generator); const pack = generator.options.pack; let errorMessage; if (componentName === undefined || componentName === null) { errorMessage = 'Invalid component name: must not be null or undefined.'; utils.log.error(errorMessage); + } else if (!pack && _isResourceComponent(generator)) { + errorMessage = 'Cannot create resource component: please re-run the command with --pack and provide an existing JET pack'; + utils.log.error(errorMessage); } else if (!pack && (componentName !== componentName.toLowerCase() || componentName.indexOf('-') < 0 || !/^[a-z]/.test(componentName))) { errorMessage = 'Invalid component name: must be all lowercase letters and contain at least one hyphen.'; utils.log.error(errorMessage); } else if (pack && (componentName !== componentName.toLowerCase() || !/^[a-z]/.test(componentName))) { errorMessage = 'Invalid component name: must be all lowercase letters.'; utils.log.error(errorMessage); - } else if (pack && !fs.existsSync(_getPathToJETPack(generator, utils, pack))) { + } else if (pack && !fs.existsSync(_getPathToJETPack(generator, pack))) { errorMessage = 'Invalid pack name: please provide an existing JET pack'; utils.log.error(errorMessage); } }, - /** * ## checkThatAppExists * * Make sure command is being run inside of a JET app * - * @param {object} utils object with helper methods */ - checkThatAppExists: (utils) => { + checkThatAppExists: () => { const errorMessage = 'Please create an application first, then create the component from within that app.'; // eslint-disable-line max-len if (!utils.isCwdJetApp()) { utils.log.error(errorMessage); @@ -113,9 +123,8 @@ module.exports = { * Log success message indicating that component has been * created * @param {object} generator object with build options - * @param {object} utils object with helper methods */ - logSuccessMessage: (generator, utils) => { + logSuccessMessage: (generator) => { utils.log(commonMessages.appendJETPrefix(`Add component '${_getComponentName(generator)}' finished.`)); }, @@ -125,11 +134,10 @@ module.exports = { * Return the dest path of the component. * * @param {object} generator object with build options - * @param {object} utils object with helper methods */ - getComponentDestPath: (generator, utils) => ( - _getComponentDestPath(generator, utils) - ) + getComponentDestPath: (generator) => { + _getComponentDestPath(generator); + } }; /** @@ -143,20 +151,25 @@ module.exports = { * @returns {string} component template path */ -function _getComponentTemplatePath(generator, utils) { - let componentType; - if (_isVComponent(generator, utils)) { - componentType = 'tsx'; +function _getComponentTemplatePath(generator) { + const templateBasePath = path.join(__dirname, '../template'); + let componentTemplatePath; + if (_isResourceComponent(generator)) { + componentTemplatePath = path.join(templateBasePath, 'resource-component'); } else { - componentType = utils.isTypescriptApplication() ? 'ts' : 'js'; + let componentType; + if (_isVComponent(generator)) { + componentType = 'tsx'; + } else { + componentType = utils.isTypescriptApplication() ? 'ts' : 'js'; + } + componentTemplatePath = path.join( + templateBasePath, + 'component', + componentType + ); } - const componentTemplatePath = path.join( - '..', - 'template', - 'component', - componentType - ); - return path.resolve(__dirname, componentTemplatePath); + return path.resolve(componentTemplatePath); } /** @@ -176,25 +189,23 @@ function _getComponentThemeTemplatePath(directoryPath) { * ## _getPathToJETPack * * @param {object} generator object with build options - * @param {object} utils object with helper methods * @param {string} pack optional name of JET pack that the component * @returns {string} */ -function _getPathToJETPack(generator, utils, pack) { - return path.join(_getComponentsBasePath(generator, utils), pack); +function _getPathToJETPack(generator, pack) { + return path.join(_getComponentsBasePath(generator), pack); } /** * ## _getComponentDestPath * * @param {object} generator object with build options - * @param {object} utils object with helper methods * @returns {string} component destination path */ -function _getComponentDestPath(generator, utils) { +function _getComponentDestPath(generator) { const pack = generator.options.pack; const destBase = pack ? - _getPathToJETPack(generator, utils, pack) : _getComponentsBasePath(generator, utils); + _getPathToJETPack(generator, pack) : _getComponentsBasePath(generator); return path.join(destBase, _getComponentName(generator)); } @@ -204,12 +215,11 @@ function _getComponentDestPath(generator, utils) { * Replace tokens (@component-name@ & @full-component-name@) in component templates * * @param {object} generator object with build options - * @param {object} utils object with helper methods * @param {string} pack name of pack that component will belong to */ -function _replaceComponentTemplateToken(generator, utils, pack) { +function _replaceComponentTemplateToken(generator, pack) { const componentName = _getComponentName(generator); - const componentBasePath = _getComponentDestPath(generator, utils); + const componentBasePath = _getComponentDestPath(generator); const folderPaths = [ componentBasePath, path.join(componentBasePath, 'resources/nls'), @@ -262,11 +272,11 @@ function _replaceComponentTokenInFileList(componentDir, componentName, pack) { ); // replace @component-name@ with component name fileContent = fileContent.replace(new RegExp('@component-name@', 'g'), componentName); - // Camel Case component name replacements are + // Camel Case component name or class name replacements are // needed only for vcomponent .tsx files. if (file && (fileExt === '.tsx' || fileExt === '.ts')) { fileContent = fileContent.replace( - new RegExp('@camelcase-component-name@', 'g'), + new RegExp('@camelcasecomponent-name@', 'g'), _toCamelCase(componentName)); } @@ -282,7 +292,7 @@ function _replaceComponentTokenInFileList(componentDir, componentName, pack) { * @param {object} utils object with helper methods * @returns {string} component base path */ -function _getComponentsBasePath(generator, utils) { +function _getComponentsBasePath(generator) { const appDir = generator.appDir === undefined ? process.cwd() : path.resolve(generator.appDir); const _configPaths = generator.appDir === undefined @@ -310,10 +320,9 @@ function _getComponentName(generator) { * Replace token (@component@) in component file names * * @param {object} generator object with build options - * @param {object} utils object with helper methods */ -function _renameComponentTemplatePrefix(generator, utils) { - const componentBasePath = _getComponentDestPath(generator, utils); +function _renameComponentTemplatePrefix(generator) { + const componentBasePath = _getComponentDestPath(generator); const componentName = _getComponentName(generator); const folderPaths = [ componentBasePath, @@ -353,31 +362,29 @@ function _renameComponentTemplatePrefixFile(componentDir, file, componentName) { * to the provided pack * * @param {object} generator object with build options - * @param {object} utils object with helper methods * @param {string} pack name of JET pack that the component belongs to */ -function _updatePackInfo({ generator, utils, pack }) { +function _updatePackInfo({ generator, pack }) { // set pack of component - if (_isVComponent(generator, utils)) { - _setVComponentPack({ generator, utils, pack }); + if (_isVComponent(generator)) { + _setVComponentPack({ generator, pack }); } else { - _setCompositeComponentPack({ generator, utils, pack }); + _setCompositeComponentPack({ generator, pack }); } // add component to dependencies of pack - _addComponentToPackDependencies({ generator, utils, pack }); + _addComponentToPackDependencies({ generator, pack }); } /** * ## _updateVComponentPack * * @param {object} options.generator - * @param {object} options.utils * @param {object} options.pack * @param {object} options.strip */ -function _updateVComponentPack({ generator, utils, pack, strip }) { +function _updateVComponentPack({ generator, pack, strip }) { const vComponentPath = path.join( - _getComponentDestPath(generator, utils), + _getComponentDestPath(generator), `${_getComponentName(generator)}.tsx` ); let vComponentContent = fs.readFileSync(vComponentPath, 'utf-8'); @@ -394,35 +401,32 @@ function _updateVComponentPack({ generator, utils, pack, strip }) { * ## _stripPackFromVComponent * * @param {object} options.generator - * @param {object} options.utils * @param {object} options.pack */ -function _stripPackFromVComponet({ generator, utils, pack }) { - _updateVComponentPack({ generator, utils, pack, strip: true }); +function _stripPackFromVComponent({ generator, pack }) { + _updateVComponentPack({ generator, pack, strip: true }); } /** * ## _setVCompponentPack * * @param {object} options.generator - * @param {object} options.utils * @param {object} options.pack */ -function _setVComponentPack({ generator, utils, pack }) { - _updateVComponentPack({ generator, utils, pack, strip: false }); +function _setVComponentPack({ generator, pack }) { + _updateVComponentPack({ generator, pack, strip: false }); } /** * ## _setCompositeComponentPack * * @param {object} options.generator - * @param {object} options.utils * @param {object} options.pack */ -function _setCompositeComponentPack({ generator, utils, pack }) { +function _setCompositeComponentPack({ generator, pack }) { const componentJsonPath = path.join( - _getComponentDestPath(generator, utils), - CONSTANTS.COMPONENT_JSON + _getComponentDestPath(generator), + constants.COMPONENT_JSON ); const componentJson = fs.readJSONSync(componentJsonPath); componentJson.pack = pack; @@ -433,20 +437,24 @@ function _setCompositeComponentPack({ generator, utils, pack }) { * ## _addComponentToPackDependencies * * @param {object} options.generator - * @param {object} options.utils * @param {object} options.pack */ -function _addComponentToPackDependencies({ generator, utils, pack }) { +function _addComponentToPackDependencies({ generator, pack }) { const componentName = _getComponentName(generator); const packComponentJsonPath = path.join( - _getPathToJETPack(generator, utils, pack), - CONSTANTS.COMPONENT_JSON); + _getPathToJETPack(generator, pack), + constants.COMPONENT_JSON); const packComponentJson = fs.readJSONSync(packComponentJsonPath); - packComponentJson.dependencies = { - ...(packComponentJson.dependencies || {}), - [`${pack}-${componentName}`]: '1.0.0' - }; - fs.writeJSONSync(packComponentJsonPath, packComponentJson, { spaces: 2 }); + const hasDependenciesToken = utils.loadToolingUtil().hasDependenciesToken(packComponentJson); + if (!hasDependenciesToken) { + // Only add component to dependnecies if the component.json does not have the dependencies + // token. If it does, the build will take care of adding all JET pack dependencies at build time + packComponentJson.dependencies = { + ...(packComponentJson.dependencies || {}), + [`${pack}-${componentName}`]: '1.0.0' + }; + fs.writeJSONSync(packComponentJsonPath, packComponentJson, { spaces: 2 }); + } } /** @@ -456,9 +464,8 @@ function _addComponentToPackDependencies({ generator, utils, pack }) { * in the tsconfig.json file * * @param {object} generator object with build options - * @param {object} utils object with helper methods */ -function _addComponentToTsconfigPathMapping(generator, utils) { +function _addComponentToTsconfigPathMapping(generator) { // dont create path mapping if not in a typescript application // or if component will be in a pack. The pack will already have a // path mapping that the component can be accessed through i.e @@ -479,8 +486,40 @@ function _addComponentToTsconfigPathMapping(generator, utils) { * @param {object} generator object with build options * @returns {boolean} */ -function _isVComponent(generator, utils) { +function _isVComponent(generator) { const type = generator.options.type; const vcomponent = generator.options.vcomponent; - return (type && type === CONSTANTS.VCOMPONENT) || vcomponent || utils.isVDOMApplication(); + // type can now be vcomponent or resource so need to cover + // that case + if (type !== undefined) { + return type === constants.VCOMPONENT; + } + return vcomponent || utils.loadToolingUtil().isVDOMApplication(); +} + +/** + * ## _isResourceComponent + * + * @param {object} generator object with build options + * @returns {boolean} + */ +function _isResourceComponent(generator) { + return generator.options.type === constants.RESOURCE_COMPONENT; +} + +function _filterTsxTemplates(generator, destPath) { + const componentName = _getComponentName(generator); + const pathToClassBasedTemplate = path.join(destPath, `${componentName}.tsx`); + const pathToFunctionalBasedTemplate = path.join(destPath, `${componentName}-functional-template.tsx`); + if (generator.options.vcomponent === 'function') { + // .tsx now has functional based template after overwriting it + // with .tsx contents. We need to do this because, + // once the chosen template is vcomponent, then we need to use the functional + // based template and not the class based one in .tsx . However, + // the staging folder needs to have only one file: .tsx. Hence, + // the need to overwrite the file and delete .tsx after + // overwriting. + fs.renameSync(pathToFunctionalBasedTemplate, pathToClassBasedTemplate); + } + fs.removeSync(pathToFunctionalBasedTemplate); } diff --git a/common/hookRunner.js b/common/hookRunner.js index b4acfeb..d3db67a 100644 --- a/common/hookRunner.js +++ b/common/hookRunner.js @@ -1,12 +1,12 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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'; -const CONSTANTS = require('../util/constants'); +const constants = require('../lib/util/constants'); const fs = require('fs'); const path = require('path'); @@ -56,7 +56,7 @@ module.exports = { * @private */ function _getHooksConfigObj() { - const configFilePath = path.resolve(CONSTANTS.PATH_TO_HOOKS_CONFIG); + const configFilePath = path.resolve(constants.PATH_TO_HOOKS_CONFIG); if (fs.existsSync(configFilePath)) { const configFileContent = fs.readFileSync(configFilePath, 'utf8'); let configFileContentAsJson = {}; diff --git a/common/index.js b/common/index.js index 97a4689..47188b0 100644 --- a/common/index.js +++ b/common/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,10 +9,9 @@ const fs = require('fs-extra'); const path = require('path'); const commonMessages = require('./messages'); -const CONSTANTS = require('../util/constants'); -const constants = require('../lib/utils.constants'); +const constants = require('../lib/util/constants'); const app = require('../lib/scopes/app'); -const utils = require('../lib/utils'); +const utils = require('../lib/util/utils'); module.exports = { @@ -36,7 +35,7 @@ module.exports = const templateDest = path.resolve('.'); return new Promise((resolve, reject) => { function filter(src, dest) { - const isOracleJetConfigJson = path.basename(src) === CONSTANTS.APP_CONFIG_JSON; + const isOracleJetConfigJson = path.basename(src) === constants.APP_CONFIG_JSON; const isVDOMTemplate = utils.isVDOMTemplate(generator); if (isVDOMTemplate && isOracleJetConfigJson) { // for vdom templates, update the oracljetconfig.json to @@ -133,7 +132,7 @@ module.exports = validateFlags: function _validateFlags(generator) { return new Promise((resolve, reject) => { const flags = generator.options; - const SUPPORTED_FLAGS = CONSTANTS.SUPPORTED_FLAGS(flags.namespace); + const SUPPORTED_FLAGS = constants.SUPPORTED_FLAGS(flags.namespace); Object.keys(flags).forEach((key) => { if (SUPPORTED_FLAGS.indexOf(key) === -1) { if (['platforms', 'platform', 'appid', 'appname'].indexOf(key) !== -1) { @@ -149,7 +148,12 @@ module.exports = addTypescript: (generator) => { if (generator.options.typescript) { - return app.addTypescript(); + return app.addTypescript(generator.options) + .then(() => { + if (generator.options.webpack && utils.isVDOMTemplate(generator)) { + _customizeVDOMTemplateTsconfigForWebpack(); + } + }); } return Promise.resolve(); }, @@ -163,7 +167,12 @@ module.exports = addwebpack: (generator) => { if (generator.options.webpack) { - return app.addwebpack(); + return app.addwebpack(generator.options) + .then(() => { + if (utils.isVDOMTemplate(generator)) { + _customizeVDOMTemplateForWebpack(); + } + }); } return Promise.resolve(); } @@ -202,14 +211,84 @@ function _updateJSON(generator, jsonPath) { const json = fs.readJSONSync(path.resolve('.', jsonPath)); // space in app name will result in npm install failure json.name = _removeSpaceInAppName(generator.options.appname); - if (generator.options['use-global-tooling']) { + if (generator.options[constants.USE_GLOBAL_TOOLING]) { // If create wants to use the global oraclejet-tooling, // then remove the dependency link in the created package.json delete json.devDependencies[constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME]; } - fs.writeJSONSync(path.resolve('.', jsonPath), json); + utils.loadToolingUtil().writeObjectAsJsonFile(path.resolve('.', jsonPath), json); } function _removeSpaceInAppName(appName) { return appName.replace(/\s/g, '-'); } + +function _customizeVDOMTemplateTsconfigForWebpack() { + // Add resolveJsonModule and esModuleInterop to app's tsconfig.json + const pathToApp = '.'; + const pathToOraclejetConfigJson = path.join(pathToApp, 'oraclejetconfig.json'); + const oraclejetConfigJson = fs.readJSONSync(pathToOraclejetConfigJson); + const pathToTsconfigJson = path.join(pathToApp, 'tsconfig.json'); + const tsconfigJson = fs.readJSONSync(pathToTsconfigJson); + tsconfigJson.compilerOptions.rootDir = `./${oraclejetConfigJson.paths.source.common}`; + tsconfigJson.compilerOptions.outDir = `./${oraclejetConfigJson.paths.staging.web}`; + tsconfigJson.compilerOptions.typeRoots.unshift('./types'); + tsconfigJson.compilerOptions.resolveJsonModule = true; + tsconfigJson.compilerOptions.esModuleInterop = true; + tsconfigJson.compilerOptions.paths.react = [ + './node_modules/preact/compat/src/index.d.ts' + ]; + tsconfigJson.compilerOptions.paths['react-dom'] = [ + './node_modules/preact/compat/src/index.d.ts' + ]; + fs.writeJSONSync(pathToTsconfigJson, tsconfigJson, { spaces: 2 }); +} + +function _customizeVDOMTemplateForWebpack() { + const pathToApp = '.'; + const pathToOraclejetConfigJson = path.join(pathToApp, 'oraclejetconfig.json'); + const oraclejetConfigJson = fs.readJSONSync(pathToOraclejetConfigJson); + // Remove injector tokens from index.html + const pathToIndexHtml = path.join( + pathToApp, + oraclejetConfigJson.paths.source.common, + 'index.html' + ); + let indexHtmlContent = fs.readFileSync(pathToIndexHtml, { encoding: 'utf-8' }).toString(); + indexHtmlContent = indexHtmlContent.replace(//gm, '').replace(/^\s*\n/gm, ''); + indexHtmlContent = indexHtmlContent.replace(/()/, '$1\n '); + fs.outputFileSync(pathToIndexHtml, indexHtmlContent); + // Delete ./src/main.js since webpack entry point is index.ts + const pathToMainJs = path.join( + pathToApp, + oraclejetConfigJson.paths.source.common, + oraclejetConfigJson.paths.source.javascript, + 'main.js' + ); + fs.removeSync(pathToMainJs); + // Delete ./scripts since not used by webpack build + const pathToScriptsFolder = path.join(pathToApp, 'scripts'); + fs.removeSync(pathToScriptsFolder); + // Delete ./path_mapping.json since not used by webpack build + const pathToPathMappingJson = path.join(pathToApp, 'path_mapping.json'); + fs.removeSync(pathToPathMappingJson); + // Replace ./.gitignore and replace + const pathToGitIgnore = path.join(pathToApp, '.gitignore'); + const gitIgnoreContent = + `/node_modules +/${oraclejetConfigJson.paths.source.exchangeComponents} +/${oraclejetConfigJson.paths.staging.web} +.DS_Store`.trim(); + fs.outputFileSync(pathToGitIgnore, gitIgnoreContent); + // Inject ./types/components/index.ts + const pathToComponentTypes = path.join(pathToApp, 'types/components/index.d.ts'); + const componentTypesContent = ` + // Add custom element entries to preact.JSX.IntrinsicElements for custom elements + // used in JSX that do not have the required type definitions + declare namespace preact.JSX { + interface IntrinsicElements { + + } + }`; + fs.outputFileSync(pathToComponentTypes, componentTypesContent); +} diff --git a/common/messages.js b/common/messages.js index de55509..8eda557 100644 --- a/common/messages.js +++ b/common/messages.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/common/restore.js b/common/restore.js index 8ffba27..6ae0e15 100644 --- a/common/restore.js +++ b/common/restore.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,37 +10,37 @@ const execSync = require('child_process').execSync; const fs = require('fs-extra'); const path = require('path'); const commonMessages = require('./messages'); -const generatorJSON = require('../package.json'); -const CONSTANTS = require('../lib/utils.constants'); +const constants = require('../lib/util/constants'); +const utils = require('../lib/util/utils'); module.exports = { - writeOracleJetConfigFile: function _writeOracleJetConfigFile(generator, utils) { + writeOracleJetConfigFile: function _writeOracleJetConfigFile() { const destinationRoot = path.resolve('.'); - const configPath = path.resolve(destinationRoot, CONSTANTS.APP_CONFIG_JSON); + const configPath = path.resolve(destinationRoot, constants.APP_CONFIG_JSON); return new Promise((resolve) => { - const generatorVersion = generatorJSON.version; let configJson; if (!fs.existsSync(configPath)) { - utils.log(`${commonMessages.appendJETPrefix()}No ${CONSTANTS.APP_CONFIG_JSON}, writing default`); + utils.log(`${commonMessages.appendJETPrefix()}No ${constants.APP_CONFIG_JSON}, writing default`); configJson = utils.readJsonAndReturnObject(path.join( __dirname, '../../template/common', - CONSTANTS.APP_CONFIG_JSON + constants.APP_CONFIG_JSON )); } else { - utils.log(`${commonMessages.appendJETPrefix() + CONSTANTS.APP_CONFIG_JSON} file exists, updating generatorVersion`); + utils.log(`${commonMessages.appendJETPrefix() + constants.APP_CONFIG_JSON} file exists`); configJson = utils.readJsonAndReturnObject(configPath); } - configJson.generatorVersion = generatorVersion; fs.writeFileSync(configPath, JSON.stringify(configJson, null, 2)); resolve(); }); }, - npmInstall: function _npmInstall() { + npmInstall: function _npmInstall(app, opt) { return new Promise((resolve) => { - const cmd = 'npm install'; + const installer = utils.getInstallerCommand(opt); + + const cmd = `${installer.installer} ${installer.verbs.install}`; fs.ensureDirSync(path.join('node_modules')); execSync(cmd, null); resolve(); diff --git a/common/template/common.js b/common/template/common.js index f1d64e2..5f4e463 100644 --- a/common/template/common.js +++ b/common/template/common.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,8 +10,8 @@ const Admzip = require('adm-zip'); const fs = require('fs-extra'); const path = require('path'); const graphics = require('../../hybrid/graphics'); -const utils = require('../../lib/utils'); -const CONSTANTS = require('../../lib/utils.constants'); +const utils = require('../../lib/util/utils'); +const constants = require('../../lib/util/constants'); /** * Inject template files into scaffolded application depending @@ -23,7 +23,7 @@ const CONSTANTS = require('../../lib/utils.constants'); function _injectTemplateFiles({ generator, namespace }) { const pathToTemplates = path.resolve(__dirname, `../../generators/${namespace}/templates/common`); const pathToApp = path.resolve(generator.appDir); - const template = generator.options.template || CONSTANTS.BLANK_TEMPLATE; + const template = generator.options.template || constants.BLANK_TEMPLATE; function _templateFileFilter(file) { const screenPath = path.join(graphics.PATH, 'screen'); const iconPath = path.join(graphics.PATH, 'icon'); @@ -79,7 +79,7 @@ function _injectTemplateFiles({ generator, namespace }) { const { ORACLEJET_PACKAGE_JSON_NAME: oraclejet, ORACLEJET_TOOLING_PACKAGE_JSON_NAME: oraclejetTooling - } = CONSTANTS; + } = constants; let updatedAppPackageJson = false; if (!appDependencies[oraclejet]) { // app's package.json does not have an entry for @oracle/oraclejet in depedencies. diff --git a/common/template/index.js b/common/template/index.js index 087e30c..a488365 100644 --- a/common/template/index.js +++ b/common/template/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,18 +11,18 @@ const commonTemplate = require('./common'); const npmTemplate = require('./npm'); const localTemplate = require('./local'); const path = require('path'); -const util = require('../../util'); -const CONSTANTS = require('../../lib/utils.constants'); +const utils = require('../../lib/util/utils'); +const constants = require('../../lib/util/constants'); const _HYBRID = 'hybrid'; const _WEB = 'web'; -const _TEMPLATES_NPM_URL = '@oracle/oraclejet-templates@~11.1.0'; +const _TEMPLATES_NPM_URL = '@oracle/oraclejet-templates@~12.0.0'; module.exports = { - handleTemplate: function _handleTemplate(generator, utils, templateDestDirectory) { - const template = generator.options.template || CONSTANTS.BLANK_TEMPLATE; + handleTemplate: function _handleTemplate(generator, templateDestDirectory) { + const template = generator.options.template || constants.BLANK_TEMPLATE; utils.log(`Processing template: ${template}`); const templateHandler = _getHandler(generator, template, templateDestDirectory); return commonTemplate.handle(templateHandler, generator.options.namespace); @@ -38,7 +38,7 @@ function _getHandler(generator, template, templateDestDirectory) { } // Template is an existing local path, but can not point to application itself - if (templateLocalPath && CONSTANTS.NPM_TEMPLATES.indexOf(template) === -1) { + if (templateLocalPath && constants.NPM_TEMPLATES.indexOf(template) === -1) { return localTemplate.handle(generator, templateLocalPath, templateDestDirectory); } const templateSpec = _resolveTemplateSpec(generator, template); @@ -81,9 +81,9 @@ function _resolveTemplateSpec(generator, template) { } function _validateTemplateName(templateName) { - if (CONSTANTS.NPM_TEMPLATES.indexOf(templateName) < 0) { + if (constants.NPM_TEMPLATES.indexOf(templateName) < 0) { let templateList = ''; - CONSTANTS.NPM_TEMPLATES.forEach((value) => { + constants.NPM_TEMPLATES.forEach((value) => { templateList += `\n ${value}`; }); const msg = `\nA URL or one of the following names is expected: ${templateList}`; @@ -106,5 +106,5 @@ function _getLocalFileAbsolutePath(templatePath) { : path.join(process.env.HOME, templatePath.slice(1)); const absolutePath = path.isAbsolute(tempPath) ? tempPath : path.resolve(process.cwd(), tempPath); - return util.fsExistsSync(absolutePath) ? absolutePath : null; + return utils.fsExistsSync(absolutePath) ? absolutePath : null; } diff --git a/common/template/local.js b/common/template/local.js index f90a550..8442904 100644 --- a/common/template/local.js +++ b/common/template/local.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/common/template/npm.js b/common/template/npm.js index 28023b3..dfd564b 100644 --- a/common/template/npm.js +++ b/common/template/npm.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,8 +9,8 @@ const fs = require('fs-extra'); const path = require('path'); const execSync = require('child_process').execSync; -const utils = require('../../lib/utils'); -const injectorUtils = require('../../lib/utils.injectors'); +const utils = require('../../lib/util/utils'); +const injectorUtils = require('../../lib/util/injectors'); module.exports = { diff --git a/common/template/url.js b/common/template/url.js index dbba2ca..b32524b 100644 --- a/common/template/url.js +++ b/common/template/url.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,7 +8,7 @@ const commonTemplateHandler = require('./common'); const fs = require('fs-extra'); -const fetchZip = require('../../util/fetchZip'); +const fetchZip = require('../../lib/util/fetchZip'); const path = require('path'); module.exports = { diff --git a/config.js b/config.js index 9ae0c1c..33cd10a 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -521,6 +521,10 @@ const config = { password: { aliases: ['p'], description: 'The user\'s registered password' + }, + ci: { + description: 'Use npm ci instead of npm install', + default: 'false' } }, examples: [ @@ -706,6 +710,9 @@ const config = { aliases: ['h'], description: 'Print help for the command' }, + installer: { + description: 'Specify an alternate package installer such as yarn' + }, verbose: { description: 'Print details' }, diff --git a/config.json b/config.json index 3ac9399..cb8a813 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,3 @@ {"eslintDirs": ["../ojet-cli"], - "eslintFilter": ["!../ojet-cli/test/**", "!../ojet-cli/generators/**/*template*/**/*.js", "!../ojet-cli/Gruntfile.js", "!../ojet-cli/test/**/*.js", "!../ojet-cli/config/**/*.js", "!../ojet-cli/template/**/*.js"], + "eslintFilter": ["!../ojet-cli/dist/**", "!../ojet-cli/test/**", "!../ojet-cli/generators/**/*template*/**/*.js", "!../ojet-cli/Gruntfile.js", "!../ojet-cli/test/**/*.js", "!../ojet-cli/config/**/*.js", "!../ojet-cli/template/**/*.js"], "fixup": ["package.json", "index.js"]} \ No newline at end of file diff --git a/generators/add-component/index.js b/generators/add-component/index.js index 4784a8d..371987d 100644 --- a/generators/add-component/index.js +++ b/generators/add-component/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,6 +9,8 @@ const common = require('../../common'); const commonComponent = require('../../common/component'); const commonHookRunner = require('../../common/hookRunner'); +const utils = require('../../lib/util/utils'); + /** * # Entry point for 'add component' task @@ -16,20 +18,19 @@ const commonHookRunner = require('../../common/hookRunner'); * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const addComponent = { arguments: parameters, options: Object.assign({ namespace: 'add-component', componentName: parameters }, opt) }; return common.validateFlags(addComponent) - .then(() => commonComponent.checkThatAppExists(utils)) - .then(() => commonComponent.validateComponentName(addComponent, utils)) - .then(() => commonComponent.writeComponentTemplate(addComponent, utils)) + .then(() => commonComponent.checkThatAppExists) + .then(() => commonComponent.validateComponentName(addComponent)) + .then(() => commonComponent.writeComponentTemplate(addComponent)) .then(() => commonHookRunner.runAfterComponentCreateHook( - { componentPath: commonComponent.getComponentDestPath(addComponent, utils) })) - .then(() => commonComponent.logSuccessMessage(addComponent, utils)) + { componentPath: commonComponent.getComponentDestPath(addComponent) })) + .then(() => commonComponent.logSuccessMessage(addComponent)) .catch((error) => { utils.log.error(error); return Promise.reject(); diff --git a/generators/add-hybrid/index.js b/generators/add-hybrid/index.js index fecbd77..79e7b8b 100644 --- a/generators/add-hybrid/index.js +++ b/generators/add-hybrid/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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 childProcess = require('child_process'); const fs = require('fs-extra'); const path = require('path'); const common = require('../../common'); -const paths = require('../../util/paths'); +const paths = require('../../lib/util/paths'); const commonMessages = require('../../common/messages'); const commonHybrid = require('../../hybrid'); const cordovaHelper = require('../../hybrid/cordova'); const platformsHelper = require('../../hybrid/platforms'); -const util = require('../../util'); +const utils = require('../../lib/util/utils'); const _configPaths = {}; @@ -96,7 +96,7 @@ function _copyCordovaMocks() { const dest = path.resolve(`./${srcHybridPath}/${srcJsPath}/`); return new Promise((resolve, reject) => { - if (util.fsExistsSync(source)) { + if (utils.fsExistsSync(source)) { fs.copy(source, dest, (err) => { if (err) { reject(err); @@ -117,9 +117,8 @@ function _copyCordovaMocks() { * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const addHybrid = { arguments: parameters, options: Object.assign({ namespace: 'add-hybrid' }, opt) @@ -134,14 +133,14 @@ module.exports = function (parameters, opt, utils) { addHybrid.appDir = path.basename(path.resolve('.')); commonHybrid.setupHybridEnv(addHybrid); }) - .then(() => platformsHelper.getPlatforms(addHybrid, utils)) + .then(() => platformsHelper.getPlatforms(addHybrid)) .then(() => _createExtraSrcDirs(addHybrid)) .then(() => cordovaHelper.create(addHybrid)) .then(() => commonHybrid.copyHooks()) .then(() => commonHybrid.copyResources()) .then(_copyCordovaMocks) .then(() => commonHybrid.removeExtraCordovaFiles()) - .then(() => platformsHelper.addPlatforms(addHybrid, utils)) + .then(() => platformsHelper.addPlatforms(addHybrid)) .then(() => commonHybrid.updateConfigXml(addHybrid)) .then(() => { utils.log(commonMessages.appendJETPrefix('Add hybrid finished.')); diff --git a/generators/add-pcss-theme/index.js b/generators/add-pcss-theme/index.js index 420c4a9..4ab61f4 100644 --- a/generators/add-pcss-theme/index.js +++ b/generators/add-pcss-theme/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,9 +8,10 @@ const fs = require('fs-extra'); const path = require('path'); -const constants = require('../../util/constants'); +const constants = require('../../lib/util/constants'); const common = require('../../common'); -const paths = require('../../util/paths'); +const paths = require('../../lib/util/paths'); +const utils = require('../../lib/util/utils'); const commonMessages = require('../../common/messages'); const DEFAULT_THEME = 'mytheme'; @@ -199,12 +200,13 @@ function _addPcssTheme(addTheme) { _loadComponentRefrence(addTheme, themeDestPath); resolve(addTheme); } catch (err) { + utils.log.error(err); reject(); } }); } -function _updateBaseTheme(themeAdded, utils) { +function _updateBaseTheme(themeAdded) { const themeName = themeAdded.themeName; const _configpaths = paths.getConfiguredPaths(path.resolve('.')); const srcPath = _configpaths.source; @@ -221,6 +223,7 @@ function _updateBaseTheme(themeAdded, utils) { fs.writeFileSync(themeConfigPath, JSON.stringify(themeConfigJson, null, 2)); resolve(themeAdded); } catch (err) { + utils.log.error(err); reject(); } }); @@ -232,9 +235,8 @@ function _updateBaseTheme(themeAdded, utils) { * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const pcssTheme = { themeOption: Object.prototype.hasOwnProperty.call(opt, constants.PCSS_THEME_FLAG), themeOptionValue: opt[constants.PCSS_THEME_FLAG], @@ -268,7 +270,7 @@ module.exports = function (parameters, opt, utils) { return common.validateArgs(pcssTheme) .then(common.validateFlags) .then(_addPcssTheme(pcssTheme)) - .then(_updateBaseTheme(pcssTheme, utils)) + .then(_updateBaseTheme(pcssTheme)) .then(() => { utils.log.success(commonMessages.appendJETPrefix(`${pcssTheme.themeName} theme added, with css variables support.`)); }) diff --git a/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss b/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss index daee183..b496ad5 100644 --- a/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss +++ b/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss @@ -3,19 +3,19 @@ // If you uncomment other imports please set generatedFileType to 'combined' in theme.json. // Please see the developer guide link below for more information // http://www.oracle.com/pls/topic/lookup?ctx=jetlatest&id=GUID-12A65AC0-4784-46FE-AC8C-09FA509737E4 - + // import SASS custom variable overrides // @import "_<%= themename %>.sass.settings.scss"; - + // Imports all jet components styles // @import "<%= importcomponents %>"; - + // To optimize performance, consider commenting out the above oj-all-components // import and uncomment _<%= themename %>.components.scss below. // Then in _<%= themename %>.components.scss uncomment only the component // imports that your application needs. - + // @import "_<%= themename %>.optimize-components.scss"; - + // import CSS Custom properties -@import "_<%= themename %>.cssvars.settings.scss"; \ No newline at end of file +@import "_<%= themename %>.cssvars.settings.scss"; diff --git a/generators/add-theme/index.js b/generators/add-theme/index.js index 12d4205..0613f55 100644 --- a/generators/add-theme/index.js +++ b/generators/add-theme/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,9 +8,10 @@ const fs = require('fs-extra'); const path = require('path'); -const constants = require('../../util/constants'); +const constants = require('../../lib/util/constants'); const common = require('../../common'); -const paths = require('../../util/paths'); +const paths = require('../../lib/util/paths'); +const utils = require('../../lib/util/utils'); const commonMessages = require('../../common/messages'); const DEFAULT_THEME = 'mytheme'; @@ -25,9 +26,8 @@ const THEMENAME_TOKEN = '<%= themename %>'; * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const addTheme = { themeName: parameters, arguments: [parameters], diff --git a/generators/app/index.js b/generators/app/index.js index 4831737..49fa608 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,13 +12,14 @@ const commonMessages = require('../../common/messages'); const commonRestore = require('../../common/restore'); const templateHandler = require('../../common/template'); const scopesApp = require('../../lib/scopes/app'); +const utils = require('../../lib/util/utils'); const fs = require('fs'); const path = require('path'); -function _writeTemplate(generator, utils) { +function _writeTemplate(generator) { return new Promise((resolve, reject) => { const appDirectory = path.resolve(path.join(generator.appDir, 'src')); - templateHandler.handleTemplate(generator, utils, appDirectory) + templateHandler.handleTemplate(generator, appDirectory) .then(() => { resolve(); }) @@ -34,9 +35,8 @@ function _writeTemplate(generator, utils) { * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const app = { options: Object.assign({ namespace: 'app' }, opt), appDir: parameters @@ -52,17 +52,17 @@ module.exports = function (parameters, opt, utils) { .then(() => common.writeCommonTemplates(app)) .then(() => common.writeGitIgnore()) .then(() => common.switchFromAppDirectory()) - .then(() => _writeTemplate(app, utils)) + .then(() => _writeTemplate(app)) .then(() => common.switchToAppDirectory(app)) .then(() => common.updatePackageJSON(app)) .then(() => { utils.log(commonMessages.scaffoldComplete()); if (!app.options.norestore) { - return commonRestore.npmInstall(app) - .then(() => commonRestore.writeOracleJetConfigFile(app, utils)) - .then(() => common.addTypescript(app)) + return commonRestore.npmInstall(app, opt) + .then(() => commonRestore.writeOracleJetConfigFile()) + .then(() => common.addTypescript(app, opt)) .then(() => common.addpwa(app)) - .then(() => common.addwebpack(app)) + .then(() => common.addwebpack(app, opt)) .then(scopesApp.addComponents) .then(commonHookRunner.runAfterAppCreateHook) .then(() => { diff --git a/generators/app/templates/common/package.json b/generators/app/templates/common/package.json index a26427b..1365bf8 100644 --- a/generators/app/templates/common/package.json +++ b/generators/app/templates/common/package.json @@ -3,13 +3,13 @@ "version": "1.0.0", "description": "An Oracle JavaScript Extension Toolkit(JET) web app", "dependencies": { - "@oracle/oraclejet": "~11.1.0" + "@oracle/oraclejet": "~12.0.0" }, "devDependencies": { "fs-extra": "^8.1.0", "glob": "^7.1.1", "underscore": "^1.10.2", - "@oracle/oraclejet-tooling": "~11.1.0" + "@oracle/oraclejet-tooling": "~12.0.0" }, "engines": { "node": ">=12.21.0" diff --git a/generators/hybrid/index.js b/generators/hybrid/index.js index fda33ae..b03cd17 100644 --- a/generators/hybrid/index.js +++ b/generators/hybrid/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -7,7 +7,7 @@ 'use strict'; const exec = require('child_process').exec; -const paths = require('../../util/paths'); +const paths = require('../../lib/util/paths'); const path = require('path'); const templateHandler = require('../../common/template/'); const common = require('../../common'); @@ -17,6 +17,7 @@ const commonMessages = require('../../common/messages'); const commonRestore = require('../../common/restore'); const cordovaHelper = require('../../hybrid/cordova'); const platformsHelper = require('../../hybrid/platforms'); +const utils = require('../../lib/util/utils'); const fs = require('fs-extra'); /* @@ -49,11 +50,11 @@ function _invokeCordovaPrepare(generator) { }); } -function _writeTemplate(generator, utils) { +function _writeTemplate(generator) { return new Promise((resolve, reject) => { const appDir = generator.appDir; const appDirectory = path.resolve(appDir, 'src'); - templateHandler.handleTemplate(generator, utils, appDirectory) + templateHandler.handleTemplate(generator, appDirectory) .then(() => { resolve(); }) @@ -69,9 +70,8 @@ function _writeTemplate(generator, utils) { * @public * @param {Array} parameters * @param {Object} options - * @param {utils} utility module */ -module.exports = function (parameters, opt, utils) { +module.exports = function (parameters, opt) { const app = { options: Object.assign({ namespace: 'hybrid' }, opt), appDir: parameters @@ -85,7 +85,7 @@ module.exports = function (parameters, opt, utils) { commonHybrid.setupHybridEnv(app); fs.mkdirSync(path.resolve(app.appDir)); }) - .then(() => platformsHelper.getPlatforms(app, utils)) + .then(() => platformsHelper.getPlatforms(app)) .then(() => common.switchToAppDirectory(app)) .then(() => common.writeCommonTemplates(app)) .then(() => common.writeGitIgnore()) @@ -93,19 +93,19 @@ module.exports = function (parameters, opt, utils) { .then(() => commonHybrid.copyResources()) .then(() => commonHybrid.removeExtraCordovaFiles()) .then(() => common.switchFromAppDirectory()) - .then(() => _writeTemplate(app, utils)) + .then(() => _writeTemplate(app)) .then(() => common.switchToAppDirectory(app)) .then(() => common.updatePackageJSON(app)) - .then(() => platformsHelper.addPlatforms(app, utils)) + .then(() => platformsHelper.addPlatforms(app)) .then(() => commonHybrid.updateConfigXml(app)) .then(() => { utils.log(commonMessages.scaffoldComplete()); if (!app.options.norestore) { - return commonRestore.npmInstall(app) + return commonRestore.npmInstall(app, opt) .then(() => commonHybrid.copyHooks()) - .then(() => commonRestore.writeOracleJetConfigFile(app, utils)) + .then(() => commonRestore.writeOracleJetConfigFile()) .then(() => _invokeCordovaPrepare(app)) - .then(() => common.addTypescript(app)) + .then(() => common.addTypescript(app, opt)) .then(() => commonHookRunner.runAfterAppCreateHook()) .then(() => utils.log(commonMessages.restoreComplete( app.options.invokedByRestore, diff --git a/generators/hybrid/templates/common/package.json b/generators/hybrid/templates/common/package.json index a9a73d6..7b63c59 100644 --- a/generators/hybrid/templates/common/package.json +++ b/generators/hybrid/templates/common/package.json @@ -3,13 +3,13 @@ "version": "1.0.0", "description": "An Oracle JavaScript Extension Toolkit (JET) mobile app", "dependencies": { - "@oracle/oraclejet": "~11.1.0" + "@oracle/oraclejet": "~12.0.0" }, "devDependencies": { "fs-extra": "^8.1.0", "glob": "^7.1.1", "underscore": "^1.10.2", - "@oracle/oraclejet-tooling": "~11.1.0" + "@oracle/oraclejet-tooling": "~12.0.0" }, "engines": { "node": ">=12.21.0" diff --git a/generators/hybrid/templates/common/src/js/cordovaMocks.js b/generators/hybrid/templates/common/src/js/cordovaMocks.js index 8323fda..6f5b443 100644 --- a/generators/hybrid/templates/common/src/js/cordovaMocks.js +++ b/generators/hybrid/templates/common/src/js/cordovaMocks.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/hybrid/cordova.js b/hybrid/cordova.js index a89499f..cb36f93 100644 --- a/hybrid/cordova.js +++ b/hybrid/cordova.js @@ -1,13 +1,13 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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'; -const paths = require('../util/paths'); -const utils = require('../lib/utils'); +const paths = require('../lib/util/paths'); +const utils = require('../lib/util/utils'); const fs = require('fs-extra'); const path = require('path'); const childProcess = require('child_process'); diff --git a/hybrid/graphics.js b/hybrid/graphics.js index dc22e14..22df1cd 100644 --- a/hybrid/graphics.js +++ b/hybrid/graphics.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/hybrid/index.js b/hybrid/index.js index fbab2ab..e457437 100644 --- a/hybrid/index.js +++ b/hybrid/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,13 +8,13 @@ const fs = require('fs-extra'); const path = require('path'); -const constants = require('../util/constants'); +const constants = require('../lib/util/constants'); const commonMessages = require('../common/messages'); const DOMParser = require('xmldom').DOMParser; const endOfLine = require('os').EOL; const graphics = require('./graphics'); -const paths = require('../util/paths'); -const utils = require('../lib/utils'); +const paths = require('../lib/util/paths'); +const utils = require('../lib/util/utils'); const ORACLEJET_APP_ID = 'org.oraclejet.'; const iOSPlugins = ['cordova-plugin-wkwebview-file-xhr', diff --git a/hybrid/platforms.js b/hybrid/platforms.js index 93c3dc0..9722a57 100644 --- a/hybrid/platforms.js +++ b/hybrid/platforms.js @@ -1,15 +1,16 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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'; -const constants = require('../util/constants'); +const constants = require('../lib/util/constants'); const path = require('path'); -const paths = require('../util/paths'); +const paths = require('../lib/util/paths'); const commonMessages = require('../common/messages'); +const utils = require('../lib/util/utils'); const inquirer = require('inquirer'); const childProcess = require('child_process'); @@ -52,14 +53,14 @@ const TEST_COMMAND = module.exports = { - getPlatforms: function _getPlatforms(generatorArg, utils) { + getPlatforms: function _getPlatforms(generatorArg) { const generator = generatorArg; if (generator.options.platforms || generator.options.platform) { // platforms = generator.options.platforms || generator.options.platform; return new Promise((resolve) => { - _validatePlatforms(generator, utils) + _validatePlatforms(generator) .then((processedPlatforms) => { generator._platformsToInstall = processedPlatforms; resolve(generator); @@ -69,7 +70,7 @@ module.exports = return new Promise((resolve, reject) => { // if platforms option is not provided do prompt - _testPlatforms(constants.SUPPORTED_HYBRID_PLATFORMS, utils) + _testPlatforms(constants.SUPPORTED_HYBRID_PLATFORMS) .then((possiblePlatforms) => { if (!possiblePlatforms.length) { resolve(generator); @@ -93,7 +94,7 @@ module.exports = }); }, - addPlatforms: function _addPlatforms(generator, utils) { + addPlatforms: function _addPlatforms(generator) { const platforms = generator._platformsToInstall; // always add the browser platform @@ -129,12 +130,12 @@ module.exports = * @param {type} generator * @return {Promise} */ -function _validatePlatforms(generator, utils) { +function _validatePlatforms(generator) { const platformOptions = generator.options.platforms || generator.options.platform; - const platforms = _processPlatformOptions(platformOptions, utils); + const platforms = _processPlatformOptions(platformOptions); return new Promise((resolve) => { - _testPlatforms(platforms, utils) + _testPlatforms(platforms) .then((availablePlatforms) => { const failedPlatforms = []; platforms.forEach((entry) => { @@ -164,9 +165,9 @@ function _validatePlatforms(generator, utils) { * @param {Array} platforms array of requested platforms * @return {Promise} a promise object */ -function _testPlatforms(platforms, utils) { +function _testPlatforms(platforms) { const filteredTestCommands = _getFilteredTestCommands(platforms); - const platformTests = _getPlatformTests(filteredTestCommands, utils); + const platformTests = _getPlatformTests(filteredTestCommands); // note there exists no reject since want to test all the filteredTestCommands // and when there are errors (i.e. test command fails) it will resolve w/o that platform return new Promise((resolve) => { @@ -190,7 +191,7 @@ function _filterPromptingPlatforms(promptPlatforms) { promptPlatforms.indexOf(type.value) !== -1); } -function _processPlatformOptions(platforms, utils) { +function _processPlatformOptions(platforms) { if (!platforms) { return []; } @@ -216,11 +217,11 @@ function _getFilteredTestCommands(platforms) { return TEST_COMMAND.filter(type => platforms.indexOf(type.platform) !== -1); } -function _getPlatformTests(platforms, utils) { +function _getPlatformTests(platforms) { const platformTests = []; platforms.forEach((info) => { - platformTests.push(_createPlatformTest(info, utils)); + platformTests.push(_createPlatformTest(info)); }); return platformTests; diff --git a/lib/scopes/app.js b/lib/scopes/app.js index 37a0d3e..db3ba68 100644 --- a/lib/scopes/app.js +++ b/lib/scopes/app.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -15,11 +15,10 @@ const path = require('path'); // Oracle const config = require('../../config'); -const CONSTANTS = require('../utils.constants'); -const paths = require('../utils.paths'); -const pckg = require('../../package.json'); +const constants = require('../util/constants'); +const paths = require('../util/paths'); const tooling = require('../tooling'); -const utils = require('../utils'); +const utils = require('../util/utils'); const addTheme = require('../../generators/add-theme'); const addPcssTheme = require('../../generators/add-pcss-theme'); const addHybrid = require('../../generators/add-hybrid'); @@ -41,38 +40,38 @@ const app = module.exports; * @param {string} [parameter] * @param {Object} [options] */ -app.create = function (parameter, options, util) { +app.create = function (parameter, options) { const opts = options; if (opts && utils.hasProperty(opts, 'hybrid')) { // Deleting 'hybrid' flag delete opts.hybrid; - return addAppHybrid(parameter, opts, util); + return addAppHybrid(parameter, opts); } // Deleting 'web' flag if (opts && utils.hasProperty(opts, 'web')) { delete opts.web; } - return addApp(parameter, opts, util); + return addApp(parameter, opts); }; -app.createComponent = function (parameter, options, util) { - return addComponent(parameter, options, util); +app.createComponent = function (parameter, options) { + return addComponent(parameter, options); }; -app.createTheme = function (parameter, options, util) { +app.createTheme = function (parameter, options) { if (!utils.validCustomProperties()) { - return addTheme(parameter, options, util); + return addTheme(parameter, options); } - return addPcssTheme(parameter, options, util); + return addPcssTheme(parameter, options); }; -app.addHybrid = function (parameters, options, util) { - return addHybrid(parameters, options, util); +app.addHybrid = function (parameters, options) { + return addHybrid(parameters, options); }; -app.addSass = function () { +app.addSass = function (options) { const toolingModule = utils.loadTooling(); - return toolingModule.addsass() + return toolingModule.addsass(options) .then(() => { utils.log.success('add sass complete'); }) @@ -82,9 +81,9 @@ app.addSass = function () { }); }; -app.addPcss = function () { +app.addPcss = function (options) { const toolingModule = utils.loadTooling(); - return toolingModule.addpcss() + return toolingModule.addpcss(options) .then(() => { utils.log.success('add pcss complete'); }) @@ -94,9 +93,9 @@ app.addPcss = function () { }); }; -app.addTypescript = function () { +app.addTypescript = function (options) { const toolingModule = utils.loadTooling(); - return toolingModule.addtypescript() + return toolingModule.addtypescript(options) .then(() => { utils.log.success('add typescript complete'); }) @@ -118,9 +117,9 @@ app.addpwa = function () { }); }; -app.addwebpack = function () { +app.addwebpack = function (options) { const toolingModule = utils.loadTooling(); - return toolingModule.addwebpack() + return toolingModule.addwebpack(options) .then(() => { utils.log.success('add webpack complete'); }) @@ -140,17 +139,18 @@ app.restore = function (options) { process.env.options = JSON.stringify(options); // if the project contains cordova's config.xml, consider it to be a hybrid; otherwise web const cordovaDir = paths.getConfiguredPaths(process.cwd()).stagingHybrid; - const isHybrid = fs.existsSync(path.resolve(cordovaDir, CONSTANTS.CORDOVA_CONFIG_XML)); - const appType = CONSTANTS.APP_TYPE; + const isHybrid = fs.existsSync(path.resolve(cordovaDir, constants.CORDOVA_CONFIG_XML)); + + const appType = constants.APP_TYPE; const restoreType = isHybrid ? appType.HYBRID : appType.WEB; if (restoreType === 'web') { - return _restoreWeb(); + return _restoreWeb(options); } - return _restoreHybrid(); + return _restoreHybrid(options); }; app.addComponents = function () { - const configPath = path.join(process.cwd(), CONSTANTS.APP_CONFIG_JSON); + const configPath = path.join(process.cwd(), constants.APP_CONFIG_JSON); const configJson = utils.readJsonAndReturnObject(configPath); const componentList = configJson.components; if (!utils.isObjectEmpty(componentList)) { @@ -172,9 +172,10 @@ app.addComponents = function () { * ## _restoreWeb * * @private + * @param {Object} [options] */ -function _restoreWeb() { - return _npmInstall() +function _restoreWeb(options) { + return _npmInstall(options) .then(_writeOracleJetConfigFile) .then(app.addComponents) .then(_runAfterAppRestoreHook) @@ -191,10 +192,13 @@ function _restoreWeb() { * ## _npmInstall * * @private + * @param {Object} [options] */ -function _npmInstall() { - utils.log('Performing \'npm install\' may take a bit.'); - return utils.spawn('npm', ['install']); +function _npmInstall(options) { + const installer = utils.getInstallerCommand(options); + + utils.log(`Performing '${installer.installer} ${installer.verbs.install}' may take a bit.`); + return utils.spawn(installer.installer, [installer.verbs.install]); } /** @@ -204,22 +208,20 @@ function _npmInstall() { */ function _writeOracleJetConfigFile() { return new Promise((resolve) => { - utils.log(`Checking '${CONSTANTS.APP_CONFIG_JSON}'config file.`); - const configPath = path.join(process.cwd(), CONSTANTS.APP_CONFIG_JSON); - const generatorVersion = pckg.version; + utils.log(`Checking '${constants.APP_CONFIG_JSON}'config file.`); + const configPath = path.join(process.cwd(), constants.APP_CONFIG_JSON); let configJson; if (!fs.existsSync(configPath)) { utils.log('No config file. Adding the default.'); configJson = utils.readJsonAndReturnObject(path.join( __dirname, '../../template/common', - CONSTANTS.APP_CONFIG_JSON + constants.APP_CONFIG_JSON )); } else { - utils.log(`'${CONSTANTS.APP_CONFIG_JSON}' file exists. Adding/updating version.`); + utils.log(`'${constants.APP_CONFIG_JSON}' file exists.`); configJson = utils.readJsonAndReturnObject(configPath); } - configJson.generatorVersion = generatorVersion; fs.writeFileSync(configPath, JSON.stringify(configJson, null, 2)); resolve(); }); @@ -229,9 +231,10 @@ function _writeOracleJetConfigFile() { * ## _restoreHybrid * * @private + * @param {Object} [options] */ -function _restoreHybrid() { - return _npmInstall() +function _restoreHybrid(options) { + return _npmInstall(options) .then(_writeOracleJetConfigFile) .then(app.addComponents) .then(_invokeCordovaPrepare) @@ -299,7 +302,7 @@ function _runAfterAppRestoreHook() { * @private */ function _getHooksConfigObj() { - const configFilePath = path.resolve(CONSTANTS.PATH_TO_HOOKS_CONFIG); + const configFilePath = path.resolve(constants.PATH_TO_HOOKS_CONFIG); if (fs.existsSync(configFilePath)) { const hooksObj = utils.readJsonAndReturnObject(configFilePath); return hooksObj.hooks || {}; diff --git a/lib/scopes/platform.plugin.js b/lib/scopes/platform.plugin.js index 7dce20d..9ef6afa 100644 --- a/lib/scopes/platform.plugin.js +++ b/lib/scopes/platform.plugin.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,8 +11,8 @@ /** * ## Dependencies */ -const utils = require('../utils'); -const CONSTANTS = require('../utils.constants'); +const utils = require('../util/utils'); +const constants = require('../util/constants'); /** * # Platform @@ -48,7 +48,7 @@ module.exports = function (task, scope, param, options) { function _validatePlatform(scope, param) { if (scope === 'platform') { param.forEach((platform) => { - if (CONSTANTS.SUPPORTED_PLATFORMS.indexOf(platform) < 0) utils.log.error(`Platform ${platform} not supported!`); + if (constants.SUPPORTED_PLATFORMS.indexOf(platform) < 0) utils.log.error(`Platform ${platform} not supported!`); }); } } diff --git a/lib/tasks/add.js b/lib/tasks/add.js index 33aaf96..e2b97cd 100644 --- a/lib/tasks/add.js +++ b/lib/tasks/add.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -14,7 +14,7 @@ const app = require('../scopes/app'); const config = require('../../config'); const platformAndPlugin = require('../scopes/platform.plugin'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'add' task @@ -44,7 +44,7 @@ module.exports = function (scope, parameters, options) { utils.log.error(utils.toNotSupportedMessage(`${task} ${scope} ${parameter}`)); return Promise.reject(); } - return app.addHybrid(parameters, options, utils); + return app.addHybrid(parameters, options); case scopes.platform.name: case scopes.plugin.name: { utils.ensureParameters(parameters); @@ -63,7 +63,7 @@ module.exports = function (scope, parameters, options) { utils.log.error(utils.toNotSupportedMessage(`${task} ${scope} ${parameter}`)); return Promise.reject(); } - return app.addSass(); + return app.addSass(options); case scopes.theming.name: utils.validateParametersCount(parameters, 0); utils.ensureJetApp(); @@ -71,7 +71,7 @@ module.exports = function (scope, parameters, options) { utils.log.error(utils.toNotSupportedMessage(`${task} ${scope} ${parameter}`)); return Promise.reject(); } - return app.addPcss(); + return app.addPcss(options); case scopes.typescript.name: utils.validateParametersCount(parameters, 0); utils.ensureJetApp(); @@ -79,7 +79,7 @@ module.exports = function (scope, parameters, options) { utils.log.error(utils.toNotSupportedMessage(`${task} ${scope} ${parameter}`)); return Promise.reject(); } - return app.addTypescript(); + return app.addTypescript(options); case scopes.pwa.name: utils.validateParametersCount(parameters, 0); utils.ensureJetApp(); @@ -95,7 +95,7 @@ module.exports = function (scope, parameters, options) { utils.log.error(utils.toNotSupportedMessage(`${task} ${scope} ${parameter}`)); return Promise.reject(); } - return app.addwebpack(); + return app.addwebpack(options); case scopes.web.name: utils.validateParametersCount(parameters, 0); utils.ensureJetHybridApp(); diff --git a/lib/tasks/build.serve.js b/lib/tasks/build.serve.js index 6e22961..478ad06 100644 --- a/lib/tasks/build.serve.js +++ b/lib/tasks/build.serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,8 +11,8 @@ */ const app = require('../scopes/app'); const config = require('../../config'); -const utils = require('../utils'); -const CONSTANTS = require('../utils.constants'); +const utils = require('../util/utils'); +const constants = require('../util/constants'); /** * # Switch for 'build' and 'serve' tasks @@ -40,7 +40,7 @@ module.exports = function (task, scope, parameters, options) { case undefined: return app.runTooling(task, scope, parameter, options); default: - if (CONSTANTS.SUPPORTED_PLATFORMS.indexOf(scope) > -1) { + if (constants.SUPPORTED_PLATFORMS.indexOf(scope) > -1) { // ojet (build|serve) (web|ios|android|windows) return app.runTooling(task, scope, parameter, options); } diff --git a/lib/tasks/clean.js b/lib/tasks/clean.js index dd41506..c9cf00c 100644 --- a/lib/tasks/clean.js +++ b/lib/tasks/clean.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -14,8 +14,8 @@ // Oracle const config = require('../../config'); -const CONSTANTS = require('../utils.constants'); -const utils = require('../utils'); +const constants = require('../util/constants'); +const utils = require('../util/utils'); /** * # Invoked platform clean @@ -33,7 +33,7 @@ module.exports = function (scope, parameters) { // Oracle command libs let tooling; try { - tooling = require(CONSTANTS.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line + tooling = require(constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line } catch (e) { utils.log.error('Your JET project does not have oraclejet-tooling installed.'); return Promise.reject(); @@ -43,7 +43,7 @@ module.exports = function (scope, parameters) { case config.tasks.clean.scopes.app.name: case undefined: default: - if (CONSTANTS.SUPPORTED_PLATFORMS.indexOf(platform) > -1) { + if (constants.SUPPORTED_PLATFORMS.indexOf(platform) > -1) { return tooling.clean.platform(platform); } utils.log.error(`Invalid platform ${platform}`); diff --git a/lib/tasks/configure.js b/lib/tasks/configure.js index f7f61e3..8048541 100644 --- a/lib/tasks/configure.js +++ b/lib/tasks/configure.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,8 +18,8 @@ const path = require('path'); // Oracle const config = require('../../config'); -const CONSTANTS = require('../utils.constants'); -const utils = require('../utils'); +const constants = require('../util/constants'); +const utils = require('../util/utils'); /** * # Switch for 'configure' task @@ -37,17 +37,17 @@ module.exports = function (task, scope, parameters, options) { if (options && utils.hasProperty(options, config.exchangeUrlParam)) { if (utils.hasGlobalOption(options)) { // Ensure storage dir - const storeDir = path.join(homedir, CONSTANTS.OJET_LOCAL_STORAGE_DIR); + const storeDir = path.join(homedir, constants.OJET_LOCAL_STORAGE_DIR); if (!fs.existsSync(storeDir)) { fs.mkdirSync(storeDir, { recursive: true }); } const data = {}; - data[CONSTANTS.EXCHANGE_GLOBAL_URL_KEY] = options[config.exchangeUrlParam]; + data[constants.EXCHANGE_GLOBAL_URL_KEY] = options[config.exchangeUrlParam]; // Write file const content = JSON.stringify(data, null, 2); - const pathToFile = path.join(storeDir, CONSTANTS.EXCHANGE_URL_FILE); + const pathToFile = path.join(storeDir, constants.EXCHANGE_URL_FILE); try { fs.writeFileSync(pathToFile, content); } catch (error) { diff --git a/lib/tasks/create.js b/lib/tasks/create.js index 28a6b6a..bd0c4da 100644 --- a/lib/tasks/create.js +++ b/lib/tasks/create.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,7 +11,7 @@ */ const app = require('../scopes/app'); const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'create' task @@ -30,13 +30,13 @@ module.exports = function (scope, parameters, options) { if (!utils.ensureJetApp()) { return Promise.reject(); } - return app.createTheme(parameter, options, utils); + return app.createTheme(parameter, options); } case scopes.component.name: { if (!utils.ensureJetApp()) { return Promise.reject(); } - return app.createComponent(parameter, options, utils); + return app.createComponent(parameter, options); } case scopes.pack.name: { if (!utils.ensureJetApp()) { @@ -47,12 +47,12 @@ module.exports = function (scope, parameters, options) { } case scopes.app.name: // ojet create app TestApp: scope = app, parameters = [TestApp] - return app.create(parameter, options, utils); + return app.create(parameter, options); case undefined: // ojet create TestApp (API): scope = undefined, parameters = [TestApp] - return app.create(parameter, options, utils); + return app.create(parameter, options); default: // ojet create TestApp (CLI): scope = TestApp, parameters = [] - return app.create(scope, options, utils); + return app.create(scope, options); } }; diff --git a/lib/tasks/help.js b/lib/tasks/help.js index dec53e5..4a2eb22 100644 --- a/lib/tasks/help.js +++ b/lib/tasks/help.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,7 +12,7 @@ * ## Dependencies */ const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Help diff --git a/lib/tasks/index.js b/lib/tasks/index.js index cd09804..f10a95f 100644 --- a/lib/tasks/index.js +++ b/lib/tasks/index.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,7 +10,7 @@ const config = require('../../config'); const pckg = require('../../package.json'); -const utils = require('../utils'); +const utils = require('../util/utils'); const add = require('./add'); const buildAndServe = require('./build.serve'); const clean = require('./clean'); diff --git a/lib/tasks/list.js b/lib/tasks/list.js index c5aa431..c1ebacf 100644 --- a/lib/tasks/list.js +++ b/lib/tasks/list.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,7 +13,7 @@ */ const config = require('../../config'); const platformAndPlugin = require('../scopes/platform.plugin'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'list' task diff --git a/lib/tasks/package.js b/lib/tasks/package.js index 201b043..567a9b5 100644 --- a/lib/tasks/package.js +++ b/lib/tasks/package.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,7 +12,7 @@ * ## Dependencies */ const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Package * diff --git a/lib/tasks/publish.js b/lib/tasks/publish.js index 2d9d436..6250d39 100644 --- a/lib/tasks/publish.js +++ b/lib/tasks/publish.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,7 +12,7 @@ * ## Dependencies */ const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'publish' task diff --git a/lib/tasks/remove.js b/lib/tasks/remove.js index da376b9..d931a53 100644 --- a/lib/tasks/remove.js +++ b/lib/tasks/remove.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,7 +13,7 @@ */ const config = require('../../config'); const platformAndPlugin = require('../scopes/platform.plugin'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'remove' task diff --git a/lib/tasks/restore.js b/lib/tasks/restore.js index 9a8d27e..c788a94 100644 --- a/lib/tasks/restore.js +++ b/lib/tasks/restore.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,7 +12,7 @@ // Oracle const app = require('../scopes/app'); const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'restore' task diff --git a/lib/tasks/search.js b/lib/tasks/search.js index c8558af..efc4185 100644 --- a/lib/tasks/search.js +++ b/lib/tasks/search.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,7 +13,7 @@ */ // Oracle const config = require('../../config'); -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Switch for 'search' task diff --git a/lib/tasks/strip.js b/lib/tasks/strip.js index 7c90bc1..fa76bf1 100644 --- a/lib/tasks/strip.js +++ b/lib/tasks/strip.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -14,10 +14,10 @@ // Node const fs = require('fs'); const path = require('path'); -const CONSTANTS = require('../utils.constants'); +const constants = require('../util/constants'); // Oracle -const utils = require('../utils'); +const utils = require('../util/utils'); /** * # Invoke 'strip' task * @@ -29,14 +29,14 @@ module.exports = function (parameters) { return Promise.reject(); } utils.validateParametersCount(parameters, 0); - const toolingPath = path.join(process.cwd(), CONSTANTS.TOOLING_PATH); + const toolingPath = path.join(process.cwd(), constants.TOOLING_PATH); if (fs.existsSync(toolingPath)) { const tooling = require(toolingPath); // eslint-disable-line return tooling.strip(); } try { // Use global install if available - const tooling = require(CONSTANTS.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line + const tooling = require(constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line return tooling.strip(); } catch (e) { // Don't error diff --git a/lib/tooling/build.js b/lib/tooling/build.js index cafc96a..a78b675 100644 --- a/lib/tooling/build.js +++ b/lib/tooling/build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,8 +9,8 @@ /* * Options and Arguments processing before Invoking tooling APIs */ -const utils = require('../utils'); -const CONSTANTS = require('../utils.constants'); +const utils = require('../util/utils'); +const constants = require('../util/constants'); module.exports = function (platform, options) { utils.validateOptions(options, 'build'); @@ -47,7 +47,11 @@ module.exports = function (platform, options) { // pass on no-optimize-flag // eslint-disable-next-line max-len - buildOptions[CONSTANTS.OMIT_COMPONENT_VERSION_FLAG] = options[CONSTANTS.OMIT_COMPONENT_VERSION_FLAG]; + buildOptions[constants.OMIT_COMPONENT_VERSION_FLAG] = options[constants.OMIT_COMPONENT_VERSION_FLAG]; + + // do not pass buildOptions.sass down because it will override + // defaultconfig.build.sass during the options merge process + delete buildOptions.sass; const tooling = utils.loadTooling(); return tooling.build(buildOptions.platform, buildOptions) diff --git a/lib/tooling/index.js b/lib/tooling/index.js index 4754a0b..a09dd3a 100644 --- a/lib/tooling/index.js +++ b/lib/tooling/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,7 +8,7 @@ const build = require('./build'); const serve = require('./serve'); -const utils = require('../utils'); +const utils = require('../util/utils'); /* * Options and Arguments processing before Invoking tooling APIs */ diff --git a/lib/tooling/serve.js b/lib/tooling/serve.js index af0f8ac..a309ad8 100644 --- a/lib/tooling/serve.js +++ b/lib/tooling/serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,8 +10,8 @@ * # Dependencies */ -const utils = require('../utils'); -const CONSTANTS = require('../utils.constants'); +const utils = require('../util/utils'); +const constants = require('../util/constants'); /** * # ojet serve command @@ -67,7 +67,7 @@ module.exports = (platform, options) => { // pass on no-optimize-flag // eslint-disable-next-line max-len - serveOptions[CONSTANTS.OMIT_COMPONENT_VERSION_FLAG] = options[CONSTANTS.OMIT_COMPONENT_VERSION_FLAG]; + serveOptions[constants.OMIT_COMPONENT_VERSION_FLAG] = options[constants.OMIT_COMPONENT_VERSION_FLAG]; const tooling = utils.loadTooling(); return tooling.serve(serveOptions.platform, serveOptions) diff --git a/util/constants.js b/lib/util/constants.js similarity index 50% rename from util/constants.js rename to lib/util/constants.js index 867f869..09b3e22 100644 --- a/util/constants.js +++ b/lib/util/constants.js @@ -1,35 +1,127 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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'; -// constants to be used for the generator +/** + * # Constants + * + */ +const OMIT_COMPONENT_VERSION_FLAG = 'omit-component-version'; + +const SHARED_BUILD_AND_SERVE_OPTIONS = [ + 'release', + 'sass', + 'nosass', + 'pcss', + 'device', + 'emulator', + 'destination', + 'build-config', + 'platform-options', + 'optimize', + 'theme', + 'themes', + 'svg', + 'user-options', + 'notscompile', + 'dbg', + OMIT_COMPONENT_VERSION_FLAG +]; module.exports = { - SUPPORTED_PLATFORMS: ['android', 'ios', 'windows', 'web'], - SUPPORTED_HYBRID_PLATFORMS: ['android', 'ios', 'windows'], + APP_CONFIG_JSON: 'oraclejetconfig.json', + + APP_TYPE: { + HYBRID: 'hybrid', + WEB: 'web' + }, + + APP_PROTECTED_OBJECTS: [ + '.gitignore', + 'hybrid/', // Disable overwriting with an empty directory + 'hybrid/config.xml', + 'oraclejetconfig.json', + 'package.json' + ], + CORDOVA_CONFIG_XML: 'config.xml', + + SYSTEM_OPTIONS: [ + 'verbose', + 'installer' + ], + + BUILD_OPTIONS: [ + 'component', + ...SHARED_BUILD_AND_SERVE_OPTIONS + ], + + SERVE_OPTIONS: [ + 'browser', + 'build', + 'livereload', + 'livereload-port', + 'server-only', + 'server-port', + ...SHARED_BUILD_AND_SERVE_OPTIONS + ], + + CONFIG_SCRIPT_PATH: 'scripts/config', + + BUILD_SCRIPT: 'oraclejet-build.js', + + SERVE_SCRIPT: 'oraclejet-serve.js', + + SUPPORTED_PLATFORMS: ['web', 'ios', 'android', 'windows'], + + PATH_TO_HOOKS_CONFIG: 'scripts/hooks/hooks.json', + + APP_STAGED_THEMES_DIRECTORY: 'staged-themes', + + TOOLING_PATH: 'node_modules/@oracle/oraclejet-tooling', + + OJET_LOCAL_STORAGE_DIR: '.ojet', + + EXCHANGE_URL_FILE: 'exchange-url.json', + + EXCHANGE_GLOBAL_URL_KEY: 'global', + + BLANK_TEMPLATE: 'blank', + + NPM_TEMPLATES: ['blank', 'blank-ts', 'basic', 'basic-ts', 'basic-vdom', 'navbar', 'navbar-ts', 'navdrawer', 'navdrawer-ts'], + + ORACLEJET_PACKAGE_JSON_NAME: '@oracle/oraclejet', + + ORACLEJET_TOOLING_PACKAGE_JSON_NAME: '@oracle/oraclejet-tooling', + + OMIT_COMPONENT_VERSION_FLAG, + + APPLICATION_ARCHITECTURE: 'architecture', + + VDOM_ARCHITECTURE: 'vdom', + + MVVM_ARCHITECTURE: 'mvvm', + + SUPPORTED_HYBRID_PLATFORMS: ['android', 'ios', 'windows'], + DEFAULT_INSTALLER: 'npm', DEFAULT_THEME: 'alta', DEFAULT_PCSS_THEME: 'web', DEFAULT_PCSS_NAME: 'redwood', PCSS_STABLE_FLAG: 'stable', PCSS_THEME_FLAG: 'basetheme', - APP_CONFIG_JSON: 'oraclejetconfig.json', COMPONENT_JSON: 'component.json', JET_COMPOSITES: 'jet-composites', JET_COMPONENTS: 'jet_components', COMPONENT_FILES: ['component.json', 'loader.js', 'styles.css'], - PATH_TO_HOOKS_CONFIG: 'scripts/hooks/hooks.json', TSCONFIG_JSON: 'tsconfig.json', VCOMPONENT: 'vcomponent', - APP_TYPE: - { - HYBRID: 'hybrid', - WEB: 'web' - }, + RESOURCE_COMPONENT: 'resource', + RESOURCE_COMPONENT_INDEX_FILE_CONTENT: '//Write your code here. In case you do not need this file, please remove it from the publicModules property list in your component.json file.\n', + USE_GLOBAL_TOOLING: 'use-global-tooling', SUPPORTED_FLAGS: (namespace) => { const systemFlags = [ @@ -67,11 +159,12 @@ module.exports = { 'pwa', 'webpack', 'vdom', - 'use-global-tooling' + 'use-global-tooling', + 'installer' ]; const restoreFlags = [ - 'invokedByRestore', + 'invokedByRestore' ]; const addComponentFlags = [ diff --git a/util/fetchZip.js b/lib/util/fetchZip.js similarity index 94% rename from util/fetchZip.js rename to lib/util/fetchZip.js index 03d9883..d4b7ea5 100644 --- a/util/fetchZip.js +++ b/lib/util/fetchZip.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/utils.injectors.js b/lib/util/injectors.js similarity index 92% rename from lib/utils.injectors.js rename to lib/util/injectors.js index b88e6e2..0af507c 100644 --- a/lib/utils.injectors.js +++ b/lib/util/injectors.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/util/paths.js b/lib/util/paths.js similarity index 94% rename from util/paths.js rename to lib/util/paths.js index 1aaf505..fd68a69 100644 --- a/util/paths.js +++ b/lib/util/paths.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -8,8 +8,9 @@ const path = require('path'); const fs = require('fs-extra'); + const constants = require('./constants'); -const util = require('./index'); +const util = require('./utils'); const _cachedPathsMap = {}; const _defaultPaths = _getDefaultPaths(); @@ -59,7 +60,7 @@ function _getDefaultPaths() { Object.defineProperty(defaultPaths, 'sourceThemes', _getValueObj('themes')); Object.defineProperty(defaultPaths, 'stagingHybrid', _getValueObj('hybrid')); Object.defineProperty(defaultPaths, 'stagingWeb', _getValueObj('web')); - Object.defineProperty(defaultPaths, 'stagingThemes', _getValueObj('themes')); + Object.defineProperty(defaultPaths, 'stagingThemes', _getValueObj(constants.APP_STAGED_THEMES_DIRECTORY)); Object.defineProperty(defaultPaths, 'components', _getValueObj(constants.JET_COMPOSITES)); Object.defineProperty(defaultPaths, 'exchangeComponents', _getValueObj(constants.JET_COMPONENTS)); return defaultPaths; diff --git a/lib/utils.js b/lib/util/utils.js similarity index 89% rename from lib/utils.js rename to lib/util/utils.js index a5600c6..a5ae0cb 100644 --- a/lib/utils.js +++ b/lib/util/utils.js @@ -1,6 +1,6 @@ #! /usr/bin/env node /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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,9 +18,8 @@ const path = require('path'); const StringDecoder = require('string_decoder').StringDecoder; // Oracle -const config = require('../config'); -const CONSTANTS = require('./utils.constants'); -const util = require('../util'); +const config = require('../../config'); +const constants = require('./constants'); /** * # Utils @@ -348,7 +347,7 @@ utils.hasProperty = function (object, propertyName) { utils.isCwdJetApp = function () { const cwd = process.cwd(); // Check if includes oraclejet-tooling - return fs.existsSync(path.join(cwd, CONSTANTS.APP_CONFIG_JSON)); + return fs.existsSync(path.join(cwd, constants.APP_CONFIG_JSON)); }; /** @@ -444,7 +443,8 @@ utils.log.warning = function (message) { * @param {string} message */ utils.log.error = function (message) { - utils.log(`Error: ${message}`); + const msgString = (message && message.stack) ? message.stack : message; + utils.log(`Error: ${msgString}`); if (!process.env.OJET) { process.exit(1); } @@ -624,7 +624,7 @@ function _addHelpMessage() { * @returns {Object} options */ utils.validateOptions = (options, jobType) => { - const validKeys = CONSTANTS.SYSTEM_OPTIONS.concat(jobType === 'build' ? CONSTANTS.BUILD_OPTIONS : CONSTANTS.SERVE_OPTIONS); + const validKeys = constants.SYSTEM_OPTIONS.concat(jobType === 'build' ? constants.BUILD_OPTIONS : constants.SERVE_OPTIONS); Object.keys(options).forEach((key) => { if (validKeys.indexOf(key) === -1) { utils.log.error(`Option ${key} not valid for ojet ${jobType} command`); @@ -652,10 +652,12 @@ utils.validatePlatform = (platform) => { let validPlatform; if (!platform) { validPlatform = utils.getDefaultPlatform(); - utils.log.warning(`Command is missing platform. Default to ${validPlatform}.`); + if (!utils.loadToolingUtil().buildWithWebpack()) { + utils.log.warning(`Command is missing platform. Default to ${validPlatform}.`); + } return validPlatform; } - if (CONSTANTS.SUPPORTED_PLATFORMS.indexOf(platform) > -1) { + if (constants.SUPPORTED_PLATFORMS.indexOf(platform) > -1) { return platform; } utils.log.error(`Invalid platform: ${platform}.`); @@ -674,7 +676,7 @@ utils.getDefaultPlatform = () => { const ojetConfig = utils.loadTooling().config; const pathConfig = ojetConfig.getConfiguredPaths(); const isHybrid = fs.existsSync( - path.resolve(pathConfig.staging.hybrid, CONSTANTS.CORDOVA_CONFIG_XML)); + path.resolve(pathConfig.staging.hybrid, constants.CORDOVA_CONFIG_XML)); const isAddHybrid = fs.existsSync(path.resolve(pathConfig.src.web)) || fs.existsSync(path.resolve(pathConfig.src.hybrid)); @@ -685,7 +687,7 @@ utils.getDefaultPlatform = () => { return platforms[0]; } // if multiple platforms are installed, log error - const supportedPlatforms = CONSTANTS.SUPPORTED_PLATFORMS.toString().replace(/,/g, '||'); + const supportedPlatforms = constants.SUPPORTED_PLATFORMS.toString().replace(/,/g, '||'); utils.log.error(`Command is missing platform. Please specify one of "<${supportedPlatforms}>"`); } return 'web'; @@ -723,14 +725,14 @@ utils.validatePlatformOptions = (platformOptions, platform) => { utils.getBuildCustomizedConfig = (options) => { let customConfig = {}; const optParam = options || {}; - const scriptPath = path.join(process.cwd(), CONSTANTS.CONFIG_SCRIPT_PATH, CONSTANTS.BUILD_SCRIPT); + const scriptPath = path.join(process.cwd(), constants.CONFIG_SCRIPT_PATH, constants.BUILD_SCRIPT); // const scriptPathBackUp = path.join(process.cwd(), - // CONSTANTS.CONFIG_SCRIPT_PATH_BACKUP, CONSTANTS.BUILD_SCRIPT); + // constants.CONFIG_SCRIPT_PATH_BACKUP, constants.BUILD_SCRIPT); if (fs.existsSync(scriptPath)) { customConfig = require(scriptPath)(); // eslint-disable-line // } else if (fs.existsSync(scriptPathBackUp)) { // customConfig = require(scriptPathBackUp)(); // eslint-disable-line - } else { + } else if (!utils.loadToolingUtil().buildWithWebpack()) { utils.log.warning(`No build configuration script found at ${scriptPath}.`); } return { ...customConfig, ...optParam }; @@ -738,14 +740,14 @@ utils.getBuildCustomizedConfig = (options) => { utils.getServeCustomizedConfig = () => { let customConfig = {}; - const scriptPath = path.join(process.cwd(), CONSTANTS.CONFIG_SCRIPT_PATH, CONSTANTS.SERVE_SCRIPT); + const scriptPath = path.join(process.cwd(), constants.CONFIG_SCRIPT_PATH, constants.SERVE_SCRIPT); // const scriptPathBackUp = path.join(process.cwd(), - // CONSTANTS.CONFIG_SCRIPT_PATH_BACKUP, CONSTANTS.SERVE_SCRIPT); + // constants.CONFIG_SCRIPT_PATH_BACKUP, constants.SERVE_SCRIPT); if (fs.existsSync(scriptPath)) { customConfig = require(scriptPath)(); // eslint-disable-line // } else if (fs.existsSync(scriptPathBackUp)) { // customConfig = require(scriptPathBackUp)(); // eslint-disable-line - } else { + } else if (!utils.loadToolingUtil().buildWithWebpack()) { utils.log.warning(`No serve configuration script found at ${scriptPath}.`); } return customConfig; @@ -771,7 +773,7 @@ utils.validCustomProperties = () => { }; utils.loadTooling = () => { - const toolingPath = path.join(process.cwd(), CONSTANTS.TOOLING_PATH); + const toolingPath = path.join(process.cwd(), constants.TOOLING_PATH); // Oracle command libs if (fs.existsSync(toolingPath)) { const tooling = require(toolingPath); // eslint-disable-line @@ -779,7 +781,7 @@ utils.loadTooling = () => { } try { // Use global install if available - const tooling = require(CONSTANTS.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line + const tooling = require(constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME); // eslint-disable-line return tooling; } catch (e) { utils.log.error('Your JET project does not have oraclejet-tooling installed.'); @@ -797,13 +799,13 @@ utils.loadTooling = () => { * @returns {object} tooling util object */ utils.loadToolingUtil = () => { - const toolingPath = path.join(process.cwd(), CONSTANTS.TOOLING_PATH); + const toolingPath = path.join(process.cwd(), constants.TOOLING_PATH); if (fs.existsSync(toolingPath)) { return require(path.join(toolingPath, 'lib', 'util')); // eslint-disable-line } try { // Use global install if available - const tooling = require(`${CONSTANTS.ORACLEJET_TOOLING_PACKAGE_JSON_NAME}/lib/util`); // eslint-disable-line + const tooling = require(`${constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME}/lib/util`); // eslint-disable-line return tooling; } catch (e) { utils.log.error('Your JET project does not have oraclejet-tooling installed.'); @@ -821,7 +823,7 @@ utils.loadToolingUtil = () => { * @returns {boolean} true if is Typescript application, * false otherwise */ -utils.isTypescriptApplication = () => fs.existsSync(path.join('.', CONSTANTS.TSCONFIG_JSON)); +utils.isTypescriptApplication = () => fs.existsSync(path.join('.', constants.TSCONFIG_JSON)); /** * Determine whether the provided template corresponds @@ -832,7 +834,7 @@ utils.isTypescriptApplication = () => fs.existsSync(path.join('.', CONSTANTS.TSC * to an NPM template * */ -utils.isNPMTemplate = template => CONSTANTS.NPM_TEMPLATES.indexOf(template) !== -1; +utils.isNPMTemplate = template => constants.NPM_TEMPLATES.indexOf(template) !== -1; /** * @@ -892,37 +894,54 @@ utils.isVDOMTemplate = ({ options }) => { }; /** - * Determine whether the current application is a VDOm - * application i.e is built using the VDOM architecture - * + * Determine if filePath exists + * @param {String} filePath * @returns {boolean} */ -utils.isVDOMApplication = () => { - const pathToOraclejetConfig = path.join('.', CONSTANTS.APP_CONFIG_JSON); - const oraclejetConfig = utils.readJsonAndReturnObject(pathToOraclejetConfig); - if (utils.hasProperty(oraclejetConfig, CONSTANTS.APPLICATION_ARCHITECTURE) - && oraclejetConfig[CONSTANTS.APPLICATION_ARCHITECTURE] === CONSTANTS.VDOM_ARCHITECTURE) { +utils.fsExistsSync = (filePath) => { + try { + fs.statSync(filePath); return true; + } catch (err) { + // file/directory does not exist + return false; } - return false; }; - /** * Determine the proper @oracle/oraclejet-tooling module location path (global or local) * @returns {string} path to @oracle/oraclejet, preferring local */ utils.getToolingPath = () => { - let source = path.resolve(`${CONSTANTS.TOOLING_PATH}`); + let source = path.resolve(`${constants.TOOLING_PATH}`); - if (util.fsExistsSync(source)) { + if (utils.fsExistsSync(source)) { return source; } - source = path.dirname(require.resolve(`${CONSTANTS.ORACLEJET_TOOLING_PACKAGE_JSON_NAME}/package.json`)); - if (util.fsExistsSync(source)) { + source = path.dirname(require.resolve(`${constants.ORACLEJET_TOOLING_PACKAGE_JSON_NAME}/package.json`)); + if (utils.fsExistsSync(source)) { return source; } // Not found anywhere return null; }; + +/** + * Return the proper installer command + * @param {Object} options + * @returns {Object} installer command & verb + */ +utils.getInstallerCommand = (options) => { + const useCI = utils.hasProperty(options, 'ci'); + if (useCI) { + return { installer: 'npm', verbs: { install: 'ci' } }; + } + let installerCmd = options.installer; + if (!installerCmd) { + const configPath = path.join(process.cwd(), constants.APP_CONFIG_JSON); + const configJson = utils.readJsonAndReturnObject(configPath); + installerCmd = configJson.installer || constants.DEFAULT_INSTALLER; + } + return installerCmd === 'yarn' ? { installer: 'yarn', verbs: { install: 'install' } } : { installer: 'npm', verbs: { install: 'install' } }; +}; diff --git a/lib/utils.constants.js b/lib/utils.constants.js deleted file mode 100644 index 849de78..0000000 --- a/lib/utils.constants.js +++ /dev/null @@ -1,111 +0,0 @@ -/** - 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'; - -/** - * # Constants - * - * @public - */ - -const OMIT_COMPONENT_VERSION_FLAG = 'omit-component-version'; - -const SHARED_BUILD_AND_SERVE_OPTIONS = [ - 'release', - 'sass', - 'nosass', - 'pcss', - 'device', - 'emulator', - 'destination', - 'build-config', - 'platform-options', - 'optimize', - 'theme', - 'themes', - 'svg', - 'user-options', - 'notscompile', - 'dbg', - OMIT_COMPONENT_VERSION_FLAG -]; - -module.exports = { - APP_CONFIG_JSON: 'oraclejetconfig.json', - - APP_TYPE: { - HYBRID: 'hybrid', - WEB: 'web' - }, - - APP_PROTECTED_OBJECTS: [ - '.gitignore', - 'hybrid/', // Disable overwriting with an empty directory - 'hybrid/config.xml', - 'oraclejetconfig.json', - 'package.json' - ], - - CORDOVA_CONFIG_XML: 'config.xml', - - SYSTEM_OPTIONS: [ - 'verbose' - ], - - BUILD_OPTIONS: [ - 'component', - ...SHARED_BUILD_AND_SERVE_OPTIONS - ], - - SERVE_OPTIONS: [ - 'browser', - 'build', - 'livereload', - 'livereload-port', - 'server-only', - 'server-port', - ...SHARED_BUILD_AND_SERVE_OPTIONS - ], - - CONFIG_SCRIPT_PATH: 'scripts/config', - - BUILD_SCRIPT: 'oraclejet-build.js', - - SERVE_SCRIPT: 'oraclejet-serve.js', - - SUPPORTED_PLATFORMS: ['web', 'ios', 'android', 'windows'], - - PATH_TO_HOOKS_CONFIG: 'scripts/hooks/hooks.json', - - TSCONFIG_JSON: 'tsconfig.json', - - APP_STAGED_THEMES_DIRECTORY: 'staged-themes', - - TOOLING_PATH: 'node_modules/@oracle/oraclejet-tooling', - - OJET_LOCAL_STORAGE_DIR: '.ojet', - - EXCHANGE_URL_FILE: 'exchange-url.json', - - EXCHANGE_GLOBAL_URL_KEY: 'global', - - BLANK_TEMPLATE: 'blank', - - NPM_TEMPLATES: ['blank', 'blank-ts', 'basic', 'basic-ts', 'basic-vdom', 'navbar', 'navbar-ts', 'navdrawer', 'navdrawer-ts'], - - ORACLEJET_PACKAGE_JSON_NAME: '@oracle/oraclejet', - - ORACLEJET_TOOLING_PACKAGE_JSON_NAME: '@oracle/oraclejet-tooling', - - OMIT_COMPONENT_VERSION_FLAG, - - APPLICATION_ARCHITECTURE: 'architecture', - - VDOM_ARCHITECTURE: 'vdom', - - MVVM_ARCHITECTURE: 'mvvm' -}; diff --git a/lib/utils.paths.js b/lib/utils.paths.js deleted file mode 100644 index 2d04fa7..0000000 --- a/lib/utils.paths.js +++ /dev/null @@ -1,126 +0,0 @@ -#! /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 - */ -// Node -const fs = require('fs'); -const path = require('path'); - -// Oracle -const CONSTANTS = require('./utils.constants'); -const utils = require('./utils'); - -/** - * # Paths - * - * @public - */ - -const paths = module.exports; - -/** - * ## getConfiguredPaths - * - * @public - * @param {string} appDir - * @returns {Promise} - */ -paths.getConfiguredPaths = function (appDir) { - const cachedPathsMap = {}; - let resultPaths = cachedPathsMap[appDir]; - if (!resultPaths) { - resultPaths = _deriveConfiguredPaths(appDir); - cachedPathsMap[appDir] = resultPaths; - } - return resultPaths; -}; - -/** - * ## getDefaultPaths - * - * @public - * @returns {Object} defaultPaths - */ -paths.getDefaultPaths = function () { - const defaultPaths = {}; - Object.defineProperty(defaultPaths, 'source', _getValueObj('src')); - Object.defineProperty(defaultPaths, 'sourceWeb', _getValueObj('src-web')); - Object.defineProperty(defaultPaths, 'sourceHybrid', _getValueObj('src-hybrid')); - Object.defineProperty(defaultPaths, 'sourceJavascript', _getValueObj('js')); - Object.defineProperty(defaultPaths, 'sourceThemes', _getValueObj('themes')); - Object.defineProperty(defaultPaths, 'stagingHybrid', _getValueObj('hybrid')); - Object.defineProperty(defaultPaths, 'stagingWeb', _getValueObj('web')); - Object.defineProperty(defaultPaths, 'stagingThemes', _getValueObj(CONSTANTS.APP_STAGED_THEMES_DIRECTORY)); - return defaultPaths; -}; - -/** - * ## _deriveConfiguredPaths - * - * @private - * @param {string} appDir - * @returns {Object} configurePaths - */ -function _deriveConfiguredPaths(appDir) { - const defaultPaths = paths.getDefaultPaths(); - const configurePaths = {}; - const conf = _getPathsFromOraclejetConfig(appDir); - Object.defineProperty(configurePaths, 'source', _getValueObj(conf.source.common, defaultPaths.source)); - Object.defineProperty(configurePaths, 'sourceWeb', _getValueObj(conf.source.web, defaultPaths.sourceWeb)); - Object.defineProperty(configurePaths, 'sourceHybrid', _getValueObj(conf.source.hybrid, defaultPaths.sourceHybrid)); - Object.defineProperty(configurePaths, 'sourceJavascript', _getValueObj(conf.source.javascript, defaultPaths.sourceJavascript)); - Object.defineProperty(configurePaths, 'sourceThemes', _getValueObj(conf.source.themes, defaultPaths.sourceThemes)); - Object.defineProperty(configurePaths, 'stagingHybrid', _getValueObj(conf.staging.hybrid, defaultPaths.stagingHybrid)); - Object.defineProperty(configurePaths, 'stagingWeb', _getValueObj(conf.staging.web, defaultPaths.stagingWeb)); - Object.defineProperty(configurePaths, 'stagingThemes', _getValueObj(conf.staging.themes, defaultPaths.stagingThemes)); - return configurePaths; -} - -/** - * ## _getValueObj - * - * @private - * @param {string} value - * @param {string} defaultValue - * @returns {Object} - */ -function _getValueObj(value, defaultValue) { - return { - value: _normPath(value) || defaultValue, - enumerable: true - }; -} - -/** - * ## _normPath - * - * @private - * @param {string} rawValue - * @returns {string || null} - */ -function _normPath(rawValue) { - return (rawValue) ? path.normalize(rawValue) : null; -} - -/** - * ## _getPathsFromOraclejetConfig - * - * @private - * @param {string} appDir - * @returns {Object} - */ -function _getPathsFromOraclejetConfig(appDir) { - const configJsonPath = path.resolve(appDir, CONSTANTS.APP_CONFIG_JSON); - const configJson = fs.existsSync(configJsonPath) ? - utils.readJsonAndReturnObject(configJsonPath) : {}; - return configJson.paths; -} diff --git a/ojet.js b/ojet.js index 7e11eb0..e1f9b04 100644 --- a/ojet.js +++ b/ojet.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/package.json b/package.json index cb7c4b8..c3453af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oracle/ojet-cli", - "version": "11.1.0", + "version": "12.0.0", "description": "Oracle JET Command Line Interface", "license": "UPL-1.0", "homepage": "http://www.oracle.com/jet", @@ -10,11 +10,11 @@ "main": "ojet.js", "dependencies": { "adm-zip": "~0.4.7", - "fs-extra": "^8.1.0", + "fs-extra": "~8.1.0", "inquirer": "~6.2.2", - "minimist": "^1.2.0", + "minimist": "~1.2.0", "xmldom": "0.5.0", - "@oracle/oraclejet-tooling": "~11.1.0" + "@oracle/oraclejet-tooling": "~12.0.0" }, "engines": { "node": ">=12.21.0" diff --git a/template/common/_gitignore b/template/common/_gitignore index 21faa2a..84ea2b7 100644 --- a/template/common/_gitignore +++ b/template/common/_gitignore @@ -1,4 +1,5 @@ /jet_components +/exchange_components /node_modules /bower_components /dist diff --git a/template/common/scripts/config/oraclejet-build.js b/template/common/scripts/config/oraclejet-build.js index 51222ad..15d6946 100644 --- a/template/common/scripts/config/oraclejet-build.js +++ b/template/common/scripts/config/oraclejet-build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/config/oraclejet-serve.js b/template/common/scripts/config/oraclejet-serve.js index 377eaa9..d3a81b8 100644 --- a/template/common/scripts/config/oraclejet-serve.js +++ b/template/common/scripts/config/oraclejet-serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_app_create.js b/template/common/scripts/hooks/after_app_create.js index 5c2ec33..18b9e27 100644 --- a/template/common/scripts/hooks/after_app_create.js +++ b/template/common/scripts/hooks/after_app_create.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_app_restore.js b/template/common/scripts/hooks/after_app_restore.js index 45f43a3..2f00201 100644 --- a/template/common/scripts/hooks/after_app_restore.js +++ b/template/common/scripts/hooks/after_app_restore.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_app_typescript.js b/template/common/scripts/hooks/after_app_typescript.js index 88ddf8f..dd912e9 100644 --- a/template/common/scripts/hooks/after_app_typescript.js +++ b/template/common/scripts/hooks/after_app_typescript.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_build.js b/template/common/scripts/hooks/after_build.js index 5b88d55..0d86b24 100644 --- a/template/common/scripts/hooks/after_build.js +++ b/template/common/scripts/hooks/after_build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_component_build.js b/template/common/scripts/hooks/after_component_build.js index 2acb2b6..a458d9a 100644 --- a/template/common/scripts/hooks/after_component_build.js +++ b/template/common/scripts/hooks/after_component_build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_component_create.js b/template/common/scripts/hooks/after_component_create.js index 9f8226c..0310937 100644 --- a/template/common/scripts/hooks/after_component_create.js +++ b/template/common/scripts/hooks/after_component_create.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_component_package.js b/template/common/scripts/hooks/after_component_package.js new file mode 100644 index 0000000..06c8c01 --- /dev/null +++ b/template/common/scripts/hooks/after_component_package.js @@ -0,0 +1,13 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log('Running after_component_package hook.'); + // const componentName = configObj.component. + resolve(configObj); + }); + }; \ No newline at end of file diff --git a/template/common/scripts/hooks/after_component_typescript.js b/template/common/scripts/hooks/after_component_typescript.js index aa48aa3..71e704c 100644 --- a/template/common/scripts/hooks/after_component_typescript.js +++ b/template/common/scripts/hooks/after_component_typescript.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_serve.js b/template/common/scripts/hooks/after_serve.js index 8c56a0c..d5467e5 100644 --- a/template/common/scripts/hooks/after_serve.js +++ b/template/common/scripts/hooks/after_serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/after_watch.js b/template/common/scripts/hooks/after_watch.js index 656abd4..96d01b0 100644 --- a/template/common/scripts/hooks/after_watch.js +++ b/template/common/scripts/hooks/after_watch.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_app_typescript.js b/template/common/scripts/hooks/before_app_typescript.js index 90b8aa4..b472997 100644 --- a/template/common/scripts/hooks/before_app_typescript.js +++ b/template/common/scripts/hooks/before_app_typescript.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_build.js b/template/common/scripts/hooks/before_build.js index 087273e..e3d566d 100644 --- a/template/common/scripts/hooks/before_build.js +++ b/template/common/scripts/hooks/before_build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_component_optimize.js b/template/common/scripts/hooks/before_component_optimize.js index c4975a3..73ed378 100644 --- a/template/common/scripts/hooks/before_component_optimize.js +++ b/template/common/scripts/hooks/before_component_optimize.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_component_package.js b/template/common/scripts/hooks/before_component_package.js new file mode 100644 index 0000000..ee8802d --- /dev/null +++ b/template/common/scripts/hooks/before_component_package.js @@ -0,0 +1,13 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log('Running before_component_package hook.'); + // const componentName = configObj.component. + resolve(configObj); + }); + }; \ No newline at end of file diff --git a/template/common/scripts/hooks/before_component_typescript.js b/template/common/scripts/hooks/before_component_typescript.js index 280e887..8b8bd58 100644 --- a/template/common/scripts/hooks/before_component_typescript.js +++ b/template/common/scripts/hooks/before_component_typescript.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_hybrid_build.js b/template/common/scripts/hooks/before_hybrid_build.js index 7128ae0..3e0c086 100644 --- a/template/common/scripts/hooks/before_hybrid_build.js +++ b/template/common/scripts/hooks/before_hybrid_build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_optimize.js b/template/common/scripts/hooks/before_optimize.js index e2cbb55..8194e15 100644 --- a/template/common/scripts/hooks/before_optimize.js +++ b/template/common/scripts/hooks/before_optimize.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_release_build.js b/template/common/scripts/hooks/before_release_build.js index 577b3c8..8392b7a 100644 --- a/template/common/scripts/hooks/before_release_build.js +++ b/template/common/scripts/hooks/before_release_build.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_serve.js b/template/common/scripts/hooks/before_serve.js index 6dfbe0b..7db6c27 100644 --- a/template/common/scripts/hooks/before_serve.js +++ b/template/common/scripts/hooks/before_serve.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_watch.js b/template/common/scripts/hooks/before_watch.js index abf8f4b..1df2eb0 100644 --- a/template/common/scripts/hooks/before_watch.js +++ b/template/common/scripts/hooks/before_watch.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/before_webpack.js b/template/common/scripts/hooks/before_webpack.js index a1ff3f7..6617133 100644 --- a/template/common/scripts/hooks/before_webpack.js +++ b/template/common/scripts/hooks/before_webpack.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, 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/template/common/scripts/hooks/hooks.json b/template/common/scripts/hooks/hooks.json index 410da8e..5ff8af1 100644 --- a/template/common/scripts/hooks/hooks.json +++ b/template/common/scripts/hooks/hooks.json @@ -4,9 +4,11 @@ "after_app_create": "scripts/hooks/after_app_create.js", "after_app_restore": "scripts/hooks/after_app_restore.js", "after_component_create": "scripts/hooks/after_component_create.js", + "after_component_package": "scripts/hooks/after_component_package.js", "before_build": "scripts/hooks/before_build.js", "before_optimize": "scripts/hooks/before_optimize.js", "before_component_optimize": "scripts/hooks/before_component_optimize.js", + "before_component_package": "scripts/hooks/before_component_package.js", "before_release": "scripts/hooks/before_release.js", "before_watch": "scripts/hooks/before_watch.js", "after_build": "scripts/hooks/after_build.js", diff --git a/template/component/css/@component@-styles.css b/template/component/css/@component@-styles.css index f2095df..701d09b 100644 --- a/template/component/css/@component@-styles.css +++ b/template/component/css/@component@-styles.css @@ -14,4 +14,9 @@ @full-component-name@{ min-height: 50px; width: 50px; +} + +@full-component-name@[hidden] +{ + display: none; } \ No newline at end of file diff --git a/template/component/js/@component@-view.html b/template/component/js/@component@-view.html index 7cdeb2d..5d7aef2 100644 --- a/template/component/js/@component@-view.html +++ b/template/component/js/@component@-view.html @@ -1,5 +1,5 @@ ', + // endTag: '' + // } + +/** + * # injectPaths + * Configuration for path injection during build in release mode + * This task reads the release paths from the mainReleasePaths json file and injects the path configuration in main.js when run in release mode. + */ + // injectPaths: paths => ({ + // startTag: '// injector:mainReleasePaths', + // endTag: '// endinjector', + // mainJs: 'path to mainjs', + // destMainJs: 'path to the inject destination', + // }), + +/** + * # uglify + * This task minifies source files and libraries that don't have minified distributions. + * It runs only when build in release mode. Support input of fileList that contains an array of file objects. + * See the example in copyCustomLibsToStaging for configuring the fileList. + * See detailed uglify options at https://github.com/mishoo/UglifyJS + */ + // uglify: { + // fileList: [{}], + // options: {} + // }, + +/** + * # requireJs + * This task runs requirejs optimizer to bundle all scripts in to a large minified main.js for release. + * It runs only when build in release mode. + * The task mirrors the configuration in this link https://github.com/gruntjs/grunt-contrib-requirejs + */ + // requireJs: { + // baseUrl: 'path to the js directory in staging area', + // name: 'the main.js file name', + // mainConfigFile: `the main configuration file`, + // optimize: 'option for optimize', + // out: 'output file path' + // }, + +/** + * # sass + * This task runs sass compile for scss files. + * It takes a fileList as input, see copyCustomLibsToStaging section for examples of fileList + * See detailed node sass options available here https://github.com/sass/node-sass + */ + // sass: { + // fileList: [], + // options: {} + // }, + +/** + * This is the web specific configuration. You can specify configurations targeted only for web apps. + * The web specific configurations will override the general configuration. + */ + web: { + // copyCustomLibsToStaging: { + // fileList: [ + // { + // cwd:'node_modules/oraclejet/', + // src: ['*'], + // dest: 'web/js/libs/oraclejet' + // } + // ] + // } + }, + +/** + * This is the hybrid specific configuration. You can specify configurations targeted only hybrid apps. + * The hybrid specific configurations will override the general configuration. + */ + hybrid: { + // copyCustomLibsToStaging: { + // fileList: [ + // { + // cwd:'node_modules/oraclejet/', + // src: ['*'], + // dest: 'hybrid/www/js/libs/oraclejet' + // } + // ] + // } + } + }; +}; diff --git a/test/templates/webpackLegacyTest/scripts/config/oraclejet-serve.js b/test/templates/webpackLegacyTest/scripts/config/oraclejet-serve.js new file mode 100644 index 0000000..8384b53 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/config/oraclejet-serve.js @@ -0,0 +1,88 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; +/** + * # oraclejet-serve.js + * This script allows users to configure and customize the serve tasks. + * Configurable tasks: connect, watch. + * To configure a task, uncomment the corresponding sections below, and pass in your configurations. + * Any options will be merged with default configuration found in node_modules/@oracle/oraclejet-tooling/lib/defaultconfig.js + * Any fileList will replace the default configuration. + */ + +module.exports = function () { + return { +/** + * # watch + * This task watches a set of files and defines a series of customizable tasks if a change is detected. + * Within the watch task config, by default there are three targets, sourceFiles, sass, themes. + * Users are encouraged to edit or add their own watch targets, be careful if rewrite the three default targets. + * Within each watch target, users can specify three properties. + * 1. The files entry takes a list of glob patterns that identifies the set of files to watch + * 2. The options.livereload specifies a boolean that indicates whether the browser should reload when files in this target are modified. + * 3. The options.tasks property specifies custom commands to run. 'compileSass' and 'copyThemes' are reserved internal tasks. + * Example commands: ['grunt copy', 'mocha test]. Once a change is detected, it will run grunt copy followed by mocha test + * once the custom tasks completed, tooling will reload the browser if liverealod is set to true, then resume watching + */ + // // Sub task watch default options + // watch: { + // sourceFiles: + // { + // files: [], + // options: { + // livereload: true + // } + // }, + + // sass: { + // files: [], + // commands: ['compileSass'] + // }, + + // themes: { + // files: [], + // options: { + // livereload: true + // }, + // commands: ['copyThemes'] + // }, + // } + +/** + * This is the web specific configuration. You can specify configurations targeted only for web apps. + * The web specific configurations will override the general configuration. + */ + web: { +/** + * # connect + * This task launches a web server for web App, does not work for hybrid App. + * Support five connect options: + * port, port number, default 8000 + * hostname, a string of the domain name, default localhost + * livereload, a boolean for livereload, default true in dev mode, false in release mode (overwritten when ) + * open, a boolean for wheather to launch browser, default to true + * base, a string of the target directory to be served, default to the staging area + */ + // connect: { + // options: {} + // }, + }, + +/** + * This is the hybrid specific configuration. You can specify configurations targeted only for hybrid apps. + * The hybrid specific configurations will override the general configuration. + */ + hybrid: { + } + }; +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_app_create.js b/test/templates/webpackLegacyTest/scripts/hooks/after_app_create.js new file mode 100644 index 0000000..3c20183 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_app_create.js @@ -0,0 +1,20 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function () { + return new Promise((resolve) => { + console.log('Running after_app_create hook.'); + resolve(); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_app_restore.js b/test/templates/webpackLegacyTest/scripts/hooks/after_app_restore.js new file mode 100644 index 0000000..7884dd3 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_app_restore.js @@ -0,0 +1,20 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function () { + return new Promise((resolve) => { + console.log('Running after_app_restore hook.'); + resolve(); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_app_typescript.js b/test/templates/webpackLegacyTest/scripts/hooks/after_app_typescript.js new file mode 100644 index 0000000..cb8090f --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_app_typescript.js @@ -0,0 +1,20 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log("Running after_app_typescript hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_build.js b/test/templates/webpackLegacyTest/scripts/hooks/after_build.js new file mode 100644 index 0000000..9093060 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_build.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running after_build hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_component_build.js b/test/templates/webpackLegacyTest/scripts/hooks/after_component_build.js new file mode 100644 index 0000000..e6b4498 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_component_build.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running after_component_build hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_component_create.js b/test/templates/webpackLegacyTest/scripts/hooks/after_component_create.js new file mode 100644 index 0000000..65b16b6 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_component_create.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log('Running after_component_create hook.'); + // const componentPath = configObj.componentPath; + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_component_typescript.js b/test/templates/webpackLegacyTest/scripts/hooks/after_component_typescript.js new file mode 100644 index 0000000..6ad7cde --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_component_typescript.js @@ -0,0 +1,20 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log("Running after_component_typescript hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_serve.js b/test/templates/webpackLegacyTest/scripts/hooks/after_serve.js new file mode 100644 index 0000000..bccb384 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_serve.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running after_serve hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/after_watch.js b/test/templates/webpackLegacyTest/scripts/hooks/after_watch.js new file mode 100644 index 0000000..93638be --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/after_watch.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running after_watch hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_app_typescript.js b/test/templates/webpackLegacyTest/scripts/hooks/before_app_typescript.js new file mode 100644 index 0000000..df007b6 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_app_typescript.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log("Running before_app_typescript hook."); + //const { tsconfigJson } = configObj.typescript; + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_build.js b/test/templates/webpackLegacyTest/scripts/hooks/before_build.js new file mode 100644 index 0000000..5e6a7c0 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_build.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_build hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_component_optimize.js b/test/templates/webpackLegacyTest/scripts/hooks/before_component_optimize.js new file mode 100644 index 0000000..d837020 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_component_optimize.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_component_optimize hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_component_typescript.js b/test/templates/webpackLegacyTest/scripts/hooks/before_component_typescript.js new file mode 100644 index 0000000..11f037b --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_component_typescript.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve) => { + console.log("Running before_component_typescript hook."); + //const { tsconfigJson } = configObj.typescript; + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_hybrid_build.js b/test/templates/webpackLegacyTest/scripts/hooks/before_hybrid_build.js new file mode 100644 index 0000000..d5ebe55 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_hybrid_build.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_hybrid_build hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_optimize.js b/test/templates/webpackLegacyTest/scripts/hooks/before_optimize.js new file mode 100644 index 0000000..4ca8b17 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_optimize.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_optimize hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_release_build.js b/test/templates/webpackLegacyTest/scripts/hooks/before_release_build.js new file mode 100644 index 0000000..cedb774 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_release_build.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_release_build hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_serve.js b/test/templates/webpackLegacyTest/scripts/hooks/before_serve.js new file mode 100644 index 0000000..1428920 --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_serve.js @@ -0,0 +1,43 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log('Running before_serve hook.'); + // ojet custom connect and serve options + // { connectOpts, serveOpts } = configObj; + // const express = require('express'); + // const http = require('http'); + // pass back custom http + // configObj['http'] = http; + // pass back custom express app + // configObj['express'] = express(); + // pass back custom options for http.createServer + // const serverOptions = {...}; + // configObj['serverOptions'] = serverOptions; + // pass back custom server + // configObj['server'] = http.createServer(serverOptions, express()); + // const tinylr = require('tiny-lr'); + // pass back custom live reload server + // configObj['liveReloadServer'] = tinylr({ port: PORT }); + // pass back a replacement set of middleware + // configObj['middleware'] = [...]; + // pass back a set of middleware that goes before the default middleware + // configObj['preMiddleware'] = [...]; + // pass back a set of middleware that goes after the default middleware + // configObj['postMiddleware'] = [...]; + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_watch.js b/test/templates/webpackLegacyTest/scripts/hooks/before_watch.js new file mode 100644 index 0000000..826e53e --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_watch.js @@ -0,0 +1,21 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_watch hook."); + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/before_webpack.js b/test/templates/webpackLegacyTest/scripts/hooks/before_webpack.js new file mode 100644 index 0000000..61cc4ab --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/before_webpack.js @@ -0,0 +1,22 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + 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'; + +module.exports = function (configObj) { + return new Promise((resolve, reject) => { + console.log("Running before_webpack hook."); + // const { config } = configObj.webpack; + resolve(configObj); + }); +}; diff --git a/test/templates/webpackLegacyTest/scripts/hooks/hooks.json b/test/templates/webpackLegacyTest/scripts/hooks/hooks.json new file mode 100644 index 0000000..410da8e --- /dev/null +++ b/test/templates/webpackLegacyTest/scripts/hooks/hooks.json @@ -0,0 +1,25 @@ +{ + "description": "OJET-CLI hooks configuration file", + "hooks": { + "after_app_create": "scripts/hooks/after_app_create.js", + "after_app_restore": "scripts/hooks/after_app_restore.js", + "after_component_create": "scripts/hooks/after_component_create.js", + "before_build": "scripts/hooks/before_build.js", + "before_optimize": "scripts/hooks/before_optimize.js", + "before_component_optimize": "scripts/hooks/before_component_optimize.js", + "before_release": "scripts/hooks/before_release.js", + "before_watch": "scripts/hooks/before_watch.js", + "after_build": "scripts/hooks/after_build.js", + "after_component_build": "scripts/hooks/after_component_build.js", + "before_hybrid_build": "scripts/hooks/before_hybrid_build.js", + "before_release_build": "scripts/hooks/before_release_build.js", + "before_serve": "scripts/hooks/before_serve.js", + "after_serve": "scripts/hooks/after_serve.js", + "after_watch": "scripts/hooks/after_watch.js", + "before_app_typescript": "scripts/hooks/before_app_typescript.js", + "before_component_typescript": "scripts/hooks/before_component_typescript.js", + "after_app_typescript": "scripts/hooks/after_app_typescript.js", + "after_component_typescript": "scripts/hooks/after_component_typescript.js", + "before_webpack": "scripts/hooks/before_webpack.js" + } +} diff --git a/test/templates/webpackLegacyTest/src/components/app.tsx b/test/templates/webpackLegacyTest/src/components/app.tsx new file mode 100644 index 0000000..351e217 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/components/app.tsx @@ -0,0 +1,36 @@ +import { customElement, ExtendGlobalProps } from "ojs/ojvcomponent"; +import { h, Component, ComponentChild } from "preact"; +import Context = require("ojs/ojcontext"); +import { Footer } from "./footer"; +import { Header } from "./header"; +import { Content } from "./content/index"; + +type Props = { + appName?: string; + userLogin?: string; +} + +@customElement("app-root") +export class App extends Component> { + static defaultProps: Props = { + appName: 'App Name', + userLogin: "john.hancock@oracle.com" + }; + + render(props: ExtendGlobalProps): ComponentChild { + return ( +
+
+ +
+
+ ); + } + + componentDidMount() { + Context.getPageContext().getBusyContext().applicationBootstrapComplete(); + } +} diff --git a/test/templates/webpackLegacyTest/src/components/content/index.tsx b/test/templates/webpackLegacyTest/src/components/content/index.tsx new file mode 100644 index 0000000..f9805b9 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/components/content/index.tsx @@ -0,0 +1,8 @@ +import { h } from "preact"; + +export function Content() { + return ( +
+
+ ); +}; diff --git a/test/templates/webpackLegacyTest/src/components/footer.tsx b/test/templates/webpackLegacyTest/src/components/footer.tsx new file mode 100644 index 0000000..88a7651 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/components/footer.tsx @@ -0,0 +1,60 @@ +import { h } from "preact"; + +type Props = { + links?: FooterLink[] +} + +type FooterLink = { + name: string; + linkId: string; + linkTarget: string; +} + +const _DEFAULT_LINKS: FooterLink[] = [ + { + name: "About Oracle", + linkId: "aboutOracle", + linkTarget: "http://www.oracle.com/us/corporate/index.html#menu-about" + }, + { + name: "Contact Us", + linkId: "contactUs", + linkTarget: "http://www.oracle.com/us/corporate/contact/index.html" + }, + { + name: "Legal Notices", + linkId: "legalNotices", + linkTarget: "http://www.oracle.com/us/legal/index.html" + }, + { + name: "Terms Of Use", + linkId: "termsOfUse", + linkTarget: "http://www.oracle.com/us/legal/terms/index.html" + }, + { + name: "Your Privacy Rights", + linkId: "yourPrivacyRights", + linkTarget: "http://www.oracle.com/us/legal/privacy/index.html" + } +] + +export function Footer({ links = _DEFAULT_LINKS } : Props ) { + return ( +
+ + +
+ ); +} diff --git a/test/templates/webpackLegacyTest/src/components/header.tsx b/test/templates/webpackLegacyTest/src/components/header.tsx new file mode 100644 index 0000000..464a7f9 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/components/header.tsx @@ -0,0 +1,94 @@ +import { h, Component, ComponentChild } from "preact"; +import * as ResponsiveUtils from "ojs/ojresponsiveutils"; +import "ojs/ojtoolbar"; +import "ojs/ojmenu"; +import "ojs/ojbutton"; + +type Props = { + appName: string, + userLogin: string +} + +type State = { + displayType: "all" | "icons", + endIconClass: string +} + +export class Header extends Component { + private mediaQuery: MediaQueryList; + + constructor(props: Props) { + super(props); + const smallOnlyQuery = ResponsiveUtils.getFrameworkQuery("sm-only"); + this.mediaQuery = window.matchMedia(smallOnlyQuery); + this._mediaQueryChangeListener = this._mediaQueryChangeListener.bind(this); + const displayType = this._getDisplayTypeFromMediaQuery(this.mediaQuery); + const endIconClass = this._getEndIconClassFromDisplayType(displayType); + this.state = { + displayType, + endIconClass + }; + } + + render(props: Readonly, state: Readonly): ComponentChild { + return ( + + ); + } + + componentDidMount() { + this.mediaQuery.addEventListener("change", this._mediaQueryChangeListener); + } + + componentWillUnmount() { + this.mediaQuery.removeEventListener("change", this._mediaQueryChangeListener); + } + + _mediaQueryChangeListener(mediaQuery) { + const displayType = this._getDisplayTypeFromMediaQuery(mediaQuery); + const endIconClass = this._getEndIconClassFromDisplayType(displayType); + this.setState({ + displayType, + endIconClass + }); + } + + _getDisplayTypeFromMediaQuery(mediaQuery) { + return mediaQuery.matches ? "icons" : "all"; + } + + _getEndIconClassFromDisplayType(displayType) { + return displayType === "icons" ? + "oj-icon demo-appheader-avatar" : + "oj-component-icon oj-button-menu-dropdown-icon" + } +} \ No newline at end of file diff --git a/test/templates/webpackLegacyTest/src/index.html b/test/templates/webpackLegacyTest/src/index.html new file mode 100644 index 0000000..4268ebd --- /dev/null +++ b/test/templates/webpackLegacyTest/src/index.html @@ -0,0 +1,55 @@ + + + + + + + + + Oracle JET VDOM Starter Template - Basic + + + + + + + + + + + + + + + + + + + diff --git a/test/templates/webpackLegacyTest/src/index.ts b/test/templates/webpackLegacyTest/src/index.ts new file mode 100644 index 0000000..42ab79c --- /dev/null +++ b/test/templates/webpackLegacyTest/src/index.ts @@ -0,0 +1 @@ +import './components/app'; \ No newline at end of file diff --git a/test/templates/webpackLegacyTest/src/main.js b/test/templates/webpackLegacyTest/src/main.js new file mode 100644 index 0000000..f332dc6 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/main.js @@ -0,0 +1,63 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +/** + * @license + * 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/ + * @ignore + */ +'use strict'; + +/** + * Example of Require.js boostrap javascript + */ + + +(function () { + requirejs.config( + { + // injector:baseUrl + baseUrl: '.', + // endinjector + paths: + /* DO NOT MODIFY + ** All paths are dynamicaly generated from the path_mappings.json file. + ** Add any new library dependencies in path_mappings json file + */ + // injector:mainReleasePaths + { + 'ojs': 'libs/oj/v12.0.0/debug', + 'ojL10n': 'libs/oj/v12.0.0/ojL10n', + 'ojtranslations': 'libs/oj/v12.0.0/resources', + 'knockout': 'libs/knockout/knockout-3.5.1.debug', + 'jquery': 'libs/jquery/jquery-3.6.0', + 'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.1', + 'text': 'libs/require/text', + 'hammerjs': 'libs/hammer/hammer-2.0.8', + 'signals': 'libs/js-signals/signals', + 'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.2', + 'css': 'libs/require-css/css.min', + 'css-builder': 'libs/require-css/css-builder', + 'normalize': 'libs/require-css/normalize', + '@oracle/oraclejet-preact': 'libs/oraclejet-preact/amd', + 'preact': 'libs/preact/dist/preact.umd', + 'preact/hooks': 'libs/preact/hooks/dist/hooks.umd', + 'proj4': 'libs/proj4js/dist/proj4-src', + 'touchr': 'libs/touchr/touchr' + , + 'chai': 'libs/chai/chai-4.3.4' + } + // endinjector + } + ); +}()); + +/** + * Load the application's entry point file + */ +require(['./index']); diff --git a/test/templates/webpackLegacyTest/src/styles/app.css b/test/templates/webpackLegacyTest/src/styles/app.css new file mode 100644 index 0000000..f5aef33 --- /dev/null +++ b/test/templates/webpackLegacyTest/src/styles/app.css @@ -0,0 +1,43 @@ +/* + Document : override + Created on : + Author : + Description: + This is where any of your application specific styles should be included +*/ +.demo-oracle-icon { + width:137px; + height:18px +} + +.demo-oracle-icon:before { + content:url("images/oracle_logo.svg") +} + +html:not([dir="rtl"]) .demo-oracle-icon { + padding-right:4px +} + +html[dir="rtl"] .demo-oracle-icon { + padding-left:4px +} + +.demo-oracle-icon:before { + display:inline +} + +.demo-appheader-avatar { + width:24px; + height:24px +} + +.demo-appheader-avatar:before { + content:url("images/avatar_24px.png") +} +@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) { + .demo-appheader-avatar:before { + content:url("images/avatar_24px_2x.png"); + -webkit-transform:translate(-25%, -25%) scale(0.5); + transform:translate(-25%, -25%) scale(0.5) + } +} \ No newline at end of file diff --git a/test/templates/webpackLegacyTest/src/styles/fonts/App_iconfont.woff b/test/templates/webpackLegacyTest/src/styles/fonts/App_iconfont.woff new file mode 100644 index 0000000..11e71bc Binary files /dev/null and b/test/templates/webpackLegacyTest/src/styles/fonts/App_iconfont.woff differ diff --git a/test/templates/webpackLegacyTest/src/styles/images/avatar_24px.png b/test/templates/webpackLegacyTest/src/styles/images/avatar_24px.png new file mode 100644 index 0000000..2838dc1 Binary files /dev/null and b/test/templates/webpackLegacyTest/src/styles/images/avatar_24px.png differ diff --git a/test/templates/webpackLegacyTest/src/styles/images/avatar_24px_2x.png b/test/templates/webpackLegacyTest/src/styles/images/avatar_24px_2x.png new file mode 100644 index 0000000..d4dd789 Binary files /dev/null and b/test/templates/webpackLegacyTest/src/styles/images/avatar_24px_2x.png differ diff --git a/test/templates/webpackLegacyTest/src/styles/images/favicon.ico b/test/templates/webpackLegacyTest/src/styles/images/favicon.ico new file mode 100644 index 0000000..abdc1bb Binary files /dev/null and b/test/templates/webpackLegacyTest/src/styles/images/favicon.ico differ diff --git a/test/templates/webpackLegacyTest/src/styles/images/oracle_logo.svg b/test/templates/webpackLegacyTest/src/styles/images/oracle_logo.svg new file mode 100644 index 0000000..b4a3b6a --- /dev/null +++ b/test/templates/webpackLegacyTest/src/styles/images/oracle_logo.svg @@ -0,0 +1,21 @@ + + + + + diff --git a/test/templates/webpackLegacyTest/tsconfig.json b/test/templates/webpackLegacyTest/tsconfig.json new file mode 100644 index 0000000..bda8891 --- /dev/null +++ b/test/templates/webpackLegacyTest/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "baseUrl": ".", + "target": "es6", + "module": "amd", + "moduleResolution": "node", + "jsx": "react", + "jsxFactory": "h", + "lib": [ + "es2015", + "dom", + "esnext.asynciterable" + ], + "typeRoots": [ + "./node_modules/@oracle/oraclejet/dist/types", + "./node_modules/@types" + ], + "paths": { + "ojs/*": [ + "./node_modules/@oracle/oraclejet/dist/types/*" + ] + }, + "declaration": true, + "noEmitOnError": true, + "experimentalDecorators": true + }, + "include": [ + "./src/**/*" + ] +} diff --git a/test/themeTest.js b/test/themeTest.js index 8b8c2da..28467db 100644 --- a/test/themeTest.js +++ b/test/themeTest.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,10 +9,47 @@ const fs = require('fs-extra'); const path = require('path'); const util = require('./util'); -const testDir = path.resolve('../test_result'); -const appDir = path.resolve(testDir, util.THEME_APP_NAME); +const appDir = util.getAppDir(util.THEME_APP_NAME); describe('PCSS Theme Test', () => { + before(async () => { + if (!util.noScaffold()) { + util.removeAppDir(util.THEME_APP_NAME); + + // Scaffold a basic web app + let result = await util.execCmd(`${util.OJET_COMMAND} create ${util.THEME_APP_NAME} --use-global-tooling --norestore=true`, { cwd: util.testDir }); + console.log(result.stdout); + // Check that it output the right text to the command line + assert.strictEqual(util.norestoreSuccess(result.stdout), true, result.stderr); + // Restore + result = await util.execCmd(`${util.OJET_APP_COMMAND} restore`, { cwd: util.getAppDir(util.THEME_APP_NAME) }); + } + }); + + it('should run ojet build --sass in an app with no *.scss files and not fail', async () => { + const result = await util.execCmd(`${util.OJET_APP_COMMAND} build --sass`, {cwd: appDir}); + assert.equal(util.buildSuccess(result.stdout), true, result.error); + }); + + it('should run ojet build --sass in an app with *.scss files and fail with correct error message', async () => { + const testComponentName = 'test-component'; + // make a temporary jet-composites folder in the app folder + await util.execCmd(`${util.OJET_APP_COMMAND} create component ${testComponentName}`, {cwd: appDir}); + const { pathToApp, sourceFolder, javascriptFolder, componentsFolder} = util.getAppPathData(util.THEME_APP_NAME); + const pathToJetCompositeFolder = path.join(pathToApp, sourceFolder, javascriptFolder, componentsFolder); + const pathToTestComponent = path.join(pathToJetCompositeFolder,`${testComponentName}`); + const testComponentCssFile = `${testComponentName}-styles.css`; + // get .css and .scss file paths and rename .css to .scss + const cssFilePath = path.join(pathToTestComponent, testComponentCssFile); + const scssFilePath = cssFilePath.replace('.css', '.scss'); + fs.renameSync(cssFilePath, scssFilePath); + // set squelch to true to not catch anything on resolving the promise + const result = await util.execCmd(`${util.OJET_APP_COMMAND} build --sass`, {cwd: appDir}, true); + // Delete the jet-composite folder created after running ojet build --sass + fs.rmdirSync(pathToJetCompositeFolder, {recursive : true}); + assert.ok(/node-sass is not installed. To install it, run: ojet add sass./.test(result.stdout), true, result.stdout); + }); + it('Should add theming to enable node-sass, postcss-custom-theme, postcss-calc, autoprefixer', async () => { const result = await util.execCmd(`${util.OJET_APP_COMMAND} add theming`, { cwd: appDir }); assert.equal(/add pcss complete/.test(result.stdout), true, result.stdout); @@ -44,6 +81,26 @@ describe('PCSS Theme Test', () => { const result = await util.execCmd(`${util.OJET_APP_COMMAND} create theme demotheme`, {cwd: appDir}, true); assert.equal(/basetheme is required/.test(result.stdout), true, result.stdout); }); - + + it('Should run build with --theme=all and check that redwood files are present in staging location', async () => { + await util.execCmd(`${util.OJET_APP_COMMAND} build --themes=all`, {cwd: appDir}); + const { stagingFolder, stylesFolder, pathToNodeModules, pathToApp } = util.getAppPathData(util.THEME_APP_NAME); + const pathToRedwoodInStaging = path.join(pathToApp, stagingFolder, stylesFolder, 'redwood', util.getJetVersion(util.THEME_APP_NAME),'web'); + const pathToRedwoodInNodeModules = path.join(pathToNodeModules, '@oracle/oraclejet/dist/css/redwood'); + const everyExpectedEntryIsPresent = fs.readdirSync(pathToRedwoodInNodeModules).every(dirEntry => { + // oj-redwood.css is renamed to redwood.css in the staging location so + // we have to update the existence check: + if (dirEntry === 'oj-redwood.css') { + return fs.existsSync(path.join(pathToRedwoodInStaging, 'redwood.css')); + } + // Similarly, oj-redwood-min.css is renamed to redwood.min.css in the staging + // location so we have to update the existence check: + else if (dirEntry === 'oj-redwood-min.css') { + return fs.existsSync(path.join(pathToRedwoodInStaging, 'redwood.min.css')); + } + return fs.existsSync(path.join(pathToRedwoodInStaging, dirEntry)); + }); + assert.ok(everyExpectedEntryIsPresent, "Not all redwood files are present in staging location."); + }); }); }); \ No newline at end of file diff --git a/test/tsTest.js b/test/tsTest.js index 10a5eca..53bd648 100644 --- a/test/tsTest.js +++ b/test/tsTest.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -7,14 +7,25 @@ const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); - +const glob = require('glob'); const util = require('./util'); let filelist; -const testDir = path.resolve('../test_result'); -const appDir = path.resolve(testDir, util.TS_APP_NAME); +const appDir = util.getAppDir(util.TS_APP_NAME); describe('Typescript Test', () => { + before(async () => { + if (!util.noScaffold()) { + util.removeAppDir(util.TS_APP_NAME); + + // Scaffold TS app from scratch + const result = await util.execCmd(`${util.OJET_COMMAND} create ${util.TS_APP_NAME} --use-global-tooling --template=navbar --typescript`, { cwd: util.testDir }); + console.log(result.stdout); + // Check output + assert.equal(util.norestoreSuccess(result.stdout) || /Your app is/.test(result.stdout), true, result.error); + } + }); + describe('Scaffold with norestore flag', () => { it('should have tsconfig.json file', () => { const pathToTsconfigJson = path.resolve(appDir, 'tsconfig.json'); @@ -76,4 +87,45 @@ describe('Typescript Test', () => { assert.ok(!fs.pathExistsSync(pathToTSFolder), pathToTSFolder); }); }); + describe('Tsconfig "extends" option', () => { + if (!util.noBuild()) { + it('should build ts app after adding "extends" to tsconfig.json', async () => { + const BASE_TSCONFIG_JSON = 'base_tsconfig.json'; + const { pathToApp } = util.getAppPathData(util.TS_APP_NAME); + // Create base_tsconfig.json and add "extends" option to tsconfig.json + const baseTsconfigJsonPath = path.join(pathToApp, BASE_TSCONFIG_JSON); + const baseTsconfigJson = { + compilerOptions: { + noEmit: true + } + }; + fs.writeJSONSync(baseTsconfigJsonPath, baseTsconfigJson, { spaces: 2 }); + const tsconfigJsonPath = path.join(pathToApp, util.TSCONFIG_JSON); + const tsconfigJson = fs.readJSONSync(tsconfigJsonPath); + tsconfigJson.extends = `./${BASE_TSCONFIG_JSON}`; + fs.writeJSONSync(tsconfigJsonPath, tsconfigJson, { spaces: 2 }); + // Run build and ensure that it was successful + const result = await util.execCmd(`${util.OJET_APP_COMMAND} build`, { cwd: util.getAppDir(util.TS_APP_NAME) }); + assert.equal(util.buildSuccess(result.stdout), true, result.error); + // Delete base_tsconfig.json and revert tsconfig.json change + fs.removeSync(baseTsconfigJsonPath); + delete tsconfigJson.extends; + fs.writeJSONSync(tsconfigJsonPath, tsconfigJson, { spaces: 2 }); + }); + } + it('should not have *.ts compiled to *.js because of noEmit in base_tsconfig.json', () => { + const { pathToApp, sourceFolder, typescriptFolder, stagingFolder, javascriptFolder } = util.getAppPathData(util.TS_APP_NAME); + const typescriptFilesPattern = path.join(pathToApp, sourceFolder, typescriptFolder, '**/*.ts'); + const typescriptFiles = glob.sync(typescriptFilesPattern); + typescriptFiles.forEach((file) => { + const stagingPath = path.normalize(file) + .replace( + path.join(pathToApp, sourceFolder, typescriptFolder), + path.join(pathToApp, stagingFolder, javascriptFolder) + ) + .replace('.ts', '.js'); + assert.ok(!fs.existsSync(stagingPath), `${stagingPath} found`); + }); + }); + }); }); diff --git a/test/util/index.js b/test/util/index.js index 63f8d6a..f56728e 100644 --- a/test/util/index.js +++ b/test/util/index.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -12,7 +12,9 @@ const path = require('path'); const exec = require('child_process').exec; -const td = path.resolve('../test_result'); +const TEST_DIR = 'test_result'; + +const td = path.resolve(`../${TEST_DIR}`); const pkg = require('../../package.json'); function _isQuick() { @@ -26,22 +28,49 @@ const JAVASCRIPT_COMPONENT_APP_CONFIG = { appName: COMPONENT_APP_NAME, scriptsFo const TYPESCRIPT_COMPONENT_APP_CONFIG = { appName: COMPONENT_TS_APP_NAME, scriptsFolder: 'ts' }; const COMPONENT_TEST_APP_CONFIGS = [JAVASCRIPT_COMPONENT_APP_CONFIG, TYPESCRIPT_COMPONENT_APP_CONFIG]; -function runComponentTestInAllTestApps({ test, pack, component, vcomponent, release, bundle, resourceComponent }) { +function runComponentTestInAllTestApps(options) { COMPONENT_TEST_APP_CONFIGS.forEach((config) => { - runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle, resourceComponent }); + runComponentTestInTestApp(config, options); }) } -function runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle, resourceComponent }) { +function runComponentTestInTestApp(config, options) { describe(config.appName, () => { - test({...config, pack, component, vcomponent, release, bundle, resourceComponent }); + options.test({...config, ...options}); }); } -const ORACLJET_CONFIG_JSON = 'oraclejetconfig.json'; +function _replaceOraclejetToolingProp(packageJson) { + packageJson.devDependencies['@oracle/oraclejet-tooling'] = `file:${path.join('..', '..', + 'ojet-cli', 'node_modules', '@oracle', 'oraclejet-tooling')}`; +} + +const ORACLEJET_CONFIG_JSON = 'oraclejetconfig.json'; const DEFAULT_COMPONENTS_FOLDER = 'jet-composites'; const OMIT_COMPONENT_VERSION_FLAG = 'omit-component-version'; -const WEBPACK_DEPENDENCIES = ['webpack', 'css-loader', 'style-loader', 'text-loader']; +const WEBPACK_LEGACY_DEPENDENCIES = ['webpack', 'css-loader', 'style-loader', 'text-loader']; +const WEBPACK_DEPENDENCIES = [ + 'webpack', + 'webpack-dev-server', + 'style-loader', + 'css-loader', + 'ts-loader', + 'raw-loader', + 'noop-loader', + 'html-webpack-plugin', + 'html-replace-webpack-plugin', + 'copy-webpack-plugin', + '@prefresh/webpack', + '@prefresh/babel-plugin', + 'webpack-merge', + 'compression-webpack-plugin', + 'mini-css-extract-plugin', + 'zlib' +]; +const COMPONENT_JSON_DEPENDENCIES_TOKEN = '@dependencies@'; +const COMPONENT_JSON = 'component.json'; +const OJET_CONFIG_JS = 'ojet.config.js'; +const TSCONFIG_JSON = 'tsconfig.json'; module.exports = { OJET_COMMAND: 'node ../ojet-cli/bin/ojet', @@ -54,16 +83,24 @@ module.exports = { PWA_APP_NAME: 'webJsPwaTest', API_APP_NAME: 'webTsApiTest', VDOM_APP_NAME: 'vdomTest', + WEBPACK_APP_NAME: 'webpackTest', + WEBPACK_LEGACY_APP_NAME: 'webpackLegacyTest', COMPONENT_APP_NAME, COMPONENT_TS_APP_NAME, JAVASCRIPT_COMPONENT_APP_CONFIG, TYPESCRIPT_COMPONENT_APP_CONFIG, EXCHANGE_URL: 'https://exchange.oraclecorp.com/api/0.2.0', - ORACLJET_CONFIG_JSON, + ORACLEJET_CONFIG_JSON, DEFAULT_COMPONENTS_FOLDER, OMIT_COMPONENT_VERSION_FLAG, + TEST_DIR, WEBPACK_DEPENDENCIES, - execCmd: function _execCmd(cmd, options, squelch, logCommand = true) { + WEBPACK_LEGACY_DEPENDENCIES, + COMPONENT_JSON_DEPENDENCIES_TOKEN, + COMPONENT_JSON, + OJET_CONFIG_JS, + TSCONFIG_JSON, + execCmd: function _execCmd(cmd, options, squelch = false, logCommand = true) { if (logCommand) { console.log(cmd); } @@ -80,6 +117,23 @@ module.exports = { }) }, + makePackageSymlink: function _makePackageSymlink() { + function _updatePackageFile(dir) { + let src = path.resolve('generators', dir, 'templates', 'common', 'package.json'); + let json = fs.readJSONSync(src); + // Replace the property + _replaceOraclejetToolingProp(json); + // Write it back out + fs.writeJsonSync(src, json); + } + + // Update the two package.json files in our built ojet-cli common templates + _updatePackageFile('app'); + + // do hybrid + _updatePackageFile('hybrid'); + }, + // Copy over oraclejet-tooling's build to the installation of ojet-cli copyOracleJetTooling: function _copyOracleJetTooling(app) { try { @@ -204,28 +258,72 @@ module.exports = { return regex.test(stdout); }, + removeAppDir: function _removeAppDir(appName) { + const appDir = path.join(td, appName); + fs.emptyDirSync(appDir); + fs.rmdirSync(appDir); + }, + runComponentTestInAllTestApps, runComponentTestInTestApp, - getOracleJetConfigJson: function _getOracleJetConfigJson({ appName }) { - const oraclejetConfigJsonPath = path.join(this.getAppDir(appName), ORACLJET_CONFIG_JSON); - const oraclejetConfigJson = fs.readJSONSync(oraclejetConfigJsonPath); + getOracleJetConfigPath: function _getOracleJetConfigPath(appName) { + return path.join(this.getAppDir(appName), ORACLEJET_CONFIG_JSON); + }, + + getOracleJetConfigJson: function _getOracleJetConfigJson(appName) { + const oraclejetConfigJson = fs.readJSONSync(this.getOracleJetConfigPath(appName)); return oraclejetConfigJson; }, - getAppPathData: function _getAppPathData({ appName }) { - const oraclejetConfigJson = this.getOracleJetConfigJson({ appName }); + writeOracleJetConfigJson: function _writeOracleJetConfigJson(appName, oraclejetConfigJson) { + fs.writeJsonSync(this.getOracleJetConfigPath(appName), oraclejetConfigJson); + }, + + writeCustomHookContents: function _writeCustomHookContents({hookName, filePath}) { + const customHookContent = `module.exports = function (configObj) { + return new Promise((resolve) => { + const componentName = configObj.component; + console.log('Running ${hookName}_component_package for component: component being packaged is', componentName); + resolve(configObj); + }); + }` + fs.writeFileSync(filePath, customHookContent); + }, + + getHooksPathAndContent: function _getHooksPathAndContent(appName) { + const { pathToAppHooks } = this.getAppPathData(appName); + const beforePackageHookPath = path.join(pathToAppHooks, `before_component_package.js`); + const afterPackageHookPath = path.join(pathToAppHooks, `after_component_package.js`); + const defaultBeforeHookContent = fs.readFileSync(beforePackageHookPath); + const defaultAfterHookContent = fs.readFileSync(afterPackageHookPath); + return { + beforePackageHookPath, + afterPackageHookPath, + defaultBeforeHookContent, + defaultAfterHookContent + } + }, + + getAppPathData: function _getAppPathData(appName, scriptsFolder='') { + const oraclejetConfigJson = this.getOracleJetConfigJson(appName); const componentsFolder = oraclejetConfigJson.paths.source.components || DEFAULT_COMPONENTS_FOLDER; const stagingFolder = oraclejetConfigJson.paths.staging.web; const javascriptFolder = oraclejetConfigJson.paths.source.javascript; - const typescriptFolder = oraclejetConfigJson.paths.source.javascript; + const typescriptFolder = oraclejetConfigJson.paths.source.typescript; const sourceFolder = oraclejetConfigJson.paths.source.common; const pathToApp = this.getAppDir(appName); const pathToBuiltComponents = path.join(pathToApp, stagingFolder, javascriptFolder, componentsFolder); + const pathToSourceComponents = path.join(pathToApp, sourceFolder, scriptsFolder, componentsFolder); const pathToMainJs = path.join(pathToApp, stagingFolder, javascriptFolder, 'main.js'); const pathToBundleJs = path.join(pathToApp, stagingFolder, javascriptFolder, 'bundle.js'); + const exchangeComponentsFolder = oraclejetConfigJson.paths.source.exchangeComponents || 'jet_components'; + const pathToNodeModules = path.join(pathToApp, 'node_modules'); + const pathToAppHooks = path.join(pathToApp, `scripts/hooks`); + const pathToExchangeComponents = path.join(pathToApp, exchangeComponentsFolder); const pathToIndexHtml = path.join(pathToApp, stagingFolder, 'index.html'); + const stylesFolder = oraclejetConfigJson.paths.source.styles; return { componentsFolder, stagingFolder, @@ -234,13 +332,19 @@ module.exports = { typescriptFolder, pathToApp, pathToBuiltComponents, + pathToSourceComponents, pathToMainJs, pathToBundleJs, - pathToIndexHtml + exchangeComponentsFolder, + pathToNodeModules, + pathToExchangeComponents, + pathToIndexHtml, + pathToAppHooks, + stylesFolder } }, getTemplatesDir: function _getTempatesDir() { return path.resolve(__dirname, '..', 'templates'); } -}; +}; \ No newline at end of file diff --git a/test/vdomTest.js b/test/vdomTest.js index 92771d1..1116f2b 100644 --- a/test/vdomTest.js +++ b/test/vdomTest.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -7,14 +7,38 @@ const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); - const Ojet = require('../ojet'); const util = require('./util'); -const testDir = path.resolve('../test_result'); -const appDir = path.resolve(testDir, util.VDOM_APP_NAME); +const appDir = util.getAppDir(util.VDOM_APP_NAME); describe('VDOM Test', () => { + before(async () => { + if (!util.noScaffold()) { + util.removeAppDir(util.VDOM_APP_NAME); + + // Scaffold vdomTest application using API + const ojet = new Ojet({ cwd: util.testDir, logs: false }); + let executeOptions = {}; + try { + executeOptions = { + task: 'create', + parameters: [util.VDOM_APP_NAME], + options: { + template: 'basic', + vdom: true + } + }; + await ojet.execute(executeOptions); + + assert.ok(true); + } catch (e) { + console.log(e); + assert.ok(false, `Error running ojet.execute with ${executeOptions}`); + } + } + }); + describe('Scaffold', () => { it('should have path_mapping.json at root of the app with no baseUrl', () => { const pathToPathMappingJson = path.resolve(appDir, 'path_mapping.json'); @@ -50,7 +74,7 @@ describe('VDOM Test', () => { sourceFolder, typescriptFolder, componentsFolder - } = util.getAppPathData({ appName: util.VDOM_APP_NAME }) + } = util.getAppPathData(util.VDOM_APP_NAME) const componentName = 'vcomp-1'; const pathToComponentTsx = path.join( pathToApp, @@ -104,70 +128,24 @@ describe('VDOM Test', () => { } }); - describe('Webpack', () => { - describe('Add webpack', () => { - if (!util.noScaffold()) { - it('should run "ojet add webpack"', async () => { - const { pathToApp } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const ojet = new Ojet({ cwd: pathToApp, logs: false }); - try { - await ojet.execute({ - task: 'add', - parameters: ['webpack'] - }); - assert.ok(true); - } catch { - assert.ok(false); - } - }); - } - it('should check that webpack and its dependencies are listed in package.json', () => { - const { pathToApp } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const packageJson = fs.readJsonSync(path.join(pathToApp, 'package.json')); - util.WEBPACK_DEPENDENCIES.forEach((dependency) => { - assert.ok(packageJson.devDependencies[dependency], `${dependency} not installed`); - }); - }); - it('should check that bundler and bundleName properties were added to oraclejetconfig.json', () => { - const oraclejetConfigJson = util.getOracleJetConfigJson({ appName: util.VDOM_APP_NAME }); - assert.ok(oraclejetConfigJson.bundler === 'webpack', 'bundler not equal to "webpack"'); - assert.ok(oraclejetConfigJson.bundleName === 'bundle.js', 'bundleName not equal to "bundle.js'); - }); - }); - describe('Build debug', () => { - it('should build in debug mode', async () => { - const { pathToApp } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const ojet = new Ojet({ cwd: pathToApp, logs: false }); - try { - await ojet.execute({ task: 'build' }); - assert.ok(true); - } catch { - assert.ok(false); - } - }); - }); - describe('Build release', () => { - it('should build in release mode', async () => { - const { pathToApp } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const ojet = new Ojet({ cwd: pathToApp, logs: false }); - try { - await ojet.execute({ task: 'build', options: { release: true }}); - assert.ok(true); - } catch { - assert.ok(false); - } - }); - it('should have bundle file', () => { - const { pathToBundleJs } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const bundleFileExists = fs.existsSync(pathToBundleJs); - assert.ok(bundleFileExists, `${pathToBundleJs} does not exist`); - }); - it('should not load require.js in index.html', () => { - const { pathToIndexHtml } = util.getAppPathData({ appName: util.VDOM_APP_NAME }); - const indexHtmlContent = fs.readFileSync(pathToIndexHtml, { encoding: 'utf-8' }); - const loadsRequireJs = /require\/require\.js'><\/script>/.test(indexHtmlContent); - assert.ok(!loadsRequireJs, `${pathToIndexHtml} loads require.js`); + describe('Add (pwa)', () => { + if (!util.noBuild()) { + it('should have appropriate vdom files and folders to cache in sw.js on running ojet add pwa', async () => { + await util.execCmd(`${util.OJET_APP_COMMAND} add pwa`, { cwd: appDir }, true, true); + await util.execCmd(`${util.OJET_APP_COMMAND} build --release`, { cwd: appDir }, true, true); + const {pathToApp, stagingFolder} = util.getAppPathData(util.VDOM_APP_NAME); + const pathToSWFile = path.join(pathToApp, stagingFolder, 'sw.js'); + const swJsContent = fs.readFileSync(pathToSWFile, { encoding: 'utf-8' }); + const regex = /resourcesToCache=(?.*)\;self/gm; + const match = regex.exec(swJsContent); + const retrievedResourcesToCache = match.groups.resourcesToCache; + const requiredResourcesToCache = ['index.js', 'index.html', 'bundle.js', 'manifest.json', 'components/', 'libs/', 'styles/']; + const swJSHasRequiredResourcesTocache = requiredResourcesToCache.every((resource) => { + return retrievedResourcesToCache.includes(resource); + }) + const errorMessage = `sw.js does not contain right files and folders to cache for a vdom app.`; + assert.equal(swJSHasRequiredResourcesTocache, true, errorMessage); }); - }); + } }); }); diff --git a/test/webTest.js b/test/webTest.js index 2ef0dae..c5fb9f2 100644 --- a/test/webTest.js +++ b/test/webTest.js @@ -1,5 +1,5 @@ /** - Copyright (c) 2015, 2021, Oracle and/or its affiliates. + Copyright (c) 2015, 2022, Oracle and/or its affiliates. Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ @@ -9,13 +9,45 @@ const fs = require('fs-extra'); const path = require('path'); const _ = require('lodash'); +const constants = require('../lib/util/constants'); +const ojetUtil = require('../lib/util/utils'); +const ojetPaths = require('../lib/util/paths'); + const util = require('./util'); let filelist; -const testDir = path.resolve('../test_result'); -const appDir = path.resolve(testDir, util.APP_NAME); +const appDir = util.getAppDir(util.APP_NAME); describe('Web Test', () => { + before(async () => { + if (!util.noScaffold()) { + const platform = util.getPlatform(process.env.OS); + + util.removeAppDir(util.APP_NAME); + util.removeAppDir(util.TEST_DIR); + + // Scaffold a basic web app + let result = await util.execCmd(`${util.OJET_COMMAND} create ${util.APP_NAME} --norestore=true`, { cwd: util.testDir }); + console.log(result.stdout); + // Check that it output the right text to the command line + assert.strictEqual(util.norestoreSuccess(result.stdout), true, result.stderr); + // Restore + result = await util.execCmd(`${util.OJET_APP_COMMAND} restore`, { cwd: util.getAppDir(util.APP_NAME) }); + console.log(result.stdout); + + // Scaffold a basic app without a name + result = await util.execCmd(`${util.OJET_COMMAND} create --norestore=true`, { cwd: util.testDir }); + // Check that it worked + assert.equal(util.norestoreSuccess(result.stdout) || /Your app is/.test(result.stdout), true, result.error); + + if (!util.noHybrid()) { + // Add hybrid + let result = await util.execCmd(`${util.OJET_APP_COMMAND} add hybrid --platform=${platform}`, { cwd: util.getAppDir(util.APP_NAME) }); + console.log(result.stdout); + } + } + }); + describe('Check essential files', () => { it('should have package.json', () => { filelist = fs.readdirSync(appDir); @@ -38,13 +70,13 @@ describe('Web Test', () => { }); } it('should not have bundle.js', async () => { - const{ pathToBundleJs } = util.getAppPathData({ appName: util.APP_NAME }) + const{ pathToBundleJs } = util.getAppPathData(util.APP_NAME) const hasBundleJs = fs.existsSync(pathToBundleJs); assert.ok(!hasBundleJs, pathToBundleJs); }) }); - describe('Build (Release)', () => { + describe('Build (Release) without the bundle name attribute', () => { if (!util.noBuild()) { it('should build release js app', async () => { const result = await util.execCmd(`${util.OJET_APP_COMMAND} build web --release`, { cwd: util.getAppDir(util.APP_NAME) }); @@ -52,17 +84,64 @@ describe('Web Test', () => { }); } it('should have bundle.js', async () => { - const{ pathToBundleJs } = util.getAppPathData({ appName: util.APP_NAME }) + const{ pathToBundleJs } = util.getAppPathData(util.APP_NAME) const hasBundleJs = fs.existsSync(pathToBundleJs); assert.ok(hasBundleJs, pathToBundleJs); }) it('should not have main.js', async () => { - const{ pathToMainJs } = util.getAppPathData({ appName: util.APP_NAME }) + const{ pathToMainJs } = util.getAppPathData(util.APP_NAME) const hasMainJs = fs.existsSync(pathToMainJs); assert.ok(!hasMainJs, pathToMainJs); }) }); + describe('Build (Release) with any given bundle name other than main.js', () => { + if (!util.noBuild()) { + it('should build release js app', async () => { + // get the oraclejetconfig.json file and add bundleName attribute value to .js: + const oracleJetConfigJSON = util.getOracleJetConfigJson(util.APP_NAME); + oracleJetConfigJSON.bundleName = `${util.API_APP_NAME}.js`; + util.writeOracleJetConfigJson(util.APP_NAME, oracleJetConfigJSON); + const result = await (util.execCmd(`${util.OJET_APP_COMMAND} build web --release`, { cwd: util.getAppDir(util.APP_NAME) })); + // Delete the bundleName attribute. Having it might cause the subsequent case(s) to fail: + delete oracleJetConfigJSON.bundleName; + util.writeOracleJetConfigJson(util.APP_NAME, oracleJetConfigJSON); + assert.equal(util.buildSuccess(result.stdout), true, result.error); + }); + } + it(`should have ${util.API_APP_NAME}.js`, async () => { + // retrieve the path for the created js file and check its presence: + const{ pathToApp, stagingFolder, javascriptFolder } = util.getAppPathData(util.APP_NAME) + const pathToBundleNameJs = path.join(pathToApp, stagingFolder, javascriptFolder, `${util.API_APP_NAME}.js`); + const hasBundleNameJs = fs.existsSync(pathToBundleNameJs); + assert.ok(hasBundleNameJs, pathToBundleNameJs); + }) + it('should not have main.js', async () => { + const{ pathToMainJs } = util.getAppPathData(util.APP_NAME) + const hasMainJs = fs.existsSync(pathToMainJs); + assert.ok(!hasMainJs, pathToMainJs); + }) + }); + + describe('Build (Release) with main.js as the bundleName', () => { + if (!util.noBuild()) { + it('should build release js app', async () => { + const oracleJetConfigJSON = util.getOracleJetConfigJson(util.APP_NAME); + oracleJetConfigJSON.bundleName = 'main.js'; + util.writeOracleJetConfigJson(util.APP_NAME, oracleJetConfigJSON); + const result = await util.execCmd(`${util.OJET_APP_COMMAND} build web --release`, { cwd: util.getAppDir(util.APP_NAME) }); + delete oracleJetConfigJSON.bundleName; + util.writeOracleJetConfigJson(util.APP_NAME, oracleJetConfigJSON); + assert.equal(util.buildSuccess(result.stdout), true, result.error); + }); + } + it('should have main.js', async () => { + const{ pathToMainJs } = util.getAppPathData(util.APP_NAME) + const hasMainJs = fs.existsSync(pathToMainJs); + assert.ok(hasMainJs, pathToMainJs); + }) + }); + // // BuildWithComponent verifies that proper path mapping is set for a component. // @@ -103,7 +182,7 @@ describe('Web Test', () => { }); it('release build: path mapping to minified component', async () => { await util.execCmd(`${util.OJET_APP_COMMAND} build web --release`, { cwd: util.getAppDir(util.APP_NAME) }); - const{ pathToBundleJs } = util.getAppPathData({ appName: util.APP_NAME }) + const{ pathToBundleJs } = util.getAppPathData(util.APP_NAME); const bundleContent = fs.readFileSync(pathToBundleJs); assert.equal(bundleContent.toString().match(`jet-composites/${testComp}/1.0.0/min`), `jet-composites/${testComp}/1.0.0/min`, `bundle.js should contain the minified component ${testComp}`); @@ -220,7 +299,7 @@ describe('Paths Mapping Test', () => { if (!util.noServe()) { describe('serve', () => { it('should serve with nobuild', async () => { - const result = await util.execCmd(`${util.OJET_APP_COMMAND} serve web --no-build`, { cwd: util.getAppDir(util.APP_NAME), maxBuffer: 1024 * 30000, timeout:40000, killSignal:'SIGTERM' }, true); + const result = await util.execCmd(`${util.OJET_APP_COMMAND} serve web --no-build`, { cwd: util.getAppDir(util.APP_NAME), maxBuffer: 1024 * 20000, timeout:30000, killSignal:'SIGTERM' }, true); assert.equal(/Watching files/i.test(result.stdout), true, result.stdout); result.process.kill(); }); @@ -231,9 +310,6 @@ describe('add theming', () => { it('should add pcss generator', async () => { const result = await util.execCmd(`${util.OJET_APP_COMMAND} add theming`, { cwd: appDir }); assert.equal(/add pcss complete/.test(result.stdout), true, result.stdout); - - // Recopy oraclejet-tooling - util.copyOracleJetTooling(`${util.APP_NAME}`); }); }); @@ -294,4 +370,75 @@ describe('Build with cdn', () => { assert.ok(!hasLibNotInWhitelist, 'libs should not contain libraries referenced from the cdn'); }); }); + + describe('Customization Test', () => { + it('should load oraclejet build config', () => { + const wd = process.cwd(); + process.chdir(util.getAppDir(util.APP_NAME)); + const buildOps = ojetUtil.getBuildCustomizedConfig(); + process.chdir(wd); + assert(!_.isEmpty(buildOps)); + }); + + it('should load oraclejet serve config', () => { + const wd = process.cwd(); + process.chdir(util.getAppDir(util.APP_NAME)); + const serveOps = ojetUtil.getServeCustomizedConfig(); + process.chdir(wd); + assert(!_.isEmpty(serveOps)); + }); + + it('should validate serve config', () => { + const wd = process.cwd(); + process.chdir(util.getAppDir(util.APP_NAME)); + const serveOps = ojetUtil.getServeCustomizedConfig(); + process.chdir(wd); + const validServe = ojetUtil.validateServeOptions(serveOps); + assert(_.isEmpty(validServe)); + }); + + + it('should get default paths', () => { + const defaultPaths = ojetPaths.getDefaultPaths(); + assert(!_.isEmpty(defaultPaths)); + }); + + it('should validate configured paths', () => { + const defaultPaths = ojetPaths.getDefaultPaths(); + assert(defaultPaths.source == 'src'); + assert(defaultPaths.sourceWeb == 'src-web'); + assert(defaultPaths.sourceHybrid == 'src-hybrid'); + assert(defaultPaths.sourceJavascript == 'js'); + assert(defaultPaths.sourceThemes == 'themes'); + assert(defaultPaths.stagingHybrid == 'hybrid'); + assert(defaultPaths.stagingWeb == 'web'); + assert(defaultPaths.stagingThemes == constants.APP_STAGED_THEMES_DIRECTORY); + }); + + + it('should get configured paths', () => { + const confPaths = ojetPaths.getConfiguredPaths(util.getAppDir(util.APP_NAME)); + assert(!_.isEmpty(confPaths)); + }); + + it('should validate configured paths', () => { + const defaultPaths = ojetPaths.getDefaultPaths(); + const confPaths = ojetPaths.getConfiguredPaths(util.getAppDir(util.APP_NAME)); + assert(_.isEqual(confPaths, defaultPaths)); + }); + + it('should validate is cwd is JET App', () => { + const wd = process.cwd(); + process.chdir(util.getAppDir(util.APP_NAME)); + const isJetApp = ojetUtil.ensureJetApp(); + process.chdir(wd); + assert(isJetApp); + }); + + it('should validate util ensure parameters', () => { + assert.doesNotThrow(() => { + ojetUtil.ensureParameters('component'); + }); + }); + }); }); diff --git a/test/webpackTest.js b/test/webpackTest.js new file mode 100644 index 0000000..2bcae4c --- /dev/null +++ b/test/webpackTest.js @@ -0,0 +1,161 @@ +/** + Copyright (c) 2015, 2022, Oracle and/or its affiliates. + Licensed under The Universal Permissive License (UPL), Version 1.0 + as shown at https://oss.oracle.com/licenses/upl/ + +*/ +const assert = require('assert'); +const fs = require('fs-extra'); +const path = require('path'); +const Ojet = require('../ojet'); +const util = require('./util'); + +describe('Webpack Test', () => { + before(async () => { + if (!util.noScaffold()) { + // Create legacy webpack app. Will remove once end-to-end webpack + // support is complete + util.removeAppDir(util.WEBPACK_LEGACY_APP_NAME); + // Scaffold vdomTest application using API + const ojet = new Ojet({ cwd: util.testDir, logs: false }); + let executeOptions = {}; + try { + executeOptions = { + task: 'create', + parameters: [util.WEBPACK_LEGACY_APP_NAME], + options: { + template: path.join(util.getTemplatesDir(), util.WEBPACK_LEGACY_APP_NAME) + } + }; + await ojet.execute(executeOptions); + assert.ok(true); + // We need the locally built copy of oraclejet-tooling before the merge + // to pick up the latest changes. Will remove after the merge + util.copyOracleJetTooling(util.WEBPACK_LEGACY_APP_NAME); + } catch (e) { + console.log(e); + assert.ok(false, `Error running ojet.execute with ${executeOptions}`); + } + } + if (!util.noScaffold()) { + // Create end-to-end webpack app + util.removeAppDir(util.WEBPACK_APP_NAME); + // Scaffold vdomTest application using API + const ojet = new Ojet({ cwd: util.testDir, logs: false }); + let executeOptions = {}; + try { + executeOptions = { + task: 'create', + parameters: [util.WEBPACK_APP_NAME], + options: { + template: 'basic', + vdom: true, + webpack: true + } + }; + await ojet.execute(executeOptions); + assert.ok(true); + } catch (e) { + console.log(e); + assert.ok(false, `Error running ojet.execute with ${executeOptions}`); + } + } + }); + describe('Webpack', () => { + describe('Scaffold', () => { + it('should check that webpack and its dependencies are listed in package.json', () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_APP_NAME); + const packageJson = fs.readJsonSync(path.join(pathToApp, 'package.json')); + util.WEBPACK_DEPENDENCIES.forEach((dependency) => { + assert.ok(packageJson.devDependencies[dependency], `${dependency} not installed`); + }); + }); + it(`should check that ${util.OJET_CONFIG_JS} was added`, () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_APP_NAME); + const pathToOjetConfigJs = path.join(pathToApp, util.OJET_CONFIG_JS); + assert.ok(fs.existsSync(pathToOjetConfigJs), `${util.OJET_CONFIG_JS} not in application`); + }); + }); + describe('Build (Debug)', () => { + it('should build in debug mode', async () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_APP_NAME); + const ojet = new Ojet({ cwd: pathToApp, logs: false }); + try { + await ojet.execute({ task: 'build' }); + assert.ok(true); + } catch { + assert.ok(false); + } + }); + }); + describe('Build (Release)', () => { + it('should build in release mode', async () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_APP_NAME); + const ojet = new Ojet({ cwd: pathToApp, logs: false }); + try { + await ojet.execute({ task: 'build', options: { release: true }}); + assert.ok(true); + } catch { + assert.ok(false); + } + }); + }); + }); + describe('Webpack (Legacy)', () => { + describe('Scaffold', () => { + it('should check that webpack and its dependencies are listed in package.json', () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const packageJson = fs.readJsonSync(path.join(pathToApp, 'package.json')); + util.WEBPACK_LEGACY_DEPENDENCIES.forEach((dependency) => { + assert.ok(packageJson.devDependencies[dependency], `${dependency} not installed`); + }); + }); + it('should check that bundler and bundleName properties were added to oraclejetconfig.json', () => { + const oraclejetConfigJson = util.getOracleJetConfigJson(util.WEBPACK_LEGACY_APP_NAME); + assert.ok(oraclejetConfigJson.bundler === 'webpack', 'bundler not equal to "webpack"'); + assert.ok(oraclejetConfigJson.bundleName === 'bundle.js', 'bundleName not equal to "bundle.js'); + }); + }); + describe('Build (Debug)', () => { + it('should build in debug mode', async () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const ojet = new Ojet({ cwd: pathToApp, logs: false }); + try { + await ojet.execute({ task: 'build' }); + assert.ok(true); + } catch { + assert.ok(false); + } + }); + }); + describe('Build (Release)', () => { + it('should build in release mode', async () => { + const { pathToApp } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const ojet = new Ojet({ cwd: pathToApp, logs: false }); + try { + await ojet.execute({ task: 'build', options: { release: true }}); + assert.ok(true); + } catch { + assert.ok(false); + } + }); + it('should have bundle.js file', () => { + const { pathToBundleJs } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const bundleFileExists = fs.existsSync(pathToBundleJs); + assert.ok(bundleFileExists, `${pathToBundleJs} does not exist`); + }); + it('should have bundle.js script in index.html', () => { + const { pathToIndexHtml } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const indexHtmlContent = fs.readFileSync(pathToIndexHtml, { encoding: 'utf-8' }); + const loadsBundleJs = /bundle\.js(?:'|")><\/script>/.test(indexHtmlContent); + assert.ok(loadsBundleJs, `${pathToIndexHtml} does not load bundle.js`); + }); + it('should not load require.js in index.html', () => { + const { pathToIndexHtml } = util.getAppPathData(util.WEBPACK_LEGACY_APP_NAME); + const indexHtmlContent = fs.readFileSync(pathToIndexHtml, { encoding: 'utf-8' }); + const loadsRequireJs = /require\/require\.js(?:'|")><\/script>/.test(indexHtmlContent); + assert.ok(!loadsRequireJs, `${pathToIndexHtml} loads require.js`); + }) + }); + }); +}); \ No newline at end of file diff --git a/util/index.js b/util/index.js deleted file mode 100644 index d1859ca..0000000 --- a/util/index.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - 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'; - -const path = require('path'); -const fs = require('fs-extra'); - -module.exports = -{ - getDirectories(source) { - // util function to get directories listing - return fs.readdirSync(source).filter(file => - fs.statSync(path.join(source, file)).isDirectory()); - }, - fsExistsSync(filePath) { - try { - fs.statSync(filePath); - return true; - } catch (err) { - // file/directory does not exist - return false; - } - } -}; -