Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tools): remove js template from @ui5/create-webcomponents-package #8503

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/create-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Options:
--name <string> - defines the package name
--component-name <string> - defines the component class name that will be created in your new package
--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.
--enable-typescript - enables TypeScript support for the package
--skip - skips configuration and generates package with a default value for each parameter that wasn't passed
```

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

Expand Down
46 changes: 4 additions & 42 deletions packages/create-package/create-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))
// from where all the files will be copied
const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);

// String utils
const isTSRelatedFile = sourcePath => {
return ["Assets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
};
const isJSRelatedFile = sourcePath => {
return ["Assets.js", "MyFirstComponent.js"].some(fileName => sourcePath.includes(fileName));
};
const isGitIgnore = sourcePath => {
return sourcePath.includes("gitignore");
};
Expand Down Expand Up @@ -65,13 +58,6 @@ const replaceVarsInFileName = (vars, fileName) => {
};

const copyFile = (vars, sourcePath, destPath) => {
const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && isJSRelatedFile(sourcePath);
const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTSRelatedFile(sourcePath);

if (ignoreJsRelated || ignoreTsRelated) {
return;
}

if (isLogo(sourcePath)) {
fs.copyFileSync(sourcePath, destPath);
return;
Expand Down Expand Up @@ -108,7 +94,7 @@ const copyFiles = (vars, sourcePath, destPath) => {
}
};

const generateFilesContent = (packageName, componentName, namespace, typescript, skipSubfolder) => {
const generateFilesContent = (packageName, componentName, namespace, skipSubfolder) => {
const tagName = argv.tag || hyphaneteComponentName(componentName);

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

const packageContent = {
Expand Down Expand Up @@ -150,13 +135,10 @@ const generateFilesContent = (packageName, componentName, namespace, typescript,
"devDependencies": {
"@ui5/webcomponents-tools": version,
"chromedriver": "*",
"typescript": "^5.2.2"
},
};

if (typescript) {
packageContent.devDependencies.typescript = "^4.9.4";
}

// Update package.json
let destDir = packageName.includes("@") ? packageName.slice(packageName.lastIndexOf("/") + 1) : packageName;

Expand Down Expand Up @@ -207,11 +189,10 @@ const createWebcomponentsPackage = async () => {
let packageName = argv.name || "my-package";
let componentName = argv.componentName || "MyComponent";
let namespace = argv.namespace || "demo.components";
let typescriptSupport = !!argv.enableTypescript;
const skipSubfolder = !!argv.skipSubfolder;

if (argv.skip) {
return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
return generateFilesContent(packageName, componentName, namespace, skipSubfolder);
}

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

if (!typescriptSupport) {
response = await prompts({
type: "select",
name: "language",
message: "Project type:",
choices: [
{
title: "JavaScript",
value: false,
},
{
title: "TypeScript",
value: true,
},
],
});
typescriptSupport = response.language;
}

if (!argv.componentName) {
response = await prompts({
type: "text",
Expand All @@ -265,7 +227,7 @@ const createWebcomponentsPackage = async () => {
namespace = response.namespace;
}

return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
return generateFilesContent(packageName, componentName, namespace, skipSubfolder);
};

createWebcomponentsPackage();
2 changes: 1 addition & 1 deletion packages/create-package/template/package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getScripts = require("@ui5/webcomponents-tools/components-package/nps.js")

const options = {
port: 8080,
typescript: INIT_PACKAGE_VAR_TYPESCRIPT,
typescript: true,
};

const scripts = getScripts(options);
Expand Down
5 changes: 0 additions & 5 deletions packages/create-package/template/src/Assets.js

This file was deleted.

82 changes: 0 additions & 82 deletions packages/create-package/template/src/MyFirstComponent.js

This file was deleted.

15 changes: 4 additions & 11 deletions packages/tools/lib/create-new-component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,15 @@ const getLibraryName = packageName => {
return packageName.substr("webcomponents-".length);
};

const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
const generateFiles = (componentName, tagName, library, packageName) => {
componentName = capitalizeFirstLetter(componentName);
const filePaths = {
"main": isTypeScript
? `./src/${componentName}.ts`
: `./src/${componentName}.js`,
"main": `./src/${componentName}.ts`,
"css": `./src/themes/${componentName}.css`,
"template": `./src/${componentName}.hbs`,
};

const FileContentTemplate = isTypeScript
? tsFileContentTemplate(componentName, tagName, library, packageName)
: jsFileContentTemplate(componentName, tagName, library, packageName);

fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
fs.writeFileSync(filePaths.main, tsFileContentTemplate(componentName, tagName, library, packageName), { flag: "wx+" });
fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });

Expand Down Expand Up @@ -112,10 +106,9 @@ const createWebComponent = async () => {
}
}

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

generateFiles(componentName, tagName, library, packageName, isTypeScript);
generateFiles(componentName, tagName, library, packageName);
};

createWebComponent();
73 changes: 0 additions & 73 deletions packages/tools/lib/create-new-component/jsFileContentTemplate.js

This file was deleted.