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

build: added dev server for ui kit development #3720

Merged
merged 3 commits into from
Jul 31, 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
42 changes: 42 additions & 0 deletions dokka-subprojects/plugin-base-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
### How to use frontend dev-server:

0. Prebuild Dokka's output for the ui-showcase project:

```bash
# Remove previous build
rm -rf dokka-integration-tests/gradle/build/ui-showcase-result
# Set output path
export DOKKA_TEST_OUTPUT_PATH='build/ui-showcase-result'
# Run gradle task
./gradlew :dokka-integration-tests:gradle:testUiShowcaseProject
```

<small> For this repetitive sequence of tasks, it could be convenient to create an alias in the bash profile, something like:</small>

```bash
alias dokkabuild="rm -rf dokka-integration-tests/gradle/build/ui-showcase-result && export DOKKA_TEST_OUTPUT_PATH='build/ui-showcase-result' && ./gradlew :dokka-integration-tests:gradle:testUiShowcaseProject"
```
<small>and then rerun only `dokkabuild`command in terminal</small>

1. Go to the plugin-base-frontend directory:
```bash
cd dokka-subprojects/plugin-base-frontend
```
2. Run dev server for ui kit:
```bash
npm run start:ui-kit
```

3. Open the browser and go to http://localhost:8001

The dev server will watch for changes in the `plugin-base-frontend/` and rebuild the `ui-showcase` project automatically.
However, for the changes in html structure produced by kotlin templates one needs to rerun `dokkabuild` manually while there is no need to restart the dev server.


### How to create a new UI kit component:

1. Run `npm run create-component -- <component-name-in-kebab-case>`

It will create all necessary files templates in `src/main/ui-kit/` directory and import them in `src/main/ui-kit/index.ts` and `src/main/ui-kit/index.scss` files.

2. Export component manually from `src/main/ui-kit/index.ts` file to make in available for webpack
65 changes: 65 additions & 0 deletions dokka-subprojects/plugin-base-frontend/create-component.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import fs from 'fs';

const firstLetterToLoweCase = str => str.charAt(0).toLowerCase() + str.slice(1);

const kebabToCamelCase = str => str.replace(/-./g, x => x.toUpperCase()[1]);

const uiKitPath = 'src/main/ui-kit';
const componentName = process.argv[2];
const componentPath = `${uiKitPath}/${componentName}`;
const lowerCaseComponentName = firstLetterToLoweCase(componentName);
const lowerCaseComponentNameCamelCase = firstLetterToLoweCase(kebabToCamelCase(componentName));

const uiKitIndexTsFile = `${uiKitPath}/index.ts`;
const uiKitIndexScssFile = `${uiKitPath}/index.scss`;
const componentIndexTsFile = `${componentPath}/index.ts`;
const componentScssFile = `${componentPath}/styles.scss`;

const currentYear = new Date().getFullYear();

const componentIndexTsFileContent = `/*
* Copyright 2014-${currentYear} JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import './styles.scss';
`;

const componentScssFileContent = `/*!
* Copyright 2014-${currentYear} JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
@import '../tokens/index';

.${lowerCaseComponentName} {
}
`;

const uiKitIndexTsFileContent = `import * as ${lowerCaseComponentNameCamelCase} from './${componentName}/index';
`;

const uiKitIndexScssFileContent = `@import './${componentName}/styles';
`;


fs.mkdir(componentPath, error => {
if (error) {
throw error;
}

const pathToContentMap = {
[componentIndexTsFile]: componentIndexTsFileContent,
[componentScssFile]: componentScssFileContent,
[uiKitIndexTsFile]: uiKitIndexTsFileContent,
[uiKitIndexScssFile]: uiKitIndexScssFileContent,
};

Object.keys(pathToContentMap).forEach((path) => {
fs.appendFile(path, pathToContentMap[path], function (err) {
if (err) {
return console.error(err);
}
console.log(`${path} updated successfully`);
});
});

console.log(`Component ${componentPath} created successfully`);
});
Loading
Loading