Skip to content

Commit

Permalink
feat: add stylelint (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiansc authored May 10, 2022
1 parent f0760be commit bd1cddf
Show file tree
Hide file tree
Showing 50 changed files with 799 additions and 378 deletions.
4 changes: 2 additions & 2 deletions .electron-vendors.cache.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"chrome": "96",
"node": "16"
"chrome": "96",
"node": "16"
}
32 changes: 11 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"ignorePatterns": [
"packages/preload/exposedInMainWorld.d.ts",
"node_modules/**",
Expand All @@ -38,25 +36,17 @@
"vue/singleline-html-element-content-newline": ["off"],
"no-undef": "off",
/**
* Having a semicolon helps the optimizer interpret your code correctly.
* This avoids rare errors in optimized code.
*/
"semi": [
"error",
"always"
],
* Having a semicolon helps the optimizer interpret your code correctly.
* This avoids rare errors in optimized code.
*/
"semi": ["error", "always"],
/**
* This will make the history of changes in the hit a little cleaner
*/
"comma-dangle": [
"warn",
"always-multiline"
],
* This will make the history of changes in the hit a little cleaner
*/
"comma-dangle": ["warn", "always-multiline"],
/**
* Just for beauty
*/
"quotes": [
"warn", "single"
]
* Just for beauty
*/
"quotes": ["warn", "single"]
}
}
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: bug
assignees: cawa-93

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: cosmic

---

