Skip to content

Commit 4f38f56

Browse files
committed
Release 4.1.0
1 parent f484ce4 commit 4f38f56

9 files changed

+225
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# @oracle/oraclejet-tooling 4.0.0
1+
# @oracle/oraclejet-tooling 4.1.0
22

33
## About the tooling API
44
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.
55

66
This is an open source project maintained by Oracle Corp.
77

88
## Installation
9-
This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://docs.oracle.com/middleware/jet400/jet/).
9+
This module will be automatically installed when you scaffold a web or hybrid mobile app following the [Oracle JET Developers Guide](http://docs.oracle.com/middleware/jet410/jet/).
1010

1111
## [Contributing](https://github.com/oracle/oraclejet-tooling/tree/master/CONTRIBUTING.md)
1212
Oracle JET is an open source project. Pull Requests are currently not being accepted. See

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Release Notes for oraclejet-tooling ##
22

3+
### 4.1.0
4+
* No changes
5+
36
### 4.0.0
47
* Moved module into @oracle scope, changing the name to @oracle/oraclejet-tooling
58

lib/buildCommon.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const npmCopy = require('./npmCopyConfig');
1616
const mainJsInjector = require('./mainJsInjector');
1717
const indexHtmlInjector = require('./indexHtmlInjector');
1818
const CONSTANTS = require('./constants');
19+
const svg = require('./svg');
1920

2021
function _getUglyCode(file, uglifyOptions) {
2122
const code = fs.readFileSync(file, 'utf-8');
@@ -44,7 +45,11 @@ function _copyFileToStaging(fileList) {
4445
for (let i = 0; i < fileList.length; i++) {
4546
const destDir = fileList[i].dest;
4647
const srcDir = fileList[i].src;
47-
fs.copySync(srcDir, destDir, { clobber: true });
48+
if (_isSvgFile(srcDir)) {
49+
fs.copySync(srcDir, destDir, { overwrite: false, errorOnExist: false });
50+
} else {
51+
fs.copySync(srcDir, destDir, { overwrite: true });
52+
}
4853
}
4954
resolve();
5055
} catch (error) {
@@ -53,6 +58,10 @@ function _copyFileToStaging(fileList) {
5358
});
5459
}
5560

61+
function _isSvgFile(fileName) {
62+
return path.extname(fileName) === '.svg';
63+
}
64+
5665
function _getThemeSrcPath(theme) {
5766
return `${config('paths').staging.themes}/${theme.name}/${theme.platform}`;
5867
}
@@ -369,4 +378,15 @@ module.exports = {
369378
resolve(context);
370379
});
371380
},
381+
382+
spriteSvg: function _spriteSvg(context) {
383+
console.log('optimizing svg into SVG sprites.....');
384+
return new Promise((resolve, reject) => {
385+
svg.spriteSvg(context, (err) => {
386+
if (err) reject(err);
387+
});
388+
console.log('svg task finished...');
389+
resolve(context);
390+
});
391+
},
372392
};

lib/buildHybrid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function _runCommonBuildTasks(context) {
115115
buildCommon.clean(context)
116116
.then(buildCommon.copy)
117117
.then(buildCommon.copyLibs)
118+
.then(buildCommon.spriteSvg)
118119
.then(buildCommon.sass)
119120
.then(buildCommon.copyThemes)
120121
.then(buildCommon.injectTheme)

lib/buildWeb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function _runCommonBuildTasks(context) {
2626
buildCommon.clean(context)
2727
.then(buildCommon.copy)
2828
.then(buildCommon.copyLibs)
29+
.then(buildCommon.spriteSvg)
2930
.then(buildCommon.sass)
3031
.then(buildCommon.injectTheme)
3132
.then(buildCommon.copyThemes)

lib/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
DEFAULT_BROWSER: 'chrome',
1616
COMMON_THEME_DIRECTORY: 'common',
1717
JET_COMPOSITE_DIRECTORY: 'jet-composites',
18+
SUPPORTED_THEME_PLATFORMS: ['android', 'ios', 'web', 'windows', 'common'],
1819
SUPPORTED_PLATFORMS: ['android', 'ios', 'web', 'windows'],
1920
SUPPORTED_HYBRID_PLATFORMS: ['android', 'ios', 'windows'],
2021
SUPPORTED_BROWSERS: ['chrome', 'firefox', 'edge', 'ie', 'opera', 'safari'],
@@ -35,5 +36,6 @@ module.exports = {
3536
SUPPORTED_SERVE_WEB_DESTINATIONS: ['server-only'],
3637
DEFAULT_BUILD_DESTINATION: 'emulator',
3738
RESERVED_Key_ALL_THEME: 'all',
38-
ORACLE_JET_CONFIG_JSON: 'oraclejetconfig.json'
39+
ORACLE_JET_CONFIG_JSON: 'oraclejetconfig.json',
40+
PATH_TO_ORACLEJET: 'node_modules/@oracle/oraclejet/dist'
3941
};

lib/defaultconfig.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ module.exports = {
6060
}
6161
}),
6262

