@ui5/create-webcomponents-package 0.0.2 → 0.0.6
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/README.md +16 -1
- package/index.js +169 -0
- package/package.json +4 -6
- package/{lib/init-package/resources → template}/.eslintignore +0 -0
- package/{lib/init-package/resources → template}/bundle.esm.js +0 -0
- package/{lib/init-package/resources → template}/config/.eslintrc.js +0 -0
- package/{lib/init-package/resources → template}/config/postcss.components/postcss.config.js +0 -0
- package/{lib/init-package/resources → template}/config/postcss.themes/postcss.config.js +0 -0
- package/{lib/init-package/resources → template}/config/rollup.config.js +0 -0
- package/{lib/init-package/resources → template}/config/wdio.conf.js +0 -0
- package/{lib/init-package/resources → template}/package-scripts.js +0 -0
- package/{lib/init-package/resources → template}/src/Assets.js +0 -0
- package/{lib/init-package/resources → template}/src/MyFirstComponent.hbs +0 -0
- package/{lib/init-package/resources → template}/src/MyFirstComponent.js +0 -0
- package/{lib/init-package/resources → template}/src/i18n/messagebundle.properties +0 -0
- package/{lib/init-package/resources → template}/src/i18n/messagebundle_de.properties +0 -0
- package/{lib/init-package/resources → template}/src/i18n/messagebundle_en.properties +0 -0
- package/{lib/init-package/resources → template}/src/i18n/messagebundle_es.properties +0 -0
- package/{lib/init-package/resources → template}/src/i18n/messagebundle_fr.properties +0 -0
- package/{lib/init-package/resources → template}/src/themes/MyFirstComponent.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_belize/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_belize_hcb/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_belize_hcw/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_fiori_3/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -0
- package/{lib/init-package/resources → template}/test/pages/index.html +0 -0
- package/{lib/init-package/resources → template}/test/specs/Demo.spec.js +0 -0
- package/yarn-error.log +10165 -0
- package/bin/init-ui5-package.js +0 -3
- package/lib/init-package/index.js +0 -1
package/README.md
CHANGED
@@ -5,7 +5,22 @@
|
|
5
5
|
[](https://travis-ci.org/SAP/ui5-webcomponents)
|
6
6
|
[](https://www.npmjs.com/package/@ui5/webcomponents)
|
7
7
|
|
8
|
-
Provides
|
8
|
+
Provides an `npm init` script for creating new UI5 Webcomponents Packages
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
with `npm`
|
13
|
+
|
14
|
+
- `npm init @ui5/webcomponents-package` (the user will be asked for **name**, **port**, **tag**)
|
15
|
+
- `npm init @ui5/webcomponents-package <NEW-PACKAGE-NAME>` (the user will be asked for **port** and **tag** only)
|
16
|
+
|
17
|
+
and with `yarn`
|
18
|
+
|
19
|
+
- `yarn create @ui5/webcomponents-package`
|
20
|
+
- `yarn create @ui5/webcomponents-package <NEW-PACKAGE-NAME>`
|
21
|
+
|
22
|
+
The script creates a new directory, and fills it with a `package.json` file and all necessary source files and resources for a new
|
23
|
+
components package.
|
9
24
|
|
10
25
|
## Resources
|
11
26
|
- [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/master/README.md)
|
package/index.js
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require("fs");
|
4
|
+
const path = require("path");
|
5
|
+
const mkdirp = require("mkdirp");
|
6
|
+
const prompts = require("prompts");
|
7
|
+
const beautify = require("json-beautify");
|
8
|
+
const parser = require("npm-config-user-agent-parser");
|
9
|
+
|
10
|
+
// from where all the files will be copied
|
11
|
+
const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
|
12
|
+
|
13
|
+
// String utils
|
14
|
+
const capitalizeFirst = str => str.substr(0,1).toUpperCase() + str.substr(1);
|
15
|
+
const kebabToCamelCase = string => toCamelCase(string.split("-"));
|
16
|
+
const toCamelCase = parts => {
|
17
|
+
return parts.map((string, index) => {
|
18
|
+
return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
19
|
+
}).join("");
|
20
|
+
};
|
21
|
+
|
22
|
+
// Validation of user input
|
23
|
+
const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
|
24
|
+
const isPortValid = port => typeof port === "string" && port.match(/^[0-9]+$/);
|
25
|
+
const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
|
26
|
+
|
27
|
+
// Utils for building the file structure
|
28
|
+
const replaceVarsInFileContent = (vars, content) => {
|
29
|
+
for (let key in vars) {
|
30
|
+
const re = new RegExp(key, "g");
|
31
|
+
content = content.replace(re, vars[key]);
|
32
|
+
}
|
33
|
+
return content;
|
34
|
+
};
|
35
|
+
|
36
|
+
const replaceVarsInFileName = (vars, fileName) => {
|
37
|
+
return fileName.replace(/MyFirstComponent/, vars.INIT_PACKAGE_VAR_CLASS_NAME);
|
38
|
+
};
|
39
|
+
|
40
|
+
const copyFile = (vars, sourcePath, destPath) => {
|
41
|
+
let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
|
42
|
+
content = replaceVarsInFileContent(vars, content);
|
43
|
+
destPath = replaceVarsInFileName(vars, destPath);
|
44
|
+
fs.writeFileSync(destPath, content);
|
45
|
+
};
|
46
|
+
|
47
|
+
const copyFiles = (vars, sourcePath, destPath) => {
|
48
|
+
const isDir = fs.lstatSync(sourcePath).isDirectory();
|
49
|
+
if (isDir) {
|
50
|
+
if (destPath) {
|
51
|
+
mkdirp.sync(destPath);
|
52
|
+
}
|
53
|
+
fs.readdirSync(sourcePath).forEach(file => {
|
54
|
+
copyFiles(vars, path.join(sourcePath, file), path.join(destPath, file));
|
55
|
+
});
|
56
|
+
} else {
|
57
|
+
copyFile(vars, sourcePath, destPath);
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
// Main function
|
62
|
+
const createWebcomponentsPackage = async () => {
|
63
|
+
let response;
|
64
|
+
|
65
|
+
// Get the name
|
66
|
+
let name = process.argv[2];
|
67
|
+
|
68
|
+
if (!isNameValid(name)) {
|
69
|
+
response = await prompts({
|
70
|
+
type: "text",
|
71
|
+
name: "name",
|
72
|
+
message: "Package name:",
|
73
|
+
validate: isNameValid,
|
74
|
+
});
|
75
|
+
name = response.name;
|
76
|
+
}
|
77
|
+
|
78
|
+
// Get the port
|
79
|
+
response = await prompts({
|
80
|
+
type: "text",
|
81
|
+
name: "port",
|
82
|
+
message: "Dev server port:",
|
83
|
+
validate: isPortValid,
|
84
|
+
initial: "8080",
|
85
|
+
});
|
86
|
+
const port = response.port;
|
87
|
+
|
88
|
+
// Get the tag
|
89
|
+
response = await prompts({
|
90
|
+
type: "text",
|
91
|
+
name: "tag",
|
92
|
+
message: "Demo component name:",
|
93
|
+
initial: "my-first-component",
|
94
|
+
validate: isTagValid,
|
95
|
+
});
|
96
|
+
const tag = response.tag;
|
97
|
+
|
98
|
+
const className = capitalizeFirst(kebabToCamelCase(tag));
|
99
|
+
|
100
|
+
// All variables that will be replaced in the content of the resources/
|
101
|
+
const vars = {
|
102
|
+
INIT_PACKAGE_VAR_NAME: name,
|
103
|
+
INIT_PACKAGE_VAR_PORT: port,
|
104
|
+
INIT_PACKAGE_VAR_TAG: tag,
|
105
|
+
INIT_PACKAGE_VAR_CLASS_NAME: className,
|
106
|
+
};
|
107
|
+
|
108
|
+
const packageContent = {
|
109
|
+
name,
|
110
|
+
version: "0.0.1",
|
111
|
+
ui5: {
|
112
|
+
webComponentsPackage: true,
|
113
|
+
},
|
114
|
+
scripts: {
|
115
|
+
"clean": "wc-dev clean",
|
116
|
+
"lint": "wc-dev lint",
|
117
|
+
"start": "wc-dev start",
|
118
|
+
"watch": "wc-dev watch",
|
119
|
+
"serve": "wc-dev serve",
|
120
|
+
"build": "wc-dev build",
|
121
|
+
"test": "wc-dev test",
|
122
|
+
"create-ui5-element": "wc-create-ui5-element",
|
123
|
+
"prepublishOnly": "npm run build",
|
124
|
+
},
|
125
|
+
exports: {
|
126
|
+
"./.port": "./.port",
|
127
|
+
"./src/*": "./src/*",
|
128
|
+
"./dist/*": "./dist/*",
|
129
|
+
"./package.json": "./package.json",
|
130
|
+
"./bundle.js": "./bundle.js",
|
131
|
+
"./*": "./dist/*",
|
132
|
+
},
|
133
|
+
"dependencies": {
|
134
|
+
"@ui5/webcomponents-base": "*",
|
135
|
+
"@ui5/webcomponents-theme-base": "*",
|
136
|
+
},
|
137
|
+
"devDependencies": {
|
138
|
+
"@ui5/webcomponents-tools": "*",
|
139
|
+
"chromedriver": "*",
|
140
|
+
},
|
141
|
+
};
|
142
|
+
|
143
|
+
// Update package.json
|
144
|
+
const destDir = path.join(`./`, name);
|
145
|
+
mkdirp.sync(destDir);
|
146
|
+
fs.writeFileSync(path.join(destDir, "package.json"), beautify(packageContent, null, 2, 100));
|
147
|
+
// Copy files
|
148
|
+
copyFiles(vars, TEMPLATE_DIR, destDir);
|
149
|
+
|
150
|
+
console.log("Package successfully created!\nNext steps:\n\n");
|
151
|
+
console.log(`$ cd ${name}`);
|
152
|
+
|
153
|
+
let userAgentInfo;
|
154
|
+
try {
|
155
|
+
userAgentInfo = parser(process.env.npm_config_user_agent);
|
156
|
+
} catch (e) {}
|
157
|
+
|
158
|
+
if (userAgentInfo && userAgentInfo.yarn) {
|
159
|
+
console.log(`$ yarn`);
|
160
|
+
console.log(`$ yarn start`);
|
161
|
+
} else {
|
162
|
+
console.log(`$ npm i`);
|
163
|
+
console.log(`$ npm start`);
|
164
|
+
}
|
165
|
+
|
166
|
+
console.log("\n\n");
|
167
|
+
};
|
168
|
+
|
169
|
+
createWebcomponentsPackage();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/create-webcomponents-package",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "UI5 Web Components: create package",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -10,9 +10,8 @@
|
|
10
10
|
"sapui5",
|
11
11
|
"ui5"
|
12
12
|
],
|
13
|
-
"scripts": {},
|
14
13
|
"bin": {
|
15
|
-
"create-webcomponents-package": "
|
14
|
+
"create-webcomponents-package": "index.js"
|
16
15
|
},
|
17
16
|
"repository": {
|
18
17
|
"type": "git",
|
@@ -20,10 +19,9 @@
|
|
20
19
|
"directory": "packages/create-package"
|
21
20
|
},
|
22
21
|
"dependencies": {
|
23
|
-
"command-line-args": "^5.2.0",
|
24
22
|
"json-beautify": "^1.1.1",
|
25
23
|
"mkdirp": "^1.0.4",
|
24
|
+
"npm-config-user-agent-parser": "^1.0.0",
|
26
25
|
"prompts": "^2.4.1"
|
27
|
-
}
|
28
|
-
"peerDependencies": {}
|
26
|
+
}
|
29
27
|
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_belize_hcb/parameters-bundle.css
RENAMED
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_belize_hcw/parameters-bundle.css
RENAMED
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_fiori_3/parameters-bundle.css
RENAMED
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_dark/parameters-bundle.css
RENAMED
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_hcb/parameters-bundle.css
RENAMED
File without changes
|
package/{lib/init-package/resources → template}/src/themes/sap_fiori_3_hcw/parameters-bundle.css
RENAMED
File without changes
|
File without changes
|
File without changes
|