Skip to content

Commit 17ae152

Browse files
authored
refactor(tools): remove js option from generation templates (#8503)
With the release of version 2.0, we strongly encourage component development to be done in TypeScript. Consequently, we are discontinuing the option to generate JavaScript projects and components, as the tooling will no longer support them by default. BREAKING CHANGE: Remove JavaScript template option from @ui5/create-webcomponents-package Previously `npm init @ui5/webcomponents-package` used to create JS-based project, however now it will be TypeScript-based project. If you previously used `npm init @ui5/webcomponents-package --enable-typescript` to create TypeScript-based project, now it's by default, e.g `npm init @ui5/webcomponents-package` and `--enable-typescript` is removed. Related to [#8461](#8461)
1 parent 62d235d commit 17ae152

File tree

7 files changed

+9
-216
lines changed

7 files changed

+9
-216
lines changed

packages/create-package/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Options:
2121
--name <string> - defines the package name
2222
--component-name <string> - defines the component class name that will be created in your new package
2323
--tag <string> - defines the tag name of the sample web component that will be created in your new package. The tag will be derived from the component name if not provided.
24-
--enable-typescript - enables TypeScript support for the package
2524
--skip - skips configuration and generates package with a default value for each parameter that wasn't passed
2625
```
2726

@@ -37,7 +36,6 @@ Options:
3736
--name <string> - defines the package name
3837
--component-name <string> - defines the component class name that will be created in your new package
3938
--tag <string> - defines the tag name of the sample web component that will be created in your new package
40-
--enable-typescript - enables TypeScript support for the package
4139
--skip - skips configuration and generates package with a default value for each parameter that wasn't passed
4240
```
4341

packages/create-package/create-package.js

+4-42
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))
1515
// from where all the files will be copied
1616
const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
1717