**Is your feature request related to a problem? Please describe.**
Expand Down
87 changes: 33 additions & 54 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,37 @@
{
"extends": [
"config:base",
":semanticCommits",
":automergeTypes",
":disableDependencyDashboard"
],
"labels": [
"dependencies"
],
"baseBranches": [
"main"
],
"bumpVersion": "patch",
"patch": {
"automerge": true
},
"minor": {
"automerge": true
},
"packageRules": [
{
"packageNames": [
"node",
"npm"
],
"enabled": false
"extends": ["config:base", ":semanticCommits", ":automergeTypes", ":disableDependencyDashboard"],
"labels": ["dependencies"],
"baseBranches": ["main"],
"bumpVersion": "patch",
"patch": {
"automerge": true
},
{
"depTypeList": [
"devDependencies"
],
"semanticCommitType": "build"
"minor": {
"automerge": true
},
{
"matchSourceUrlPrefixes": [
"https://github.com/searchfe/cosmic/"
],
"groupName": "Vite monorepo packages",
"automerge": false
},
{
"matchPackagePatterns": [
"^@typescript-eslint",
"^eslint"
],
"automerge": true,
"groupName": "eslint"
},
{
"matchPackageNames": [
"electron"
],
"separateMajorMinor": false
}
],
"rangeStrategy": "pin"
"packageRules": [
{
"packageNames": ["node", "npm"],
"enabled": false
},
{
"depTypeList": ["devDependencies"],
"semanticCommitType": "build"
},
{
"matchSourceUrlPrefixes": ["https://github.com/searchfe/cosmic/"],
"groupName": "Vite monorepo packages",
"automerge": false
},
{
"matchPackagePatterns": ["^@typescript-eslint", "^eslint"],
"automerge": true,
"groupName": "eslint"
},
{
"matchPackageNames": ["electron"],
"separateMajorMinor": false
}
],
"rangeStrategy": "pin"
}
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

5 changes: 5 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "@ecomfe/stylelint-config",
"ignoreFiles": ["**/dist/**", "**/node_modules/**"]

}
90 changes: 50 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,110 @@
# Cosmic
# Cosmic

[![GitHub issues by-label](https://img.shields.io/github/issues/searchfe/cosmic/help%20wanted?label=issues%20need%20help&logo=github)](https://github.com/searchfe/cosmic/issues?q=label%3A%22help+wanted%22+is%3Aopen+is%3Aissue)
[![Required Node.JS >= v16.13](https://img.shields.io/static/v1?label=node&message=%3E=16.13&logo=node.js&color)](https://nodejs.org/about/releases/)
[![Required npm >= v8.1](https://img.shields.io/static/v1?label=npm&message=%3E=8.1&logo=npm&color)](https://github.com/npm/cli/releases)


Cosmic is the free and open source ui design suite. It supports the entirety of the prototype, visual design, animation, component package and code release.


## Get started

### Continuous Integration
- The configured workflow will check the types for each push and PR.
- The configured workflow will check the code style for each push and PR.
- Unit tests are placed within each package and run separately.
- End-to-end tests are placed in the root [`tests`](tests) directory and use [playwright].

- The configured workflow will check the types for each push and PR.
- The configured workflow will check the code style for each push and PR.
- Unit tests are placed within each package and run separately.
- End-to-end tests are placed in the root [`tests`](tests) directory and use [playwright].

### Continuous delivery
- Each time you push changes to the `main` branch, the [`release`](.github/workflows/release.yml) workflow starts, which creates a release draft.
- The version is automatically set based on the current date in the format `yy.mm.dd-minutes`.
- Notes are automatically generated and added to the release draft.
- Code signing supported. See [`compile` job in the `release` workflow](.github/workflows/release.yml).
- **Auto-update is supported**. After the release is published, all client applications will download the new version and install updates silently.

- Each time you push changes to the `main` branch, the [`release`](.github/workflows/release.yml) workflow starts, which creates a release draft.
- The version is automatically set based on the current date in the format `yy.mm.dd-minutes`.
- Notes are automatically generated and added to the release draft.
- Code signing supported. See [`compile` job in the `release` workflow](.github/workflows/release.yml).
- **Auto-update is supported**. After the release is published, all client applications will download the new version and install updates silently.

### Project Structure

The structure of this template is very similar to the structure of a monorepo.

The entire source code of the program is divided into three modules (packages) that are each bundled independently:
- [`packages/app`](packages/app)
Electron [**main script**](https://www.electronjs.org/docs/tutorial/quick-start#create-the-main-script-file).
- [`packages/preload`](packages/preload)
Used in `BrowserWindow.webPreferences.preload`. See [Checklist: Security Recommendations](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content).
- [`packages/site`](packages/site)
Electron [**web page**](https://www.electronjs.org/docs/tutorial/quick-start#create-a-web-page).
- [`packages/core`](packages/core)
Core libs for cosmic.
- [`packages/module`](packages/module)
Modules for cosmic.

- [`packages/app`](packages/app)
Electron [**main script**](https://www.electronjs.org/docs/tutorial/quick-start#create-the-main-script-file).
- [`packages/preload`](packages/preload)
Used in `BrowserWindow.webPreferences.preload`. See [Checklist: Security Recommendations](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content).
- [`packages/site`](packages/site)
Electron [**web page**](https://www.electronjs.org/docs/tutorial/quick-start#create-a-web-page).
- [`packages/core`](packages/core)
Core libs for cosmic.
- [`packages/module`](packages/module)
Modules for cosmic.

### Compile App

The next step is to package and compile a ready to distribute Electron app for macOS, Windows and Linux with "auto update" support out of the box.

To do this using the [electron-builder]:
- Using the npm script `compile`: This script is configured to compile the application as quickly as possible. It is not ready for distribution, it is compiled only for the current platform and is used for debugging.
- Using GitHub Actions: The application is compiled for any platform and ready-to-distribute files are automatically added as a draft to the GitHub releases page.

- Using the npm script `compile`: This script is configured to compile the application as quickly as possible. It is not ready for distribution, it is compiled only for the current platform and is used for debugging.
- Using GitHub Actions: The application is compiled for any platform and ready-to-distribute files are automatically added as a draft to the GitHub releases page.

### Using external modules in renderer

According to [Electron's security guidelines](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content), Node.js integration is disabled for remote content. This means that **you cannot call any Node.js api in the `packages/site` directly**. This also means you can't import external modules during runtime in the renderer:

```js
// renderer.bundle.js
const {writeFile} = require('fs') // ReferenceError: require is not defined
writeFile()
const { writeFile } = require('fs'); // ReferenceError: require is not defined
writeFile();
```

To use external modules in Renderer you **must** describe the interface in the `packages/preload` where the Node.js api is allowed:

```ts
// packages/preload/src/index.ts
import type {BinaryLike} from 'crypto';
import {createHash} from 'crypto';
import type { BinaryLike } from 'crypto';
import { createHash } from 'crypto';

contextBridge.exposeInMainWorld('nodeCrypto', {
sha256sum(data: BinaryLike) {
const hash = createHash('sha256');
hash.update(data);
return hash.digest('hex');
},
sha256sum(data: BinaryLike) {
const hash = createHash('sha256');
hash.update(data);
return hash.digest('hex');
},
});
```

The [`dts-cb`](https://github.com/cawa-93/dts-for-context-bridge) utility will automatically generate an interface for TS:

```ts
// packages/preload/exposedInMainWorld.d.ts
// packages/preload/exposedInMainWorld.d.ts
interface Window {
readonly nodeCrypto: { sha256sum(data: import("crypto").BinaryLike): string; };
readonly nodeCrypto: { sha256sum(data: import('crypto').BinaryLike): string };
}
```

And now, you can safely use the registered method:

```ts
// packages/site/src/App.vue
window.nodeCrypto.sha256sum('data')
window.nodeCrypto.sha256sum('data');
```

[Read more about Security Considerations](https://www.electronjs.org/docs/tutorial/context-isolation#security-considerations).


### Modes and Environment Variables

All environment variables set as part of the `import.meta`, so you can access them as follows: `import.meta.env`.

If you are using TypeScript and want to get code completion you must add all the environment variables to the [`ImportMetaEnv` in `types/env.d.ts`](types/env.d.ts).

The mode option is used to specify the value of `import.meta.env.MODE` and the corresponding environment variables files that need to be loaded.

By default, there are two modes:
- `production` is used by default
- `development` is used by `npm run watch` script

- `production` is used by default
- `development` is used by `npm run watch` script

When running the build script, the environment variables are loaded from the following files in your project root:

Expand All @@ -111,6 +121,7 @@ To prevent accidentally leaking env variables to the client, only variables pref
DB_PASSWORD=foobar
VITE_SOME_KEY=123
```

Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your client source code, but `DB_PASSWORD` will not.

**Do not put any sensitive data in files managed by git, for instance database password or server address in intranet**
Expand All @@ -119,7 +130,6 @@ Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your

See [Contributing Guide](contributing.md).


[vite]: https://github.com/vitejs/vite/
[electron]: https://github.com/electron/electron
[electron-builder]: https://github.com/electron-userland/electron-builder
Expand Down
6 changes: 3 additions & 3 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Do not create issues about bumping dependencies unless a bug has been identified

Remember that we’re here to help, but not to make guesses about what you need help with:

- Whatever bug or issue you're experiencing, assume that it will not be as obvious to the maintainers as it is to you.
- Spell it out completely. Keep in mind that maintainers need to think about _all potential use cases_ of a library. It's important that you explain how you're using a library so that maintainers can make that connection and solve the issue.
- Whatever bug or issue you're experiencing, assume that it will not be as obvious to the maintainers as it is to you.
- Spell it out completely. Keep in mind that maintainers need to think about _all potential use cases_ of a library. It's important that you explain how you're using a library so that maintainers can make that connection and solve the issue.

_It can't be understated how frustrating and draining it can be to maintainers to have to ask clarifying questions on the most basic things, before it's even possible to start debugging. Please try to make the best use of everyone's time involved, including yourself, by providing this information up front._


## Repo Setup

The package manager used to install and link dependencies must be npm v7 or later.

1. Clone repo
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:preload": "vitest run -r packages/preload --passWithNoTests",
"test:site": "vitest run -r packages/site --passWithNoTests",
"watch": "node scripts/watch.js",
"format": "stylelint --fix packages/**/*.{css,less} && eslint '**/*.{js,ts,jsx,vue}' --fix",
"lint": "eslint . --ext js,ts,vue",
"typecheck:main": "tsc --noEmit -p packages/app/tsconfig.json",
"typecheck:preload": "tsc --noEmit -p packages/preload/tsconfig.json",
Expand All @@ -32,6 +33,7 @@
"commit": "git-cz"
},
"devDependencies": {
"@ecomfe/stylelint-config": "^1.1.2",
"@typescript-eslint/eslint-plugin": "5.10.1",
"@typescript-eslint/parser": "^5.19.0",
"@vitejs/plugin-vue": "2.1.0",
Expand All @@ -54,6 +56,7 @@
"playwright": "1.18.0",
"rimraf": "^3.0.2",
"simple-git-hooks": "2.7.0",
"stylelint": "^14.8.2",
"typescript": "4.5.5",
"unplugin-icons": "^0.13.4",
"unplugin-vue-components": "^0.17.21",
Expand Down
Loading

0 comments on commit bd1cddf

Please sign in to comment.