diff --git a/README.md b/README.md index 0814d7b..37fd3e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @oracle/oraclejet-tooling 10.0.0 +# @oracle/oraclejet-tooling 10.1.0 ## About the tooling API This tooling API contains methods to build and serve Oracle JET web and hybrid mobile apps. It is intended to be used with task running tools such as grunt or gulp. The APIs can also be invoked directly. @@ -6,7 +6,7 @@ This tooling API contains methods to build and serve Oracle JET web and hybrid m This is an open source project maintained by Oracle Corp. ## Installation -This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet1000&id=homepage). +This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://www.oracle.com/pls/topic/lookup?ctx=jet1010&id=homepage). ## [Contributing](https://github.com/oracle/oraclejet-tooling/blob/master/CONTRIBUTING.md) Oracle JET is an open source project. Pull Requests are currently not being accepted. See diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7941fcf..f0e3666 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,6 +1,6 @@ ## Release Notes for oraclejet-tooling ## -### 10.0.0 +### 10.1.0 * No changes ### 5.2.0 diff --git a/lib/buildCommon/compileTypescript.js b/lib/buildCommon/compileTypescript.js index 4b37744..b154ce7 100644 --- a/lib/buildCommon/compileTypescript.js +++ b/lib/buildCommon/compileTypescript.js @@ -316,12 +316,18 @@ function _runTypescriptCompilation(context) { // eslint-disable-next-line no-param-reassign context.opts.typescript.compilationFailed = true; errors.forEach((error) => { - // only log the path starting from the staging folder i.e no need - // for the absolute path that includes the app name since the cwd - // is the app - const indexOfStagingFolder = error.indexOf(`/${context.opts.stagingPath}/`); - const formattedError = error.substring(indexOfStagingFolder + 1); - util.log(`Typescript Error: ${formattedError}`); + let errorMessage; + if (typeof error === 'string') { + // error is a Typescript error string. only log the path starting from the staging folder + // i.e no need for the absolute path that includes the app name since the cwd + // is the app + const indexOfStagingFolder = error.indexOf(`/${context.opts.stagingPath}/`); + errorMessage = error.substring(indexOfStagingFolder + 1); + } else { + // error is a TransformerError object + errorMessage = error.toString(); + } + util.log(`Typescript Error: ${errorMessage}`); }); } resolve(context); diff --git a/lib/publish.js b/lib/publish.js index 5c17255..1b16fa7 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -32,6 +32,9 @@ module.exports = function (scope, parameter, options) { case (CONSTANTS.API_SCOPES.PACK): return pack.publish(parameter, options); default: + if (options && util.hasProperty(options, 'path')) { + return component.publish(parameter, options); + } util.log.error(`Please specify ojet.${CONSTANTS.API_TASKS.PUBLISH}() 'scope' parameter.`); return false; } diff --git a/lib/scopes/component.js b/lib/scopes/component.js index a98bc66..ec2f369 100644 --- a/lib/scopes/component.js +++ b/lib/scopes/component.js @@ -785,17 +785,23 @@ function _getBuiltComponentPath(componentName, opts) { */ component.publish = function (componentName, options) { return new Promise((resolve) => { - util.ensureParameters(componentName, CONSTANTS.API_TASKS.PUBLISH); - // The first level function stores user input for the session process.env.options = JSON.stringify(options); + + // If path provided, skip building and packaging. Publish directly. + if (!componentName && util.getOptionsProperty('path')) { + return _publishArchive(options); + } + + util.ensureParameters(componentName, CONSTANTS.API_TASKS.PUBLISH); + const opts = options || {}; // We allow publishing of only a single component // If multiple, it would be hard distinguish between // single component and a single pack component // User can script a loop if he wants to package multiple component - let componentPath = opts.path || _getBuiltComponentPath(componentName, opts); + let componentPath = _getBuiltComponentPath(componentName, opts); const hadBeenBuiltBefore = !!componentPath; // If pack name was used as the component name @@ -846,10 +852,7 @@ component.publish = function (componentName, options) { return util.loginIfCredentialsProvided(); }) .then(() => { // eslint-disable-line - if (!opts.path) { - return _packArchive(componentName, componentPath, opts); - } - return true; + return _packArchive(componentName, componentPath, opts); }) .then(() => { // eslint-disable-line return exchangeUtils.uploadToExchange(componentName, opts); @@ -865,6 +868,21 @@ component.publish = function (componentName, options) { }); }; +function _publishArchive(options) { + return new Promise((resolve) => { + const archiveName = path.basename(options.path); // Name of the file e.g. demo-card.zip + return util.loginIfCredentialsProvided() + .then(() => exchangeUtils.uploadToExchange(archiveName, options)) + .then(() => { + util.log.success(`Archive '${archiveName}' was published.`); + resolve(); + }) + .catch((error) => { + util.log.error(error, true); + }); + }); +} + /** * ## _packArchive * Archives component folder diff --git a/lib/templates/pack/component.json b/lib/templates/pack/component.json index 5debb97..2e3e3c8 100644 --- a/lib/templates/pack/component.json +++ b/lib/templates/pack/component.json @@ -1,7 +1,7 @@ { "name": "@pack@", "version": "1.0.0", - "jetVersion": "10.0.0", + "jetVersion": "10.1.0", "type": "pack", "displayName": "A user friendly, translatable name of the pack.", "description": "A translatable high-level description for the pack.", diff --git a/lib/util.js b/lib/util.js index 6598167..0e9fbdd 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1178,8 +1178,18 @@ util.request = function (options, body, multipartFormData) { // https://nodejs.org/api/http.html#http_http_request_url_options_callback // https://nodejs.org/api/https.html#https_https_request_options_callback - // Always add security option - opts.secure = util.getOptionsProperty('secure'); + // Add 'secure' property if missing + if (util.hasProperty(opts, 'secure')) { + // Save for next request of this session + process.env.options = JSON.stringify( + // Merge current state with 'secure' option + Object.assing(JSON.parse(process.env.options), { secure: opts.secure }) + ); + } else { + // Create 'secure' property with cach + opts.secure = util.getOptionsProperty('secure'); + } + // Automatically Add Authorization header // Except of the token request if (opts.path !== '/auth/token') { @@ -1215,7 +1225,7 @@ util.request = function (options, body, multipartFormData) { } opts = Object.assign(defaults, opts); } - const protocol = _validateProtocol(opts.protocol, opts.secure); + const protocol = _validateProtocol(opts); if (util.isVerbose()) { const optionsCopy = util.cloneObject(opts); @@ -1332,21 +1342,10 @@ util.getOptionsProperty = (property) => { * @returns {Object} | @throws - returns valid protocol or throws error */ -function _validateProtocol(requestedProtocol, secure) { // eslint-disable-line - // Cache secure options for the current session - const env = process.env; - let secureCopy; - // Check cache - if (env.secure) { - secureCopy = env.secure === 'true'; // Convert to boolean - } else { - secureCopy = typeof secure === 'undefined' ? true : secure; - // Cache - env.secure = secure; // Convert to string - } - - if (requestedProtocol === 'https:' || !secureCopy) { - return requestedProtocol === 'https:' ? https : http; +function _validateProtocol(options) { // eslint-disable-line + const protocol = options.protocol; + if (protocol === 'https:' || options.secure === false) { + return protocol === 'https:' ? https : http; } util.log.error('HTTP protocol is insecure. Please use HTTPS instead. At your own risk, you can force the HTTP protocol with the —secure=false or {secure: false} option.'); } diff --git a/package.json b/package.json index f7225a2..cab0753 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oracle/oraclejet-tooling", - "version": "10.0.0", + "version": "10.1.0", "license": "UPL-1.0", "description": "Programmatic API to build and serve Oracle JET web and mobile applications", "keywords": [