18-
// String utils
19-
const isTSRelatedFile = sourcePath => {
20-
return ["Assets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
21-
};
22-
const isJSRelatedFile = sourcePath => {
23-
return ["Assets.js", "MyFirstComponent.js"].some(fileName => sourcePath.includes(fileName));
24-
};
2518
const isGitIgnore = sourcePath => {
2619
return sourcePath.includes("gitignore");
2720
};
@@ -65,13 +58,6 @@ const replaceVarsInFileName = (vars, fileName) => {
6558
};
6659

6760
const copyFile = (vars, sourcePath, destPath) => {
68-
const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && isJSRelatedFile(sourcePath);
69-
const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTSRelatedFile(sourcePath);
70-
71-
if (ignoreJsRelated || ignoreTsRelated) {
72-
return;
73-
}
74-
7561
if (isLogo(sourcePath)) {
7662
fs.copyFileSync(sourcePath, destPath);
7763
return;
@@ -108,7 +94,7 @@ const copyFiles = (vars, sourcePath, destPath) => {
10894
}
10995
};
11096

111-
const generateFilesContent = (packageName, componentName, namespace, typescript, skipSubfolder) => {
97+
const generateFilesContent = (packageName, componentName, namespace, skipSubfolder) => {
11298
const tagName = argv.tag || hyphaneteComponentName(componentName);
11399

114100
// All variables that will be replaced in the content of the resources/
@@ -117,7 +103,6 @@ const generateFilesContent = (packageName, componentName, namespace, typescript,
117103
INIT_PACKAGE_VAR_NAME: packageName,
118104
INIT_PACKAGE_VAR_TAG: tagName,
119105
INIT_PACKAGE_VAR_CLASS_NAME: componentName,
120-
INIT_PACKAGE_VAR_TYPESCRIPT: typescript,
121106
};
122107

123108
const packageContent = {
@@ -150,13 +135,10 @@ const generateFilesContent = (packageName, componentName, namespace, typescript,
150135
"devDependencies": {
151136
"@ui5/webcomponents-tools": version,
152137
"chromedriver": "*",
138+
"typescript": "^5.2.2"
153139
},
154140
};
155141

156-
if (typescript) {
157-
packageContent.devDependencies.typescript = "^4.9.4";
158-
}
159-
160142
// Update package.json
161143
let destDir = packageName.includes("@") ? packageName.slice(packageName.lastIndexOf("/") + 1) : packageName;
162144

@@ -207,11 +189,10 @@ const createWebcomponentsPackage = async () => {
207189
let packageName = argv.name || "my-package";
208190
let componentName = argv.componentName || "MyComponent";
209191
let namespace = argv.namespace || "demo.components";
210-
let typescriptSupport = !!argv.enableTypescript;
211192
const skipSubfolder = !!argv.skipSubfolder;
212193

213194
if (argv.skip) {
214-
return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
195+
return generateFilesContent(packageName, componentName, namespace, skipSubfolder);
215196
}
216197

217198
if (!argv.name) {
@@ -224,25 +205,6 @@ const createWebcomponentsPackage = async () => {
224205
packageName = response.name;
225206
}
226207

227-
if (!typescriptSupport) {
228-
response = await prompts({
229-
type: "select",
230-
name: "language",
231-
message: "Project type:",
232-
choices: [
233-
{
234-
title: "JavaScript",
235-
value: false,
236-
},
237-
{
238-
title: "TypeScript",
239-
value: true,
240-
},
241-
],
242-
});
243-
typescriptSupport = response.language;
244-
}
245-
246208
if (!argv.componentName) {
247209
response = await prompts({
248210
type: "text",
@@ -265,7 +227,7 @@ const createWebcomponentsPackage = async () => {
265227
namespace = response.namespace;
266228
}
267229

268-
return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
230+
return generateFilesContent(packageName, componentName, namespace, skipSubfolder);
269231
};
270232

271233
createWebcomponentsPackage();

packages/create-package/template/package-scripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const getScripts = require("@ui5/webcomponents-tools/components-package/nps.js")
22

33
const options = {
44
port: 8080,
5-
typescript: INIT_PACKAGE_VAR_TYPESCRIPT,
5+
typescript: true,
66
};
77

88
const scripts = getScripts(options);

packages/create-package/template/src/Assets.js

-5
This file was deleted.

packages/create-package/template/src/MyFirstComponent.js

-82
This file was deleted.

packages/tools/lib/create-new-component/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,15 @@ const getLibraryName = packageName => {
5858
return packageName.substr("webcomponents-".length);
5959
};
6060

61-
const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
61+
const generateFiles = (componentName, tagName, library, packageName) => {
6262
componentName = capitalizeFirstLetter(componentName);
6363
const filePaths = {
64-
"main": isTypeScript
65-
? `./src/${componentName}.ts`
66-
: `./src/${componentName}.js`,
64+
"main": `./src/${componentName}.ts`,
6765
"css": `./src/themes/${componentName}.css`,
6866
"template": `./src/${componentName}.hbs`,
6967
};
7068

71-
const FileContentTemplate = isTypeScript
72-
? tsFileContentTemplate(componentName, tagName, library, packageName)
73-
: jsFileContentTemplate(componentName, tagName, library, packageName);
74-
75-
fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
69+
fs.writeFileSync(filePaths.main, tsFileContentTemplate(componentName, tagName, library, packageName), { flag: "wx+" });
7670
fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
7771
fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
7872

@@ -112,10 +106,9 @@ const createWebComponent = async () => {
112106
}
113107
}
114108

115-
const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
116109
const tagName = hyphaneteComponentName(componentName);
117110

118-
generateFiles(componentName, tagName, library, packageName, isTypeScript);
111+
generateFiles(componentName, tagName, library, packageName);
119112
};
120113

121114
createWebComponent();

packages/tools/lib/create-new-component/jsFileContentTemplate.js

-73
This file was deleted.

0 commit comments

Comments
 (0)