@ui5/webcomponents-tools 0.0.0-f9b9eadb8 → 0.0.0-fd6264051
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -0
- package/README.md +1 -1
- package/assets-meta.js +15 -1
- package/components-package/nps.js +51 -27
- package/components-package/postcss.themes.js +5 -2
- package/components-package/rollup-plugins/empty-module.js +15 -0
- package/components-package/rollup.js +134 -40
- package/components-package/wdio.js +53 -28
- package/components-package/wdio.sync.js +360 -0
- package/icons-collection/nps.js +53 -9
- package/lib/copy-and-watch/index.js +6 -4
- package/lib/copy-list/index.js +28 -0
- package/lib/create-icons/index.js +32 -14
- package/lib/create-illustrations/index.js +150 -0
- package/lib/create-new-component/index.js +12 -4
- package/lib/documentation/index.js +42 -20
- package/lib/documentation/templates/api-properties-section.js +3 -1
- package/lib/documentation/templates/template.js +2 -1
- package/lib/esm-abs-to-rel/index.js +54 -0
- package/lib/generate-json-imports/i18n.js +56 -18
- package/lib/generate-json-imports/themes.js +44 -13
- package/lib/hash/config.js +10 -0
- package/lib/hash/generate.js +19 -0
- package/lib/hash/upToDate.js +31 -0
- package/lib/hbs2lit/src/litVisitor2.js +31 -6
- package/lib/hbs2lit/src/svgProcessor.js +3 -3
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +4 -11
- package/lib/i18n/toJSON.js +1 -1
- package/lib/jsdoc/config.json +1 -1
- package/lib/jsdoc/plugin.js +30 -1
- package/lib/jsdoc/template/publish.js +22 -2
- package/lib/polyfill-placeholder/index.js +5 -0
- package/lib/postcss-css-to-esm/index.js +19 -16
- package/lib/postcss-css-to-json/index.js +20 -11
- package/lib/postcss-new-files/index.js +36 -0
- package/lib/replace-global-core/index.js +20 -0
- package/lib/scoping/lint-src.js +1 -1
- package/lib/scoping/missing-dependencies.js +65 -0
- package/lib/scoping/report-tags-usage.js +28 -0
- package/lib/serve/index.js +46 -0
- package/{components-package → lib/serve}/serve.json +0 -0
- package/package.json +51 -52
- package/bin/init-ui5-package.js +0 -3
- package/lib/init-package/index.js +0 -123
- package/lib/init-package/resources/.eslintignore +0 -3
- package/lib/init-package/resources/bundle.es5.js +0 -25
- package/lib/init-package/resources/bundle.esm.js +0 -34
- package/lib/init-package/resources/config/.eslintrc.js +0 -1
- package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
- package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
- package/lib/init-package/resources/config/rollup.config.js +0 -1
- package/lib/init-package/resources/config/wdio.conf.js +0 -1
- package/lib/init-package/resources/package-scripts.js +0 -11
- package/lib/init-package/resources/src/Assets.js +0 -5
- package/lib/init-package/resources/src/MyFirstComponent.hbs +0 -1
- package/lib/init-package/resources/src/MyFirstComponent.js +0 -56
- package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
- package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
- package/lib/init-package/resources/src/themes/MyFirstComponent.css +0 -11
- package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -3
- package/lib/init-package/resources/test/pages/index.html +0 -56
- package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
@@ -0,0 +1,31 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const path = require("path");
|
3
|
+
const process = require("process");
|
4
|
+
const { hashElement } = require("folder-hash");
|
5
|
+
const config = require("./config.js");
|
6
|
+
|
7
|
+
const inputDir = path.normalize(process.argv[2]);
|
8
|
+
const hashFileName = path.normalize(process.argv[3]);
|
9
|
+
|
10
|
+
const isUpToDate = async (inputDir, hashFileName) => {
|
11
|
+
// No dist/ directory or no hash file
|
12
|
+
if (!fs.existsSync(inputDir) || !fs.existsSync(hashFileName)) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Empty hash file
|
17
|
+
const existingHash = `${fs.readFileSync(hashFileName)}`;
|
18
|
+
if (!existingHash) {
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Calculate the hash of the dist/ directory
|
23
|
+
const result = await hashElement(inputDir, config);
|
24
|
+
const newHash = result.hash;
|
25
|
+
|
26
|
+
return newHash === existingHash;
|
27
|
+
};
|
28
|
+
|
29
|
+
isUpToDate(inputDir, hashFileName).then(upToDate => {
|
30
|
+
process.exit(upToDate ? 0 : 1); // 0 means success (it is up to date), 1 means failure (must rebuild the dist/)
|
31
|
+
});
|
@@ -8,9 +8,26 @@ let skipIfDefined = false;
|
|
8
8
|
// when true => an HTML node value, when false => an attribute value
|
9
9
|
let isNodeValue = false;
|
10
10
|
|
11
|
+
// when true => the current attribute is "style"
|
12
|
+
let isStyleAttribute = false;
|
13
|
+
|
11
14
|
// matches event handlers @click= and boolean attrs ?disabled=
|
12
15
|
const dynamicAttributeRgx = /\s(\?|@)([a-zA-Z|-]+)="?\s*$/;
|
13
16
|
|
17
|
+
if (!String.prototype.replaceAll) {
|
18
|
+
String.prototype.replaceAll = function(str, newStr){
|
19
|
+
|
20
|
+
// If a regex pattern
|
21
|
+
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
|
22
|
+
return this.replace(str, newStr);
|
23
|
+
}
|
24
|
+
|
25
|
+
// If a string
|
26
|
+
return this.replace(new RegExp(str, 'g'), newStr);
|
27
|
+
|
28
|
+
};
|
29
|
+
}
|
30
|
+
|
14
31
|
function HTMLLitVisitor(debug) {
|
15
32
|
this.blockCounter = 0;
|
16
33
|
this.keys = [];
|
@@ -18,7 +35,7 @@ function HTMLLitVisitor(debug) {
|
|
18
35
|
this.result = "";
|
19
36
|
this.mainBlock = "";
|
20
37
|
this.blockPath = "context";
|
21
|
-
this.blockParameters = ["context"];
|
38
|
+
this.blockParameters = ["context", "tags", "suffix"];
|
22
39
|
this.paths = []; //contains all normalized relative paths
|
23
40
|
this.debug = debug;
|
24
41
|
if (this.debug) {
|
@@ -34,7 +51,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
34
51
|
this.keys.push(key);
|
35
52
|
this.debug && this.blockByNumber.push(key);
|
36
53
|
|
37
|
-
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") =>
|
54
|
+
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") => ";
|
38
55
|
|
39
56
|
if (this.keys.length > 1) { //it's a nested block
|
40
57
|
this.blocks[this.prevKey()] += this.currentKey() + "(" + this.blockParameters.join(", ") + ")";
|
@@ -45,7 +62,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
45
62
|
|
46
63
|
this.blocks[this.currentKey()] += "html`";
|
47
64
|
Visitor.prototype.Program.call(this, program);
|
48
|
-
this.blocks[this.currentKey()] += "`;
|
65
|
+
this.blocks[this.currentKey()] += "`;";
|
49
66
|
|
50
67
|
this.keys.pop(key);
|
51
68
|
};
|
@@ -54,7 +71,7 @@ HTMLLitVisitor.prototype.ContentStatement = function(content) {
|
|
54
71
|
Visitor.prototype.ContentStatement.call(this, content);
|
55
72
|
// let content = content.orgiinal; // attribute="__ attribute = "__ attribute ="__
|
56
73
|
|
57
|
-
|
74
|
+
let contentStatement = content.original;
|
58
75
|
skipIfDefined = !!dynamicAttributeRgx.exec(contentStatement);
|
59
76
|
|
60
77
|
const closingIndex = contentStatement.lastIndexOf(">");
|
@@ -63,6 +80,15 @@ HTMLLitVisitor.prototype.ContentStatement = function(content) {
|
|
63
80
|
isNodeValue = closingIndex > openingIndex;
|
64
81
|
}
|
65
82
|
|
83
|
+
isStyleAttribute = !isNodeValue && contentStatement.match(/style *= *["']? *$/);
|
84
|
+
|
85
|
+
if (!isStyleAttribute && contentStatement.match(/style=/)) {
|
86
|
+
console.log("WARNING: style hard-coded", contentStatement);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Scope custom element tags
|
90
|
+
contentStatement = contentStatement.replaceAll(/(<\/?\s*)([a-zA-Z0-9_]+-[a-zA-Z0-9_-]+)/g, "$1\${scopeTag(\"$2\", tags, suffix)}");
|
91
|
+
|
66
92
|
this.blocks[this.currentKey()] += contentStatement;
|
67
93
|
};
|
68
94
|
|
@@ -74,7 +100,6 @@ HTMLLitVisitor.prototype.MustacheStatement = function(mustache) {
|
|
74
100
|
} else {
|
75
101
|
const path = normalizePath.call(this, mustache.path.original);
|
76
102
|
const hasCalculatingClasses = path.includes("context.classes");
|
77
|
-
const hasStylesCalculation = path.includes("context.styles");
|
78
103
|
|
79
104
|
let parsedCode = "";
|
80
105
|
|
@@ -82,7 +107,7 @@ HTMLLitVisitor.prototype.MustacheStatement = function(mustache) {
|
|
82
107
|
parsedCode = `\${unsafeHTML(${path})}`;
|
83
108
|
} else if (hasCalculatingClasses) {
|
84
109
|
parsedCode = `\${classMap(${path})}`;
|
85
|
-
} else if (
|
110
|
+
} else if (isStyleAttribute) {
|
86
111
|
parsedCode = `\${styleMap(${path})}`;
|
87
112
|
} else if (skipIfDefined){
|
88
113
|
parsedCode = `\${${path}}`;
|
@@ -46,8 +46,8 @@ function getSVGMatches(template) {
|
|
46
46
|
|
47
47
|
function getSVGBlock(input, blockCounter) {
|
48
48
|
return {
|
49
|
-
usage: `\${blockSVG${blockCounter}(context)}`,
|
50
|
-
definition: `\nconst blockSVG${blockCounter} = (context) =>
|
49
|
+
usage: `\${blockSVG${blockCounter}(context, tags, suffix)}`,
|
50
|
+
definition: `\nconst blockSVG${blockCounter} = (context, tags, suffix) => svg\`${input}\`;`,
|
51
51
|
};
|
52
52
|
}
|
53
53
|
|
@@ -55,7 +55,7 @@ function replaceInternalBlocks(template, svgContent) {
|
|
55
55
|
const internalBlocks = svgContent.match(blockrx) || [];
|
56
56
|
|
57
57
|
internalBlocks.forEach(blockName => {
|
58
|
-
const rx = new RegExp(`const ${blockName}.*(html\`)
|
58
|
+
const rx = new RegExp(`const ${blockName}.*(html\`).*;`);
|
59
59
|
template = template.replace(rx, (match, p1) => {
|
60
60
|
return match.replace(p1, "svg\`");
|
61
61
|
});
|
@@ -1,17 +1,10 @@
|
|
1
1
|
const buildRenderer = (controlName, litTemplate) => {
|
2
|
-
return
|
3
|
-
|
4
|
-
|
5
|
-
import { html, svg, repeat, classMap, styleMap, unsafeHTML, setTags, setSuffix } from '@ui5/webcomponents-base/dist/renderer/LitRenderer.js';
|
2
|
+
return `/* eslint no-unused-vars: 0 */
|
3
|
+
import { html, svg, repeat, classMap, styleMap, ifDefined, unsafeHTML, scopeTag } from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
|
4
|
+
|
6
5
|
${litTemplate}
|
7
6
|
|
8
|
-
|
9
|
-
setTags(tags);
|
10
|
-
setSuffix(suffix);
|
11
|
-
return block0(context);
|
12
|
-
};
|
13
|
-
|
14
|
-
export default main;`
|
7
|
+
export default block0;`;
|
15
8
|
};
|
16
9
|
|
17
10
|
module.exports = {
|
package/lib/i18n/toJSON.js
CHANGED
@@ -30,7 +30,7 @@ const messagesJSONDist = path.normalize(`${process.argv[3]}`);
|
|
30
30
|
const outputFile = path.normalize(`${messagesJSONDist}/${filename}.json`);
|
31
31
|
|
32
32
|
fs.writeFileSync(outputFile, JSON.stringify(properties));
|
33
|
-
console.log(`[i18n]: "${filename}.json" has been generated!`);
|
33
|
+
// console.log(`[i18n]: "${filename}.json" has been generated!`);
|
34
34
|
};
|
35
35
|
|
36
36
|
mkdirp.sync(messagesJSONDist);
|
package/lib/jsdoc/config.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"source": {
|
3
3
|
"include": "src",
|
4
|
-
"excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js"
|
4
|
+
"excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js|thirdparty"
|
5
5
|
},
|
6
6
|
"opts" : {
|
7
7
|
"recurse": true,
|
package/lib/jsdoc/plugin.js
CHANGED
@@ -31,6 +31,12 @@
|
|
31
31
|
*
|
32
32
|
* tagname
|
33
33
|
*
|
34
|
+
* native
|
35
|
+
*
|
36
|
+
* noattribute
|
37
|
+
*
|
38
|
+
* allowPreventDefault
|
39
|
+
*
|
34
40
|
* It furthermore listens to the following JSDoc3 events to implement additional functionality
|
35
41
|
*
|
36
42
|
* parseBegin
|
@@ -2060,9 +2066,11 @@ exports.defineTags = function(dictionary) {
|
|
2060
2066
|
});
|
2061
2067
|
|
2062
2068
|
dictionary.defineTag('slot', {
|
2063
|
-
mustNotHaveValue: true,
|
2064
2069
|
onTagged: function(doclet, tag) {
|
2065
2070
|
doclet.slot = true;
|
2071
|
+
if (tag.value) {
|
2072
|
+
doclet.propertyName = tag.value;
|
2073
|
+
}
|
2066
2074
|
}
|
2067
2075
|
});
|
2068
2076
|
|
@@ -2079,6 +2087,27 @@ exports.defineTags = function(dictionary) {
|
|
2079
2087
|
doclet.tagname = tag.value;
|
2080
2088
|
}
|
2081
2089
|
});
|
2090
|
+
|
2091
|
+
dictionary.defineTag('allowPreventDefault', {
|
2092
|
+
mustHaveValue: false,
|
2093
|
+
onTagged: function(doclet, tag) {
|
2094
|
+
doclet.allowPreventDefault = true;
|
2095
|
+
}
|
2096
|
+
});
|
2097
|
+
|
2098
|
+
dictionary.defineTag('native', {
|
2099
|
+
mustHaveValue: false,
|
2100
|
+
onTagged: function(doclet, tag) {
|
2101
|
+
doclet.native = true;
|
2102
|
+
}
|
2103
|
+
});
|
2104
|
+
|
2105
|
+
dictionary.defineTag('noattribute', {
|
2106
|
+
mustHaveValue: false,
|
2107
|
+
onTagged: function(doclet, tag) {
|
2108
|
+
doclet.noattribute = true;
|
2109
|
+
}
|
2110
|
+
});
|
2082
2111
|
};
|
2083
2112
|
|
2084
2113
|
exports.handlers = {
|
@@ -2804,6 +2804,10 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2804
2804
|
attrib("export", undefined, '', true);
|
2805
2805
|
}
|
2806
2806
|
|
2807
|
+
if (member.noattribute) {
|
2808
|
+
attrib("noattribute", true);
|
2809
|
+
}
|
2810
|
+
|
2807
2811
|
if (member.readonly) {
|
2808
2812
|
attrib("readonly", member.readonly, null);
|
2809
2813
|
}
|
@@ -2815,7 +2819,14 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2815
2819
|
if ( member.since ) {
|
2816
2820
|
attrib("since", extractVersion(member.since));
|
2817
2821
|
}
|
2818
|
-
|
2822
|
+
|
2823
|
+
var type = listTypes(member.type);
|
2824
|
+
attrib("type", type);
|
2825
|
+
|
2826
|
+
if ((type === "object" || type === "Object") && visibility(member) === "public") {
|
2827
|
+
attrib("noattribute", true);
|
2828
|
+
}
|
2829
|
+
|
2819
2830
|
tag("description", normalizeWS(member.description), true);
|
2820
2831
|
if (member.defaultvalue) {
|
2821
2832
|
attrib("defaultValue", member.defaultvalue);
|
@@ -2838,6 +2849,9 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2838
2849
|
if (member.slot) {
|
2839
2850
|
tag("property");
|
2840
2851
|
attrib("name", member.name);
|
2852
|
+
if (member.propertyName) {
|
2853
|
+
attrib("propertyName", member.propertyName);
|
2854
|
+
}
|
2841
2855
|
if (member.__ui5.module && member.__ui5.module !== symbol.__ui5.module) {
|
2842
2856
|
attrib("module", member.__ui5.module);
|
2843
2857
|
attrib("export", undefined, '', true);
|
@@ -2879,6 +2893,12 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2879
2893
|
attrib("module", member.__ui5.module);
|
2880
2894
|
attrib("export", undefined, '', true);
|
2881
2895
|
}
|
2896
|
+
if (member.allowPreventDefault) {
|
2897
|
+
attrib("allowPreventDefault", true);
|
2898
|
+
}
|
2899
|
+
if (member.native) {
|
2900
|
+
attrib("native", true);
|
2901
|
+
}
|
2882
2902
|
attrib("visibility", visibility(member), 'public');
|
2883
2903
|
if ( member.scope === 'static' ) {
|
2884
2904
|
attrib("static", true, false, /* raw = */true);
|
@@ -3845,7 +3865,7 @@ function createAPIJS(symbols, filename) {
|
|
3845
3865
|
|
3846
3866
|
var output = [];
|
3847
3867
|
|
3848
|
-
var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;
|
3868
|
+
var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|noattribute|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;
|
3849
3869
|
|
3850
3870
|
function isNoKeyword($) { return !rkeywords.test($.name); }
|
3851
3871
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
const postcss = require('postcss');
|
2
1
|
const fs = require('fs');
|
3
2
|
const path = require('path');
|
4
3
|
const mkdirp = require('mkdirp');
|
@@ -7,13 +6,13 @@ const assets = require("../../assets-meta.js");
|
|
7
6
|
const DEFAULT_THEME = assets.themes.default;
|
8
7
|
|
9
8
|
const getDefaultThemeCode = packageName => {
|
10
|
-
return `import {
|
9
|
+
return `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
11
10
|
|
12
|
-
import defaultThemeBase from "@ui5/webcomponents-
|
11
|
+
import defaultThemeBase from "@ui5/webcomponents-theming/dist/generated/themes/${DEFAULT_THEME}/parameters-bundle.css.js";
|
13
12
|
import defaultTheme from "./${DEFAULT_THEME}/parameters-bundle.css.js";
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", () => defaultThemeBase);
|
15
|
+
registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", () => defaultTheme);
|
17
16
|
`;
|
18
17
|
};
|
19
18
|
|
@@ -25,18 +24,22 @@ const proccessCSS = css => {
|
|
25
24
|
return JSON.stringify(css);
|
26
25
|
}
|
27
26
|
|
28
|
-
module.exports =
|
27
|
+
module.exports = function (opts) {
|
29
28
|
opts = opts || {};
|
30
29
|
|
31
|
-
return
|
32
|
-
|
33
|
-
|
30
|
+
return {
|
31
|
+
postcssPlugin: 'postcss-css-to-esm',
|
32
|
+
Once (root) {
|
33
|
+
let css = root.toString();
|
34
|
+
css = proccessCSS(css);
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
const targetFile = root.source.input.from.replace(`/${opts.toReplace}/`, "/dist/generated/").replace(`\\${opts.toReplace}\\`, "\\dist\\generated\\");
|
37
|
+
mkdirp.sync(path.dirname(targetFile));
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
39
|
+
const filePath = `${targetFile}.js`;
|
40
|
+
const defaultTheme = opts.includeDefaultTheme ? getDefaultThemeCode(opts.packageName) : ``;
|
41
|
+
fs.writeFileSync(filePath, `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
};
|
45
|
+
module.exports.postcss = true;
|
@@ -1,4 +1,3 @@
|
|
1
|
-
const postcss = require('postcss');
|
2
1
|
const fs = require('fs');
|
3
2
|
const path = require('path');
|
4
3
|
const mkdirp = require('mkdirp');
|
@@ -11,17 +10,27 @@ const proccessCSS = css => {
|
|
11
10
|
return css;
|
12
11
|
}
|
13
12
|
|
14
|
-
module.exports =
|
13
|
+
module.exports = function (opts) {
|
15
14
|
opts = opts || {};
|
16
15
|
|
17
|
-
return
|
18
|
-
|
19
|
-
|
16
|
+
return {
|
17
|
+
postcssPlugin: 'postcss-css-to-json',
|
18
|
+
Once (root) {
|
19
|
+
let css = root.toString();
|
20
|
+
css = proccessCSS(css);
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
const targetFile = root.source.input.from.replace(`/${opts.toReplace}/`, "/dist/generated/assets/").replace(`\\${opts.toReplace}\\`, "\\dist\\generated\\assets\\");
|
23
|
+
mkdirp.sync(path.dirname(targetFile));
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
const filePath = `${targetFile}.json`;
|
26
|
+
const data = {
|
27
|
+
packageName: opts.packageName,
|
28
|
+
fileName: targetFile.substr(targetFile.lastIndexOf("themes")),
|
29
|
+
content: css
|
30
|
+
};
|
31
|
+
fs.writeFileSync(filePath, JSON.stringify({_: data}));
|
32
|
+
}
|
33
|
+
};
|
34
|
+
};
|
35
|
+
|
36
|
+
module.exports.postcss = true;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
const chokidar = require("chokidar");
|
2
|
+
const commandLineArgs = require("command-line-args");
|
3
|
+
const { exec } = require("child_process");
|
4
|
+
|
5
|
+
const options = commandLineArgs([
|
6
|
+
{ name: "srcFiles", type: String },
|
7
|
+
]);
|
8
|
+
|
9
|
+
const runPostcss = path => {
|
10
|
+
let command = `postcss ${path} --config config/postcss.components --base src --dir dist/css/`;
|
11
|
+
console.log(`Executing: ${command}`);
|
12
|
+
exec(command, (err, stdout, stderr) => {
|
13
|
+
if (err) {
|
14
|
+
console.log(`Could not run postcss for ${path}. Error: ${err}`);
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
command = `${command} -w`;
|
19
|
+
console.log(`Executing: ${command}`);
|
20
|
+
exec(command, (err, stdout, stderr) => {
|
21
|
+
if (err) {
|
22
|
+
console.log(`Could not run postcss in watch mode for ${path}. Error: ${err}`);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
};
|
26
|
+
|
27
|
+
let ready = false; // Do nothing until the ready event has been fired (we don't want to recompile all files initially)
|
28
|
+
const watcher = chokidar.watch(options.srcFiles);
|
29
|
+
watcher.on("ready", () => {
|
30
|
+
ready = true; // Initial scan is over -> waiting for new files
|
31
|
+
});
|
32
|
+
watcher.on("add", path => {
|
33
|
+
if (ready) {
|
34
|
+
runPostcss(path);
|
35
|
+
}
|
36
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const glob = require("glob");
|
3
|
+
|
4
|
+
const basePath = process.argv[2];
|
5
|
+
|
6
|
+
const replaceGlobalCoreUsage = (srcPath) => {
|
7
|
+
|
8
|
+
const original = fs.readFileSync(srcPath).toString();
|
9
|
+
let replaced = original.replace(/sap\.ui\.getCore\(\)/g, `Core`);
|
10
|
+
|
11
|
+
if (original !== replaced) {
|
12
|
+
replaced = `import Core from 'sap/ui/core/Core';
|
13
|
+
${replaced}`;
|
14
|
+
fs.writeFileSync(srcPath, replaced);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
18
|
+
const fileNames = glob.sync(basePath + "**/*.js");
|
19
|
+
fileNames.forEach(replaceGlobalCoreUsage);
|
20
|
+
console.log("Success: Replaced global core usage in:", basePath);
|
package/lib/scoping/lint-src.js
CHANGED
@@ -10,7 +10,7 @@ const errors = [];
|
|
10
10
|
glob.sync(path.join(process.cwd(), "src/**/*.css")).forEach(file => {
|
11
11
|
let content = String(fs.readFileSync(file));
|
12
12
|
tags.forEach(tag => {
|
13
|
-
if (content.match(new RegExp(`(^|[
|
13
|
+
if (content.match(new RegExp(`(^|[^\.\-_A-Za-z0-9"\[])(${tag})([^\-_A-Za-z0-9]|$)`, "g"))) {
|
14
14
|
errors.push(`Warning! ${tag} found in ${file}`);
|
15
15
|
}
|
16
16
|
});
|
@@ -0,0 +1,65 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const glob = require("glob");
|
3
|
+
const path = require("path");
|
4
|
+
const process = require("process");
|
5
|
+
|
6
|
+
const projectPath = process.argv[2];
|
7
|
+
|
8
|
+
// gather all tags from all files
|
9
|
+
const tagsToFiles = new Map();
|
10
|
+
const filesToTags = new Map();
|
11
|
+
|
12
|
+
let files = [
|
13
|
+
...glob.sync(path.join("packages/main/src/**/*.js")),
|
14
|
+
...glob.sync(path.join("packages/fiori/src/**/*.js")),
|
15
|
+
];
|
16
|
+
files.forEach(file => {
|
17
|
+
let matches = file.match(/([a-zA-Z0-9_]+)\.js$/);
|
18
|
+
const name = matches[1];
|
19
|
+
|
20
|
+
const content = `${fs.readFileSync(file)}`;
|
21
|
+
matches = content.match(/tag: "(.*?)",/);
|
22
|
+
if (matches) {
|
23
|
+
const tag = matches[1];
|
24
|
+
tagsToFiles.set(tag, name);
|
25
|
+
filesToTags.set(name, tag);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
// Process the package
|
30
|
+
files = glob.sync(path.join(projectPath, "src/**/*.js"));
|
31
|
+
tagsToFiles.forEach((file, tag) => {
|
32
|
+
const sourcePath = path.join(projectPath, "src/", `${file}.js`);
|
33
|
+
if (!fs.existsSync(sourcePath)) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
const sourceContent = `${fs.readFileSync(sourcePath)}`.split("\n").join(" ");
|
37
|
+
|
38
|
+
const hbsPath = path.join(projectPath, "src/", `${file}.hbs`);
|
39
|
+
const hbsContent = fs.existsSync(hbsPath) ? `${fs.readFileSync(hbsPath)}` : "";
|
40
|
+
|
41
|
+
const hbsPopoverPath = path.join(projectPath, "src/", `${file}Popover.hbs`);
|
42
|
+
const hbsPopoverContent = fs.existsSync(hbsPopoverPath) ? `${fs.readFileSync(hbsPopoverPath)}` : "";
|
43
|
+
|
44
|
+
// deps
|
45
|
+
let deps = [];
|
46
|
+
let matches = sourceContent.match(/static get dependencies\(\) \{\s+return \[(.*?)\]/);
|
47
|
+
if (matches) {
|
48
|
+
deps = matches[1].split(",").map(x => x.trim()).filter(x => !!x);
|
49
|
+
}
|
50
|
+
|
51
|
+
// tags
|
52
|
+
matches = [
|
53
|
+
...hbsContent.matchAll(/<ui5-[a-z0-9-]+/g),
|
54
|
+
...hbsPopoverContent.matchAll(/<ui5-[a-z0-9-]+/g),
|
55
|
+
];
|
56
|
+
if (matches) {
|
57
|
+
matches.forEach(match => {
|
58
|
+
const tagUsed = match[0].substr(1);
|
59
|
+
const dep = tagsToFiles.get(tagUsed);
|
60
|
+
if (!deps.includes(dep)) {
|
61
|
+
console.log(`${file} used ${tagUsed}`);
|
62
|
+
}
|
63
|
+
});
|
64
|
+
}
|
65
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const glob = require("glob");
|
3
|
+
const path = require("path");
|
4
|
+
const process = require("process");
|
5
|
+
|
6
|
+
// gather all tags from all files
|
7
|
+
const tags = new Set();
|
8
|
+
const files = glob.sync(path.join(process.argv[2], "src/**/*.js"));
|
9
|
+
files.forEach(file => {
|
10
|
+
const content = `${fs.readFileSync(file)}`;
|
11
|
+
const matches = content.match(/tag: "(.*?)",/);
|
12
|
+
if (matches) {
|
13
|
+
tags.add(matches[1]);
|
14
|
+
}
|
15
|
+
});
|
16
|
+
|
17
|
+
// report all usages of any tag within any file, which is not the tag definition and is not hasAttribute
|
18
|
+
files.forEach(file => {
|
19
|
+
const content = `${fs.readFileSync(file)}`;
|
20
|
+
const lines = content.split("\n");
|
21
|
+
lines.forEach(line => {
|
22
|
+
tags.forEach(tag => {
|
23
|
+
if (line.includes(`"${tag}"`) && !line.includes(`tag: "${tag}",`) && !line.includes(`hasAttribute("${tag}")`)) {
|
24
|
+
console.log(`${file}: ${line.trim()}`);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
});
|
28
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const path = require("path");
|
3
|
+
const commandLineArgs = require("command-line-args");
|
4
|
+
const { exec } = require("child_process");
|
5
|
+
const colors = require("cli-color");
|
6
|
+
const isPortReachable = require("is-port-reachable");
|
7
|
+
|
8
|
+
const options = commandLineArgs([
|
9
|
+
{ name: "port", type: Number },
|
10
|
+
{ name: "portStep", type: Number },
|
11
|
+
{ name: "packageName", type: String },
|
12
|
+
{ name: "dir", type: String },
|
13
|
+
{ name: "config", type: String },
|
14
|
+
]);
|
15
|
+
const serveConfig = path.join(__dirname, `serve.json`);
|
16
|
+
|
17
|
+
const requestPort = async () => {
|
18
|
+
const serveProcess = (await gen.next()).value;
|
19
|
+
serveProcess.stdout.on('data', data => {
|
20
|
+
const matches = data.match(/Accepting connections at .*?:(\d+)/);
|
21
|
+
if (matches) {
|
22
|
+
console.log(colors.yellow(`Reserved port ${matches[1]} for the ${options.packageName} package.`));
|
23
|
+
fs.writeFileSync(".port", matches[1]);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
};
|
27
|
+
|
28
|
+
async function* serverGenerator(callback, port = 8080, step = 1) {
|
29
|
+
while (true) {
|
30
|
+
const portInUse = await isPortReachable(port, { host: "127.0.0.1" });
|
31
|
+
if (!portInUse) {
|
32
|
+
const command = `serve --config "${serveConfig}" --no-port-switching --no-clipboard -l ${port} ${options.dir}`;
|
33
|
+
console.log(colors.yellow(`Executing: ${command}`));
|
34
|
+
const serveProcess = exec(command, (err) => {
|
35
|
+
console.log(colors.yellow(`Port ${port} already in use.`));
|
36
|
+
callback();
|
37
|
+
});
|
38
|
+
yield serveProcess;
|
39
|
+
}
|
40
|
+
port += step;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
const gen = serverGenerator(requestPort, options.port, options.portStep);
|
45
|
+
|
46
|
+
requestPort();
|
File without changes
|