Skip to content

Commit

Permalink
release 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosOrozco88 committed Oct 22, 2021
1 parent a49f98c commit 8f33086
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 93 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.2 (22/10/2021)
- New configuration property `ui5-tools.server.babelSourcesLive`. Live transpile js.
- AppcacheBuster is changed default value: `None`.

## 1.1.1 (19/10/2021)
- Babelify bug solved
- Dependencies upgrade
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ You can find examples of vscode workspace configuration in [workspaceExample](wo
- `ui5-tools.server.protocol`: Should use http or https | default: `http`
- `ui5-tools.server.odataProxy`: Proxy all odata calls to a server | default: `None`
- `ui5-tools.server.odataUri`: Your odata server uri url (example: `http://srvaspgwd.com:8080/`). odataProxy `Other` accepts multiple uris (example: `http://srvaspgwd.com:8080/, http://srvaspgwd.com:8080/`)
- `ui5-tools.server.odataQuery`: Query for the gateway server (example: sap-client=100) | default: ` `
- `ui5-tools.server.odataSecure`: Verify odataProxy SSL Certs | default: `false`
- `ui5-tools.server.odataMountPath`: The mountpath for 'Other' odataProxy. Accepts multiple paths, respecting the same order that odataUri for odataProxy type `Other` | default: `/odata`
- `ui5-tools.server.resourcesProxy`: Proxy all odata calls to a gateway, cdn or local folder (proxy all url begining with /resources) | default: `CDN SAPUI5`
- `ui5-tools.server.resourcesUri`: Your resources server url (example: http://srvaspgwd.com:8080/)
- `ui5-tools.server.resourcesSecure`: Verify resourcesProxy SSL Certs | default: `false`
- `ui5-tools.server.cacheBuster`: Activate cacheBuster in server mode: | Default: `PROD`
- `ui5-tools.server.babelSourcesLive`: Live transform es6 to es5 (server in DEV mode), internet explorer 11 compat: `false`
- `ui5-tools.server.cacheBuster`: Activate cacheBuster in server mode: | Default: `None`

#### Builder Settings

Expand Down
46 changes: 44 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ui5-tools",
"displayName": "UI5 Tools",
"description": "Local development tools for UI5",
"version": "1.1.1",
"version": "1.1.2",
"publisher": "carlosorozcojimenez",
"author": "Carlos Orozco Jiménez <carlos.orozco.jimenez@gmail.com>",
"contributors": [
Expand Down Expand Up @@ -193,7 +193,7 @@
}
],
"configuration": {
"title": "ui5-Tools",
"title": "UI5 Tools",
"properties": {
"ui5-tools.srcFolder": {
"type": "string",
Expand Down Expand Up @@ -322,6 +322,16 @@
"default": "",
"description": "Your resources server url (example: http://srvaspgwd.com:8080/)"
},
"ui5-tools.server.resourcesSecure": {
"type": "boolean",
"default": false,
"description": "Verify resourcesProxy SSL Certs"
},
"ui5-tools.server.babelSourcesLive": {
"type": "boolean",
"default": false,
"description": "Live transform es6 to es5 (server in DEV mode), internet explorer 11 compat"
},
"ui5-tools.server.cacheBuster": {
"type": "string",
"enum": [
Expand All @@ -336,14 +346,9 @@
"Activate cacheBuster allways",
"CacheBuster disabled"
],
"default": "PROD",
"default": "None",
"description": "Activate cacheBuster in server mode:"
},
"ui5-tools.server.resourcesSecure": {
"type": "boolean",
"default": false,
"description": "Verify resourcesProxy SSL Certs"
},
"ui5-tools.builder.babelSources": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -477,6 +482,7 @@
"@types/babel__core": "^7.1.16",
"@types/babel__preset-env": "^7.9.2",
"@types/connect-livereload": "^0.5.32",
"@types/cookie-parser": "^1.4.2",
"@types/ejs": "^3.1.0",
"@types/express": "^4.17.13",
"@types/glob": "^7.1.4",
Expand Down Expand Up @@ -515,6 +521,7 @@
"babel-plugin-transform-remove-console": "^6.9.4",
"chokidar": "^3.5.2",
"connect-livereload": "^0.6.1",
"cookie-parser": "^1.4.5",
"core-js": "^3.18.3",
"deepmerge": "^4.2.2",
"dotenv": "^10.0.0",
Expand All @@ -527,6 +534,7 @@
"less-openui5": "^0.11.2",
"livereload": "^0.9.3",
"marked": "^3.0.7",
"minimatch": "^3.0.4",
"on-headers": "^1.0.2",
"open": "^8.3.0",
"openui5-preload": "4.0.0",
Expand Down
66 changes: 38 additions & 28 deletions src/Builder/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,34 +488,9 @@ export default {
//require('core-js');

for (let i = 0; i < jsFiles.length; i++) {
const uriOrigJs = Uri.file(jsFiles[i].fsPath);
const jsFileRaw = await workspace.fs.readFile(uriOrigJs);
const jsFileString = jsFileRaw.toString();

const babelified: BabelFileResult | null = await transformAsync(jsFileString, {
plugins: [
[
transformAsyncToPromises,
{
inlineHelpers: true,
},
],
[transformRemoveConsole],
],
presets: [
[
presetEnv,
{
targets: {
browsers: 'last 2 versions, ie 11',
},
},
],
],
});
if (babelified && babelified.code && babelified.code !== jsFileString) {
const babelifiedCode = babelified.code.replace(/\r\n|\r|\n/g, os.EOL);

const babelifiedCode: string = await this.babelifyFile(ui5App, jsFiles[i]);
if (babelifiedCode) {
const uriOrigJs = jsFiles[i];
await workspace.fs.writeFile(uriOrigJs, Buffer.from(babelifiedCode));
}
}
Expand All @@ -525,6 +500,41 @@ export default {
}
},

async babelifyFile(ui5App: Ui5App, fsUri: Uri): Promise<string> {
let babelifiedCode = '';

const jsFileRaw = await workspace.fs.readFile(fsUri);
const jsFileString = jsFileRaw.toString();
const filename = fsUri.fsPath.replace(ui5App.srcFsPath, '').replace(ui5App.distFsPath, '');
const babelified: BabelFileResult | null = await transformAsync(jsFileString, {
filename: filename,
plugins: [
[
transformAsyncToPromises,
{
inlineHelpers: true,
},
],
[transformRemoveConsole],
],
presets: [
[
presetEnv,
{
targets: {
browsers: 'last 2 versions, ie 11',
},
},
],
],
});
if (babelified && babelified.code && babelified.code !== jsFileString) {
babelifiedCode = babelified.code.replace(/\r\n|\r|\n/g, os.EOL);
}

return babelifiedCode;
},

/**
* Create -dbg.js files
*/
Expand Down
43 changes: 39 additions & 4 deletions src/Server/Apps.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import express from 'express';
import Utils from '../Utils/Utils';
import { workspace, RelativePattern, FileStat } from 'vscode';
import { workspace, RelativePattern, FileStat, Uri } from 'vscode';
import minimatch from 'minimatch';
import { ServerOptions } from '../Types/Types';
import Builder from '../Builder/Builder';
import Log from '../Utils/Log';
import path from 'path';
import { LogLevel } from 'ts-loader/dist/logger';

export default {
/**
* Starts server in development mode (serving srcFolder)
* @param {object} object params
*/
async serve({ serverApp, ui5Apps = [], bServeProduction = false, bCacheBuster }: ServerOptions): Promise<void> {
async serve({
serverApp,
ui5Apps = [],
bServeProduction = false,
bCacheBuster,
bBabelSourcesLive,
sBabelSourcesExclude,
}: ServerOptions): Promise<void> {
// Static serve all apps
ui5Apps.forEach((ui5App) => {
const staticPath = bServeProduction ? ui5App.distFsPath : ui5App.srcFsPath;

const aBabelExclude = sBabelSourcesExclude ? sBabelSourcesExclude.split(',') : [];
serverApp.use(
ui5App.appServerPath,
(req, res, next) => {
async (req, res, next) => {
const sInnerPath = req.url;
if (bCacheBuster) {
const sInnerPath = req.url;
if (sInnerPath.indexOf('/resources') < 0 && sInnerPath.indexOf('/sap/public/') < 0) {
// Not loading ui5 resources or public resources from gateway like themes
const oRegex = new RegExp('(/~).*(~)', 'g');
Expand All @@ -29,6 +42,28 @@ export default {
}
}
}
if (bBabelSourcesLive) {
if (sInnerPath.endsWith('.js') && !sInnerPath.includes('resources/')) {
try {
let bTranspile = true;
for (let i = 0; i < aBabelExclude.length && bTranspile; i++) {
const sExclude = aBabelExclude[i];
bTranspile = !minimatch(sInnerPath, sExclude);
}
if (bTranspile) {
const fsPath = Uri.parse(path.join(staticPath + req.path));
const babelifiedCode = await Builder.babelifyFile(ui5App, fsPath);
res.type('.js');
// Log.server(`LiveTranspile: ${req.path} transpiled successfully`, LogLevel.INFO);
res.end(babelifiedCode);
} else {
// Log.server(`LiveTranspile: ${req.path} skipped babelify`, LogLevel.INFO);
}
} catch (error: any) {
// Log.server(`LiveTranspile: ${error.message}`, LogLevel.WARN);
}
}
}

next();
},
Expand Down
Loading

0 comments on commit 8f33086

Please sign in to comment.