Skip to content

Commit b5e1337

Browse files
authored
chore(framework): Create a localization package and deprecate utils (#1296)
1 parent 2f4fd6e commit b5e1337

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2464
-45
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Keep in mind that linking the same module with npm and Yarn may cause issues. Al
183183
- [UI5 Web Components Icons](https://www.npmjs.com/package/@ui5/webcomponents-icons)
184184
- [UI5 Web Components Base](https://www.npmjs.com/package/@ui5/webcomponents-base)
185185
- [UI5 Web Components Theme Base](https://www.npmjs.com/package/@ui5/webcomponents-theme-base)
186-
- [UI5 Web Components Utils](https://www.npmjs.com/package/@ui5/webcomponents-utils)
186+
- [UI5 Web Components Localization](https://www.npmjs.com/package/@ui5/webcomponents-localization)
187187

188188
## Limitations
189189
None as of 1.0.0-rc.5

docs/Assets.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Currently our npm packages follow the scheme:
1616
<a name="packages"></a>
1717
## Packages
1818

19-
### `utils` package
19+
### `localization` package
2020

21-
The `utils` package provides CLDR assets.
21+
The `localization` package provides CLDR assets.
2222

2323
`import "@ui5/webcomponents-utils/dist/Assets.js";`
2424

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
"ui5"
1010
],
1111
"scripts": {
12-
"build": "npm-run-all --sequential build:utils build:base build:theme-base build:icons build:main build:fiori",
13-
"build:utils": "cd packages/utils && yarn build",
12+
"build": "npm-run-all --sequential build:base build:localization build:theme-base build:icons build:main build:fiori",
13+
"build:localization": "cd packages/localization && yarn build",
1414
"build:base": "cd packages/base && yarn build",
1515
"build:theme-base": "cd packages/theme-base && yarn build",
1616
"build:icons": "cd packages/icons && yarn build",
1717
"build:main": "cd packages/main && yarn build",
1818
"build:fiori": "cd packages/fiori && yarn build",
1919
"build:playground": "yarn build:main && yarn build:fiori && cd packages/playground && yarn build",
2020
"build:playground:master": "yarn build:main && yarn build:fiori && cd packages/playground && yarn build:master",
21-
"clean": "npm-run-all --sequential clean:utils clean:base clean:theme-base clean:icons clean:main clean:fiori",
22-
"clean:utils": "cd packages/utils && yarn clean",
21+
"clean": "npm-run-all --sequential clean:base clean:localization clean:theme-base clean:icons clean:main clean:fiori",
22+
"clean:localization": "cd packages/localization && yarn clean",
2323
"clean:base": "cd packages/base && yarn clean",
2424
"clean:theme-base": "cd packages/theme-base && yarn clean",
2525
"clean:icons": "cd packages/icons && yarn clean",
@@ -28,11 +28,12 @@
2828
"prepare:main": "cd packages/main && nps prepare",
2929
"prepare:fiori": "cd packages/fiori && nps prepare",
3030
"dev:base": "cd packages/base && nps watch",
31+
"dev:localization": "cd packages/localization && nps watch",
3132
"dev:theme-base": "cd packages/theme-base && nps watch",
3233
"dev:main": "cd packages/main && nps dev",
3334
"dev:fiori": "cd packages/fiori && nps dev",
34-
"start": "npm-run-all --sequential build:utils build:base build:theme-base build:icons prepare:main prepare:fiori start:all",
35-
"start:all": "npm-run-all --parallel dev:base dev:theme-base dev:main dev:fiori",
35+
"start": "npm-run-all --sequential build:localization build:base build:theme-base build:icons prepare:main prepare:fiori start:all",
36+
"start:all": "npm-run-all --parallel dev:base dev:localization dev:theme-base dev:main dev:fiori",
3637
"start:base": "cd packages/base && yarn start",
3738
"start:theme-base": "cd packages/theme-base && yarn start",
3839
"start:main": "cd packages/main && yarn start",
@@ -60,6 +61,7 @@
6061
"packages/core",
6162
"packages/utils",
6263
"packages/base",
64+
"packages/localization",
6365
"packages/main",
6466
"packages/fiori",
6567
"packages/icons",

packages/base/package-scripts.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const scripts = {
1111
},
1212
copy: {
1313
default: "nps copy.src copy.test copy.webcomponents-polyfill",
14-
cldr: 'copy-and-watch "../../node_modules/@ui5/webcomponents-utils/dist/**/cldr/*.json" dist/generated/assets/cldr/',
1514
src: "copy-and-watch \"src/**/*.js\" dist/",
1615
test: "copy-and-watch \"test/**/*.*\" dist/test-resources",
1716
"webcomponents-polyfill": "copy-and-watch \"../../node_modules/@webcomponents/webcomponentsjs/**/*.*\" dist/webcomponentsjs/",

packages/core/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**DEPRECATED!!!**
66

7-
This package is now deprecated in favor of [@ui5/webcomponents-utils](https://www.npmjs.com/package/@ui5/webcomponents-utils).
7+
This package is now deprecated in favor of [@ui5/webcomponents-localization](https://www.npmjs.com/package/@ui5/webcomponents-localization).
88

99
[![Travis CI Build Status](https://travis-ci.org/SAP/ui5-webcomponents.svg?branch=master)](https://travis-ci.org/SAP/ui5-webcomponents)
1010
[![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)

packages/localization/.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
lib
3+
overlay
4+
package-scripts.js

packages/localization/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/
2+
node_modules/
3+
overlay/
4+
!core

packages/localization/.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Enforce public npm registry
2+
registry = https://registry.npmjs.org/

packages/localization/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/master/docs/images/UI5_logo_wide.png)
2+
3+
# UI5 Web Components - Localization
4+
5+
[![Travis CI Build Status](https://travis-ci.org/SAP/ui5-webcomponents.svg?branch=master)](https://travis-ci.org/SAP/ui5-webcomponents)
6+
[![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)
7+
8+
Provides date/time and CLDR functionality for the purposes of building UI5 Web Components.
9+
10+
## Resources
11+
- [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/master/README.md)
12+
- [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
13+
- [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
14+
15+
## Support
16+
We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://join-ui5-slack.herokuapp.com/).
17+
18+
## Contribute
19+
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/CONTRIBUTING.md).
20+
21+
## License
22+
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
23+
This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/master/LICENSE.txt) file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const config = require("@ui5/webcomponents-tools/components-package/eslint.js");
2+
3+
module.exports = config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const child_process = require("child_process");
4+
5+
const fileList = process.argv[2];
6+
const dest = process.argv[3];
7+
8+
const filesToCopy = fs.readFileSync(fileList).toString();
9+
// console.log(filesToCopy);
10+
11+
// Support full-line comments starting with # in the used-modules.txt file
12+
const shouldCopy = file => file.length && !file.startsWith("#");
13+
14+
const trimFile = file => file.trim();
15+
16+
const copyArgs = filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(moduleName => {
17+
return "../../node_modules/@openui5/sap.ui.core/src/" + moduleName + " " + path.dirname(path.join(dest, moduleName));
18+
});
19+
20+
copyArgs.forEach(args => {
21+
console.log(args);
22+
child_process.execSync(`npx copy-and-watch ${args}`)
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const esprima = require("esprima");
2+
const escodegen = require("escodegen");
3+
4+
const fs = require("fs");
5+
const path = require("path");
6+
const glob = require("glob");
7+
const basePath = process.argv[2];
8+
9+
const convertImports = (srcPath) => {
10+
let changed = false;
11+
// console.log("scanning imports of", srcPath);
12+
let code = fs.readFileSync(srcPath).toString();
13+
const tree = esprima.parseModule(code);
14+
const importer = srcPath.replace(basePath, "");
15+
const importerDir = path.dirname(importer);
16+
// console.log("-> ", importer);
17+
tree.body.forEach(node => {
18+
if (node.type === "ImportDeclaration") {
19+
let importee = node.source.value;
20+
if (importee.startsWith(".")) {
21+
// add .js extension if missing
22+
if (!importee.endsWith(".js")) {
23+
node.source.value += ".js"
24+
changed = true;
25+
}
26+
return;
27+
}
28+
let importeeDir = path.dirname(importee);
29+
let importeeFile = path.basename(importee);
30+
let relativePath = path.relative(importerDir, importeeDir);
31+
if (relativePath.length === 0) {
32+
relativePath = "."
33+
}
34+
if (!relativePath.startsWith(".")) {
35+
relativePath = "./" + relativePath;
36+
}
37+
38+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
39+
let relativeImport = `${relativePath}/${importeeFile}.js`;
40+
// console.log(importee + " --> " + relativeImport);
41+
node.source.value = relativeImport;
42+
changed = true;
43+
}
44+
});
45+
46+
if (changed) {
47+
fs.writeFileSync(srcPath, escodegen.generate(tree));
48+
}
49+
}
50+
51+
const fileNames = glob.sync(basePath + "**/*.js");
52+
// console.log(fileNames);
53+
fileNames.forEach(convertImports);
54+
console.log("Success: Converted absolute imports to relative for files in:", basePath)
Original file line numberDiff line numberDiff line change
@@ -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);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sap.ui.define([], function () {
2+
// used by Metadata.js
3+
return {
4+
browser: {
5+
phantomJS: false
6+
}
7+
}
8+
});

0 commit comments

Comments
 (0)