From bca8c923e17d8c670991d3a966f4f6d1f59555f0 Mon Sep 17 00:00:00 2001 From: Ben Moroze Date: Thu, 7 Oct 2021 16:27:44 -0400 Subject: [PATCH] Release 11.1.0 --- README.md | 4 +- RELEASENOTES.md | 4 + common/template/index.js | 2 +- common/template/npm.js | 82 +++++++++---------- config.js | 2 +- .../templates/mytheme/web/mytheme.scss | 26 +++--- generators/app/templates/common/package.json | 4 +- .../hybrid/templates/common/package.json | 4 +- ojet.js | 5 +- package.json | 6 +- template/component/js/component.json | 2 +- template/component/js/loader.js | 2 +- template/component/ts/component.json | 2 +- template/component/ts/loader.ts | 2 +- template/component/tsx/@component@.tsx | 2 +- test/componentTest.js | 2 +- test/jetpackTest.js | 74 +++++++++++++++++ test/setup.js | 7 +- .../resource-component/component.json | 5 ++ .../templates/resource-component/js/logger.js | 11 +++ .../resource-component/js/resource.js | 11 +++ .../templates/resource-component/resource.css | 3 + .../templates/resource-component/ts/logger.ts | 3 + .../resource-component/ts/resource.ts | 5 ++ test/templates/webTsApiTest/package.json | 4 +- .../webTsApiTest/src/js/path_mapping.json | 24 +++++- .../my-component/my-component-viewModel.ts | 2 +- test/util/index.js | 18 ++-- test/vdomTest.js | 67 +++++++++++++++ 29 files changed, 292 insertions(+), 93 deletions(-) create mode 100644 test/templates/resource-component/component.json create mode 100644 test/templates/resource-component/js/logger.js create mode 100644 test/templates/resource-component/js/resource.js create mode 100644 test/templates/resource-component/resource.css create mode 100644 test/templates/resource-component/ts/logger.ts create mode 100644 test/templates/resource-component/ts/resource.ts diff --git a/README.md b/README.md index 2a2ff6c..6449074 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @oracle/ojet-cli 11.0.0 +# @oracle/ojet-cli 11.1.0 ## About the module This module contains a command line interface for Oracle JET web and hybrid mobile application development. @@ -64,7 +64,7 @@ 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=jet1100&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=jet1110&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. diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 2955ddd..113ab7e 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,9 @@ ## Release Notes for ojet-cli ## +### 11.1.0 + +* ojs/ojcss is supported as a name for the ojcss plugin + ### 11.0.0 * Support for es5 code for IE11 has been removed. There will no longer be a "main_es5.js" or "batch_es5.js" generated in builds. Therefore, release builds will now directly load the bundle.js after bundling and minifying all code from main.js and the application into it. Previous versions attempted to modify portions of the main.js to refer to the bundled and minified bundle.js for release builds. diff --git a/common/template/index.js b/common/template/index.js index 7cea5bd..087e30c 100644 --- a/common/template/index.js +++ b/common/template/index.js @@ -17,7 +17,7 @@ const CONSTANTS = require('../../lib/utils.constants'); const _HYBRID = 'hybrid'; const _WEB = 'web'; -const _TEMPLATES_NPM_URL = '@oracle/oraclejet-templates@~11.0.0'; +const _TEMPLATES_NPM_URL = '@oracle/oraclejet-templates@~11.1.0'; module.exports = { diff --git a/common/template/npm.js b/common/template/npm.js index 92d9ba9..28023b3 100644 --- a/common/template/npm.js +++ b/common/template/npm.js @@ -78,50 +78,44 @@ function _copyNpmTemplate(generator, templateSpec, destination) { const filePathFromTemplateRoot = filePath.split(templateSegment).pop(); const isPathMappingJson = path.basename(filePath) === 'path_mapping.json'; const isIndexHtml = path.basename(filePath) === 'index.html'; - if (isVDOMTemplate) { - if (isPathMappingJson) { - const pathMappingJson = fs.readJSONSync(filePath); - // baseUrl will be set from javascript location in oraclejetconfig.json - delete pathMappingJson.baseUrl; - // write to root of the app and not /src - filePathDest = path.join(destination, '../path_mapping.json'); - fs.writeJSONSync(filePathDest, pathMappingJson, { spaces: 2 }); - } else if (isIndexHtml) { - // remove content between injector:theme and injector:scripts tokens, - // they will be added during the build - let indexHTML = fs.readFileSync(filePath, { encoding: 'utf-8' }); - const scriptsInjector = injectorUtils.scriptsInjector; - const themeInjector = injectorUtils.themeInjector; - // remove content between injector:scripts token - indexHTML = injectorUtils.removeInjectorTokensContent({ - content: indexHTML, - pattern: injectorUtils.getInjectorTagsRegExp( - scriptsInjector.startTag, - scriptsInjector.endTag - ), - eol: injectorUtils.getLineEnding(indexHTML), - startTag: `\t\t${scriptsInjector.startTag}`, - endTag: `\t\t${scriptsInjector.endTag}` - }); - // remove content between injector:theme token - indexHTML = injectorUtils.removeInjectorTokensContent({ - content: indexHTML, - pattern: injectorUtils.getInjectorTagsRegExp( - themeInjector.startTag, - themeInjector.endTag - ), - eol: injectorUtils.getLineEnding(indexHTML), - startTag: `\t\t${themeInjector.startTag}`, - endTag: `\t\t${themeInjector.endTag}` - }); - // write to /src - filePathDest = path.join(destination, '..', filePathFromTemplateRoot); - fs.outputFileSync(filePathDest, indexHTML, { encoding: 'utf-8' }); - } else { - // copy to /src - filePathDest = path.join(destination, '..', filePathFromTemplateRoot); - fs.copySync(filePath, filePathDest); - } + if (isVDOMTemplate && isPathMappingJson) { + const pathMappingJson = fs.readJSONSync(filePath); + // baseUrl will be set from javascript location in oraclejetconfig.json + delete pathMappingJson.baseUrl; + // write to root of the app and not /src + filePathDest = path.join(destination, '../path_mapping.json'); + fs.writeJSONSync(filePathDest, pathMappingJson, { spaces: 2 }); + } else if (isIndexHtml) { + // remove content between injector:theme and injector:scripts tokens, + // they will be added during the build + let indexHTML = fs.readFileSync(filePath, { encoding: 'utf-8' }); + const scriptsInjector = injectorUtils.scriptsInjector; + const themeInjector = injectorUtils.themeInjector; + // remove content between injector:scripts token + indexHTML = injectorUtils.removeInjectorTokensContent({ + content: indexHTML, + pattern: injectorUtils.getInjectorTagsRegExp( + scriptsInjector.startTag, + scriptsInjector.endTag + ), + eol: injectorUtils.getLineEnding(indexHTML), + startTag: `\t\t${scriptsInjector.startTag}`, + endTag: `\t\t${scriptsInjector.endTag}` + }); + // remove content between injector:theme token + indexHTML = injectorUtils.removeInjectorTokensContent({ + content: indexHTML, + pattern: injectorUtils.getInjectorTagsRegExp( + themeInjector.startTag, + themeInjector.endTag + ), + eol: injectorUtils.getLineEnding(indexHTML), + startTag: `\t\t${themeInjector.startTag}`, + endTag: `\t\t${themeInjector.endTag}` + }); + // write to /src + filePathDest = path.join(destination, '..', filePathFromTemplateRoot); + fs.outputFileSync(filePathDest, indexHTML, { encoding: 'utf-8' }); } else { // copy to /src filePathDest = path.join(destination, '..', filePathFromTemplateRoot); diff --git a/config.js b/config.js index 1914f78..9ae0c1c 100644 --- a/config.js +++ b/config.js @@ -676,7 +676,7 @@ const config = { 'ojet serve --cssvars=enabled', 'ojet serve ios --no-livereload --emulator="iPad-Air, 10.2"', 'ojet serve --device --release', - 'ojet serve windows --no-sass --livereload-port=357230', + 'ojet serve windows --no-sass --livereload-port=35723', 'ojet serve android --browser', 'ojet serve --browser=edge', 'ojet serve ios --device --build-config ./buildConfig.json --theme myCustomTheme', diff --git a/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss b/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss index 76a311a..daee183 100644 --- a/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss +++ b/generators/add-pcss-theme/templates/mytheme/web/mytheme.scss @@ -1,23 +1,21 @@ - -// Note that the order in the aggregating file is important -// -// 1. custom variables file: Due to the way sass default works, -// the custom variable file must be imported before the platform theme -// aggregating file (where the platform variable file will be imported). -// 2. platform theme aggregating file - +// In theme.json the generatedFileType defaults to 'add-on', therefore only the +// import "_<%= themename %>.cssvars.settings.scss" is uncommented here by default. +// 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"; - +// @import "_<%= themename %>.sass.settings.scss"; + // Imports all jet components styles -@import "<%= importcomponents %>"; - +// @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 diff --git a/generators/app/templates/common/package.json b/generators/app/templates/common/package.json index 41b23e3..a26427b 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.0.0" + "@oracle/oraclejet": "~11.1.0" }, "devDependencies": { "fs-extra": "^8.1.0", "glob": "^7.1.1", "underscore": "^1.10.2", - "@oracle/oraclejet-tooling": "~11.0.0" + "@oracle/oraclejet-tooling": "~11.1.0" }, "engines": { "node": ">=12.21.0" diff --git a/generators/hybrid/templates/common/package.json b/generators/hybrid/templates/common/package.json index e88b786..a9a73d6 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.0.0" + "@oracle/oraclejet": "~11.1.0" }, "devDependencies": { "fs-extra": "^8.1.0", "glob": "^7.1.1", "underscore": "^1.10.2", - "@oracle/oraclejet-tooling": "~11.0.0" + "@oracle/oraclejet-tooling": "~11.1.0" }, "engines": { "node": ">=12.21.0" diff --git a/ojet.js b/ojet.js index 536fd6a..7e11eb0 100644 --- a/ojet.js +++ b/ojet.js @@ -28,13 +28,14 @@ class Ojet { * @param {Object} options.options options to execute the task with * @returns {Promise} */ - async execute({ task, scope, parameters = [], options }) { + async execute({ task, scope, parameters = [], options = {} }) { this._setOptions(); let result; // eslint-disable-next-line prefer-rest-params this._logExecuteSummary(arguments[0]); try { - result = await tasks([task, scope, ...parameters], options); + const tasksList = [task, ...(scope ? [scope, ...parameters] : parameters)]; + result = await tasks(tasksList, options); } catch (error) { result = Promise.reject(error); } finally { diff --git a/package.json b/package.json index aa2b52e..cb7c4b8 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@oracle/ojet-cli", - "version": "11.0.0", + "version": "11.1.0", "description": "Oracle JET Command Line Interface", "license": "UPL-1.0", - "homepage": "http://oraclejet.org", + "homepage": "http://www.oracle.com/jet", "bin": { "ojet": "bin/ojet" }, @@ -14,7 +14,7 @@ "inquirer": "~6.2.2", "minimist": "^1.2.0", "xmldom": "0.5.0", - "@oracle/oraclejet-tooling": "~11.0.0" + "@oracle/oraclejet-tooling": "~11.1.0" }, "engines": { "node": ">=12.21.0" diff --git a/template/component/js/component.json b/template/component/js/component.json index 9b61500..5a959d0 100644 --- a/template/component/js/component.json +++ b/template/component/js/component.json @@ -1,7 +1,7 @@ { "name": "@component-name@", "version": "1.0.0", - "jetVersion": "^11.0.0", + "jetVersion": "^11.1.0", "displayName": "A user friendly, translatable name of the component.", "description": "A translatable high-level description for the component.", "properties": { diff --git a/template/component/js/loader.js b/template/component/js/loader.js index b2eb7b1..b65bdb6 100644 --- a/template/component/js/loader.js +++ b/template/component/js/loader.js @@ -4,7 +4,7 @@ as shown at https://oss.oracle.com/licenses/upl/ */ -define(['ojs/ojcomposite', 'text!./@component-name@-view.html', './@component-name@-viewModel', 'text!./component.json', 'css!./@component-name@-styles'], +define(['ojs/ojcomposite', 'text!./@component-name@-view.html', './@component-name@-viewModel', 'text!./component.json', 'css!./@component-name@-styles.css'], function(Composite, view, viewModel, metadata) { Composite.register('@full-component-name@', { view: view, diff --git a/template/component/ts/component.json b/template/component/ts/component.json index 9b61500..5a959d0 100644 --- a/template/component/ts/component.json +++ b/template/component/ts/component.json @@ -1,7 +1,7 @@ { "name": "@component-name@", "version": "1.0.0", - "jetVersion": "^11.0.0", + "jetVersion": "^11.1.0", "displayName": "A user friendly, translatable name of the component.", "description": "A translatable high-level description for the component.", "properties": { diff --git a/template/component/ts/loader.ts b/template/component/ts/loader.ts index a4554cf..73f9ccc 100644 --- a/template/component/ts/loader.ts +++ b/template/component/ts/loader.ts @@ -2,7 +2,7 @@ import Composite = require("ojs/ojcomposite"); import * as view from "text!./@component-name@-view.html"; import viewModel from "./@component-name@-viewModel"; import * as metadata from "text!./component.json"; -import "css!./@component-name@-styles"; +import "css!./@component-name@-styles.css"; Composite.register("@full-component-name@", { view: view, diff --git a/template/component/tsx/@component@.tsx b/template/component/tsx/@component@.tsx index bd30c9f..2d4c6b6 100644 --- a/template/component/tsx/@component@.tsx +++ b/template/component/tsx/@component@.tsx @@ -1,7 +1,7 @@ import { customElement, ExtendGlobalProps } from "ojs/ojvcomponent"; import { h, Component, ComponentChild } from "preact"; import componentStrings = require("ojL10n!./resources/nls/@component-name@-strings"); -import "css!./@component-name@-styles"; +import "css!./@component-name@-styles.css"; type Props = { message?: string; diff --git a/test/componentTest.js b/test/componentTest.js index 51bc170..7771cb6 100644 --- a/test/componentTest.js +++ b/test/componentTest.js @@ -420,7 +420,7 @@ function buildTsComponentAppWithDeclarationFalse({ appName }) { function omitComponentVerstionTest({ appName }) { describe(`Build ${appName} with --${util.OMIT_COMPONENT_VERSION_FLAG}`, () => { - const components = [COMPONENT_NAME, COMPONENT_NAME_COMPOSITE, COMPONENT_NAME_DEMO, VCOMPONENT_NAME]; + const components = [COMPONENT_NAME, COMPONENT_NAME_COMPOSITE, COMPONENT_NAME_DEMO, VCOMPONENT_NAME, EXCHANGE_COMPONENT_PACK]; if (!util.noBuild()) { it(`should build ${appName} with --${util.OMIT_COMPONENT_VERSION_FLAG}`, async () => { const command = `${util.OJET_APP_COMMAND} build --${util.OMIT_COMPONENT_VERSION_FLAG}`; diff --git a/test/jetpackTest.js b/test/jetpackTest.js index 6201011..91419ce 100644 --- a/test/jetpackTest.js +++ b/test/jetpackTest.js @@ -16,6 +16,7 @@ const PACK_NAME = 'pack-1'; const DEFAULT_PACK_VERSION = '1.0.0'; const COMPONENT_NAME = 'comp-1'; const VCOMPONENT_NAME = 'vcomp-1'; +const RESOURCE_COMPONENT_NAME = 'resources'; const EXCHANGE_PACK = 'oj-gbu-app'; const EXCHANGE_PACK_VERSION = '3.0.0'; const EXCHANGE_PACK_BUNDLE = 'shell-bundle'; @@ -229,6 +230,71 @@ function createVComponentInPackTest({ appName, scriptsFolder, pack, component }) }); } +function createResourceComponentInPackTest({ appName, pack, scriptsFolder, resourceComponent, component }) { + if (!util.noScaffold()) { + before(() => { + // Create resource component + const { pathToApp, sourceFolder, componentsFolder } = util.getAppPathData({ appName }); + const resourceComponentTemplatePath = path.join(util.getTemplatesDir(), 'resource-component'); + const packComponentPath = path.join(pathToApp, sourceFolder, scriptsFolder, componentsFolder, pack); + const resourceComponentPath = path.join(packComponentPath, resourceComponent); + fs.ensureDirSync(resourceComponentPath); + // Copy script agnostic files e.g component.json, *.css + fs + .readdirSync(resourceComponentTemplatePath, { withFileTypes: true }) + .filter((dirEntry) => { + // TODO: support nested, script agnotic files + return dirEntry.isFile(); + }) + .forEach((dirEntry) => { + const file = dirEntry.name; + const srcPath = path.join(resourceComponentTemplatePath, file); + const destPath = path.join(resourceComponentPath, file); + if (path.basename(srcPath) == 'component.json') { + // Set pack and create dependencies + const componentJson = fs.readJsonSync(srcPath); + componentJson.name = resourceComponent; + componentJson.pack = pack; + componentJson.dependencies = { + [`${pack}-${component}`]: '1.0.0' + }; + fs.writeJsonSync(destPath, componentJson, { spaces: 2 }); + } else { + fs.copyFileSync(srcPath, destPath); + } + }); + // Copy script files based on scriptsFolder + const scriptFilePath = path.join(resourceComponentTemplatePath, scriptsFolder) + fs + .readdirSync(scriptFilePath) + .forEach((file) => { + const srcPath = path.join(scriptFilePath, file); + const destPath = path.join(resourceComponentPath, file); + fs.copyFileSync(srcPath, destPath); + }); + // No need to add resource component to pack's dependencies list + }); + } + it('should check that resource component is in pack', () => { + const { pathToApp, sourceFolder, componentsFolder } = util.getAppPathData({ appName }); + const packComponentPath = path.join(pathToApp, sourceFolder, scriptsFolder, componentsFolder, pack); + const resourceComponentPath = path.join(packComponentPath, resourceComponent); + assert.ok(fs.existsSync(resourceComponentPath), `${resourceComponent} not found in ${pack}`); + }); + it(`should check that resource component has correct component.json`, () => { + const { pathToApp, sourceFolder, componentsFolder } = util.getAppPathData({ appName }); + const packComponentPath = path.join(pathToApp, sourceFolder, scriptsFolder, componentsFolder, pack); + const resourceComponentPath = path.join(packComponentPath, resourceComponent); + if (fs.existsSync(resourceComponentPath)) { + const componentJson = fs.readJsonSync(path.join(resourceComponentPath, 'component.json')); + assert.strictEqual(componentJson.name, resourceComponent, `${resourceComponent}'s name is not ${resourceComponent} in component.json`); + assert.strictEqual(componentJson.pack, pack, `${resourceComponent}'s pack is not ${pack} in component.json`); + assert.strictEqual(componentJson.type, 'resource', `${resourceComponent}'s type is not resource in component.json}`); + assert.ok(componentJson.dependencies, `${resourceComponent}'s component.json does not have dependencies`); + } + }); +} + function createComponentInPackFailureTest({ appName, pack, component }) { describe('check create component in pack failure', () => { it('should fail with "Invalid pack name:"', async () => { @@ -527,6 +593,14 @@ describe('JET Pack Tests', () => { component: VCOMPONENT_NAME }); }); + describe('create resource component', () => { + util.runComponentTestInAllTestApps({ + test: createResourceComponentInPackTest, + pack: PACK_NAME, + component: COMPONENT_NAME, + resourceComponent: RESOURCE_COMPONENT_NAME + }); + }); describe('ojet add pack', () => { util.runComponentTestInAllTestApps({ test: addPackTest, pack: EXCHANGE_PACK, version: EXCHANGE_PACK_VERSION }); }) diff --git a/test/setup.js b/test/setup.js index a759efa..46a9fcf 100644 --- a/test/setup.js +++ b/test/setup.js @@ -133,7 +133,7 @@ before(async () => { task: 'create', parameters: [util.API_APP_NAME], options: { - template: path.join(__dirname, 'templates', util.API_APP_NAME), + template: path.join(util.getTemplatesDir(), util.API_APP_NAME), } }); assert.ok(true); @@ -154,8 +154,7 @@ before(async () => { parameters: [util.VDOM_APP_NAME], options: { template: 'basic', - vdom: true, - 'use-global-tooling': true + vdom: true } }; await ojet.execute(executeOptions); @@ -166,5 +165,5 @@ before(async () => { } // Always copy - //util.copyOracleJetTooling(util.VDOM_APP_NAME); + util.copyOracleJetTooling(util.VDOM_APP_NAME); }); diff --git a/test/templates/resource-component/component.json b/test/templates/resource-component/component.json new file mode 100644 index 0000000..02c2ef3 --- /dev/null +++ b/test/templates/resource-component/component.json @@ -0,0 +1,5 @@ +{ + "type": "resource", + "version": "1.0.0", + "publicModules": ["resource"] +} \ No newline at end of file diff --git a/test/templates/resource-component/js/logger.js b/test/templates/resource-component/js/logger.js new file mode 100644 index 0000000..12fccac --- /dev/null +++ b/test/templates/resource-component/js/logger.js @@ -0,0 +1,11 @@ +/** + 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/ + +*/ +define(function() { + return { + log: (message) => console.log(message) + } +}); \ No newline at end of file diff --git a/test/templates/resource-component/js/resource.js b/test/templates/resource-component/js/resource.js new file mode 100644 index 0000000..64deb96 --- /dev/null +++ b/test/templates/resource-component/js/resource.js @@ -0,0 +1,11 @@ +/** + 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/ + +*/ +define(['./logger'], (logger) => { + return { + logger + } +}); \ No newline at end of file diff --git a/test/templates/resource-component/resource.css b/test/templates/resource-component/resource.css new file mode 100644 index 0000000..08bcb4c --- /dev/null +++ b/test/templates/resource-component/resource.css @@ -0,0 +1,3 @@ +body { + font: 1em sans-serif; +} \ No newline at end of file diff --git a/test/templates/resource-component/ts/logger.ts b/test/templates/resource-component/ts/logger.ts new file mode 100644 index 0000000..b3c1790 --- /dev/null +++ b/test/templates/resource-component/ts/logger.ts @@ -0,0 +1,3 @@ +export default { + log: (message) => console.log(message) +} \ No newline at end of file diff --git a/test/templates/resource-component/ts/resource.ts b/test/templates/resource-component/ts/resource.ts new file mode 100644 index 0000000..ebd9b20 --- /dev/null +++ b/test/templates/resource-component/ts/resource.ts @@ -0,0 +1,5 @@ +import logger from './logger'; + +export default { + logger +} \ No newline at end of file diff --git a/test/templates/webTsApiTest/package.json b/test/templates/webTsApiTest/package.json index f759be7..398d623 100644 --- a/test/templates/webTsApiTest/package.json +++ b/test/templates/webTsApiTest/package.json @@ -3,10 +3,10 @@ "version": "1.0.0", "description": "An Oracle JavaScript Extension Toolkit(JET) web app", "dependencies": { - "@oracle/oraclejet": "https://artifacthub-phx.oci.oraclecorp.com/ojet-dev-local/oracle-oraclejet-11.0.0.tgz" + "@oracle/oraclejet": "https://artifacthub-phx.oci.oraclecorp.com/ojet-dev-local/oracle-oraclejet-11.1.0.tgz" }, "devDependencies": { - "@oracle/oraclejet-tooling": "https://artifacthub-phx.oci.oraclecorp.com/ojet-dev-local/oracle-oraclejet-tooling-12.0.0.tgz", + "@oracle/oraclejet-tooling": "file:../../../../oraclejet-tooling/dist/oraclejet-tooling", "typescript": "4.0.2" }, "engines": { diff --git a/test/templates/webTsApiTest/src/js/path_mapping.json b/test/templates/webTsApiTest/src/js/path_mapping.json index 45db3fd..0f4c915 100644 --- a/test/templates/webTsApiTest/src/js/path_mapping.json +++ b/test/templates/webTsApiTest/src/js/path_mapping.json @@ -2,11 +2,11 @@ "use": "local", "cdns": { "jet": { - "prefix": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.0.0/lastSuccessfulBuild/artifact/cdn/v11.0.0/default/js", - "css": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.0.0//lastSuccessfulBuild/artifact/cdn/v11.0.0/default/css", + "prefix": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.1.0/lastSuccessfulBuild/artifact/cdn/v11.1.0/default/js", + "css": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.1.0//lastSuccessfulBuild/artifact/cdn/v11.1.0/default/css", "config": "bundles-config.js" }, - "3rdparty": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.0.0/lastSuccessfulBuild/artifact/cdn/v11.0.0/3rdparty" + "3rdparty": "https://ci-cloud.us.oracle.com/jenkins/uitech/job/CDN_v11.1.0/lastSuccessfulBuild/artifact/cdn/v11.1.0/3rdparty" }, "libs": { "knockout": { @@ -338,6 +338,22 @@ "pathSuffix": "/min/ojcss'", "cdnPath": "ojcss" } - } + }, + "ojs/ojcss": { + "cdn": "jet", + "cwd": "node_modules/@oracle/oraclejet/dist/js/libs/oj", + "debug": { + "src": ["debug/ojcss.js"], + "path": "libs/oj/v#{version}", + "pathSuffix": "/debug/ojcss'", + "cdnPath": "ojcss" + }, + "release": { + "src": ["min/ojcss.js"], + "path": "libs/oj/v#{version}", + "pathSuffix": "/min/ojcss'", + "cdnPath": "ojcss" + } + } } } diff --git a/test/templates/webTsApiTest/src/ts/jet-composites/my-component/my-component-viewModel.ts b/test/templates/webTsApiTest/src/ts/jet-composites/my-component/my-component-viewModel.ts index f375dd6..0750ec2 100644 --- a/test/templates/webTsApiTest/src/ts/jet-composites/my-component/my-component-viewModel.ts +++ b/test/templates/webTsApiTest/src/ts/jet-composites/my-component/my-component-viewModel.ts @@ -6,7 +6,7 @@ import Context = require("ojs/ojcontext"); import Composite = require("ojs/ojcomposite"); import "ojs/ojknockout"; import "css!./my-component-styles"; -import "ojcss!my-pack/resources/css/shared"; +import "ojs/ojcss!my-pack/resources/css/shared"; export default class ViewModel implements Composite.ViewModel { busyResolve: (() => void); diff --git a/test/util/index.js b/test/util/index.js index c048ba2..63f8d6a 100644 --- a/test/util/index.js +++ b/test/util/index.js @@ -26,21 +26,22 @@ 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}) { +function runComponentTestInAllTestApps({ test, pack, component, vcomponent, release, bundle, resourceComponent }) { COMPONENT_TEST_APP_CONFIGS.forEach((config) => { - runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle}); + runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle, resourceComponent }); }) } -function runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle}) { +function runComponentTestInTestApp({ config, test, pack, component, vcomponent, release, bundle, resourceComponent }) { describe(config.appName, () => { - test({...config, pack, component, vcomponent, release, bundle}); + test({...config, pack, component, vcomponent, release, bundle, resourceComponent }); }); } const ORACLJET_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']; module.exports = { OJET_COMMAND: 'node ../ojet-cli/bin/ojet', @@ -61,6 +62,7 @@ module.exports = { ORACLJET_CONFIG_JSON, DEFAULT_COMPONENTS_FOLDER, OMIT_COMPONENT_VERSION_FLAG, + WEBPACK_DEPENDENCIES, execCmd: function _execCmd(cmd, options, squelch, logCommand = true) { if (logCommand) { console.log(cmd); @@ -223,6 +225,7 @@ module.exports = { const pathToBuiltComponents = path.join(pathToApp, stagingFolder, javascriptFolder, componentsFolder); const pathToMainJs = path.join(pathToApp, stagingFolder, javascriptFolder, 'main.js'); const pathToBundleJs = path.join(pathToApp, stagingFolder, javascriptFolder, 'bundle.js'); + const pathToIndexHtml = path.join(pathToApp, stagingFolder, 'index.html'); return { componentsFolder, stagingFolder, @@ -232,7 +235,12 @@ module.exports = { pathToApp, pathToBuiltComponents, pathToMainJs, - pathToBundleJs + pathToBundleJs, + pathToIndexHtml } + }, + + getTemplatesDir: function _getTempatesDir() { + return path.resolve(__dirname, '..', 'templates'); } }; diff --git a/test/vdomTest.js b/test/vdomTest.js index 3948481..92771d1 100644 --- a/test/vdomTest.js +++ b/test/vdomTest.js @@ -103,4 +103,71 @@ 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`); + }); + }); + }); });