63+
svgMin: paths => ({
64+
fileList: [
65+
{
66+
cwd: `${paths.staging.themes}`,
67+
src: ['**/*.svg'],
68+
dest: `${paths.staging.themes}`
69+
}
70+
],
71+
options: {
72+
plugins: [
73+
{ removeXMLNS: false },
74+
{ removeViewBox: false },
75+
{ removeUselessStrokeAndFill: false },
76+
{ convertStyleToAttrs: false },
77+
{ removeEmptyAttrs: true },
78+
{
79+
removeAttrs: {
80+
attrs: ['xmlnsX']
81+
}
82+
}
83+
]
84+
}
85+
}),
86+
87+
svgSprite: {
88+
options: {
89+
shape: {
90+
spacing: { // Add padding
91+
padding: 2, // 0 would sometimes have nearby sprites bleeding in (see "layout")
92+
box: 'content' // I was hoping this would exclude the padding but doesn't, so have to include the padding in the background-position
93+
}
94+
}
95+
}
96+
},
97+
6398
copySrcToStaging: paths => ({
6499
fileList: [
65100
{

lib/svg.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
Copyright (c) 2015, 2017, Oracle and/or its affiliates.
3+
The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
'use strict';
6+
7+
const fs = require('fs-extra');
8+
const util = require('./util');
9+
const path = require('path');
10+
const SVGO = require('svgo');
11+
const glob = require('glob');
12+
const config = require('./config');
13+
const CONSTANTS = require('./constants');
14+
const SVGSpriter = require('svg-sprite');
15+
16+
/**
17+
* Return the promise to optimize user provided svg files, remove redundant content
18+
* @param {Object} Running context that contains all options
19+
* @returns {Promise} return the promise
20+
*/
21+
22+
function _svgMin(context) {
23+
const opts = context.opts.svgMin;
24+
const fileResult = util.getFileList(context.buildType, opts.fileList);
25+
const svgo = new SVGO(opts.options);
26+
return new Promise((resolve, reject) => {
27+
try {
28+
fileResult.forEach((file) => {
29+
const src = fs.readFileSync(file.src);
30+
svgo.optimize(src, (result) => {
31+
if (result.error) reject(result.error);
32+
fs.outputFileSync(path.resolve(file.dest), result.data);
33+
});
34+
});
35+
resolve(context);
36+
} catch (error) {
37+
reject(error);
38+
}
39+
});
40+
}
41+
42+
/**
43+
* Return the promise to combine user provided svg files into a sprite.svg
44+
* and update the _oj.common.sprite.scss
45+
* @param {Object} Running context that contains all options
46+
* @returns {Promise} return the promise
47+
*/
48+
function _svgSprite(context) {
49+
const opts = context.opts.svgSprite;
50+
const padding = opts.options.shape.spacing.padding || 2;
51+
const themePath = path.join(`${config('paths').staging.themes}`, CONSTANTS.DEFAULT_THEME);
52+
return new Promise((resolve, reject) => {
53+
try {
54+
fs.readdirSync(themePath).forEach((dir) => {
55+
if (CONSTANTS.SUPPORTED_THEME_PLATFORMS.indexOf(dir) !== -1) {
56+
opts.options.mode = _svgSpriteMode(_mapToSourceSkinName(dir));
57+
const fileList = glob.sync('**/*.svg', { cwd: path.join(themePath, dir) });
58+
if (opts.options.shape.spacing.padding) opts.options.shape.spacing.padding = padding;
59+
const spriter = new SVGSpriter(opts.options);
60+
fileList.forEach((file) => {
61+
if (path.basename(file) !== 'sprite.svg') {
62+
const fileBase = path.join(themePath, dir);
63+
spriter.add(path.resolve(file), path.basename(file), fs.readFileSync(path.resolve(fileBase, file), { encoding: 'utf-8' }));
64+
}
65+
});
66+
spriter.compile((error, result) => {
67+
Object.keys(result).forEach((mode) => {
68+
Object.keys(result[mode]).forEach((resource) => {
69+
const output = result[mode][resource];
70+
const svgDestSuffix = 'images/sprites/sprite.svg';
71+
let dest = path.join(config('paths').staging.themes, CONSTANTS.DEFAULT_THEME, dir, svgDestSuffix);
72+
dest = path.extname(output.path) === '.svg' ? dest : output.path;
73+
const filePrefix = _mapToSourceSkinName(dir).replace('-', '.');
74+
fs.outputFileSync(dest, output.contents);
75+
const content = fs.readFileSync(dest, 'utf-8').replace(/_(?!.+\.svg)/g, '-');
76+
if (filePrefix !== 'common') {
77+
fs.outputFileSync(dest, content.replace(/common\.sprite/g, `${filePrefix}.sprite`));
78+
} else {
79+
fs.outputFileSync(dest, content.replace(/oj-image-url/g, 'oj-common-image-url'));
80+
}
81+
});
82+
});
83+
});
84+
}
85+
});
86+
resolve(context);
87+
} catch (error) {
88+
reject(error);
89+
}
90+
});
91+
}
92+
93+
/**
94+
* Return the mode configuration for svg spriter
95+
* @param {String} Skin name
96+
* @returns {Object} return the object configuration
97+
*/
98+
function _svgSpriteMode(skin) {
99+
const filePrefix = skin.replace('-', '.');
100+
return {
101+
css: {
102+
render: {
103+
scss: {
104+
template: `${CONSTANTS.PATH_TO_ORACLEJET}/scss/templates/svg-sprite-template.scss.txt`,
105+
dest: `${CONSTANTS.PATH_TO_ORACLEJET}/scss/${skin}/widgets/_oj.${filePrefix}.sprite.scss`
106+
}
107+
},
108+
layout: 'horizontal',
109+
dest: '.',
110+
sprite: 'sprite.svg',
111+
bust: false,
112+
example: false
113+
}
114+
};
115+
}
116+
117+
/**
118+
* Map the tooling theme skin to JET distribution
119+
* @param {String} skin name
120+
* @returns {String} skin name
121+
*/
122+
function _mapToSourceSkinName(skin) {
123+
switch (skin) {
124+
case 'web':
125+
return 'alta';
126+
case 'ios':
127+
return 'alta-ios';
128+
case 'android':
129+
return 'alta-android';
130+
case 'windows':
131+
return 'alta-windows';
132+
case 'common':
133+
return 'common';
134+
default:
135+
return skin;
136+
}
137+
}
138+
139+
module.exports = {
140+
spriteSvg: function _spriteSvg(context) {
141+
return new Promise((resolve, reject) => {
142+
try {
143+
_svgMin(context)
144+
.then(_svgSprite)
145+
.then(() => {
146+
resolve(context);
147+
});
148+
} catch (error) {
149+
reject(error);
150+
}
151+
});
152+
}
153+
};

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oracle/oraclejet-tooling",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"license": "UPL-1.0",
55
"description": "Programmatic API to build and serve Oracle JET web and mobile applications",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"lib"
1414
],
1515
"dependencies": {
16-
"fs-extra": "^1.0.0",
16+
"fs-extra": "^4.0.0",
1717
"glob": "^7.1.1",
1818
"lodash.difference": "^4.5.0",
1919
"lodash.escaperegexp": "^4.1.2",
@@ -30,13 +30,15 @@
3030
"tiny-lr": "^1.0.3",
3131
"serve-static": "^1.11.1",
3232
"serve-index": "^1.8.0",
33-
"opn": "^4.0.2"
33+
"opn": "^4.0.2",
34+
"svgo": "^0.7.0",
35+
"svg-sprite": "^1.3.7"
3436
},
3537
"engines": {
3638
"node": ">=4.0.0"
3739
},
3840
"devDependencies": {
3941
"eslint": "~3.19.0"
4042
},
41-
"jetdocversion": "400"
43+
"jetdocversion": "410"
4244
}

0 commit comments

Comments
 (0)