Skip to content

Commit f326574

Browse files
authored
feat: inital move cli to mono-repo (#6126)
* feat: inital move cli to mono-repo * feat: linting and formatting on cli package * ci: remove force command * package: terser-webpack-plugin * config: ignore local from eslint and prettier * ci: add seperate runners for each package in monorepo * fix: point to local grapesjs location vs installed for scripts * package: move old babel deps back * config: remove stats.json from eslint * package: bump and pin all build deps for cli * test: fix ts errors in cli and global test script
1 parent d24b8f0 commit f326574

32 files changed

+2210
-136
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ module.exports = {
5252
'max-len': ['error', { code: 300 }],
5353
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }],
5454
},
55-
ignorePatterns: ['*/docs/api/*', 'dist'],
55+
ignorePatterns: ['*/docs/api/*', 'dist', 'packages/cli/src/template/**/*.*', '*/locale/*', 'stats.json'],
5656
};

.github/workflows/quality.yml

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ jobs:
1717
run: pnpm lint
1818
- name: Format Check
1919
run: pnpm format:check
20-
- name: Test
21-
run: pnpm test
2220
- name: Docs
2321
run: pnpm docs:api

.github/workflows/test.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: GrapesJS Tests
2+
on:
3+
push:
4+
branches: [dev]
5+
pull_request:
6+
branches: [dev]
7+
8+
jobs:
9+
test-core:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: ./.github/actions/setup-project
14+
- name: Core Tests
15+
run: pnpm test
16+
working-directory: ./packages/core
17+
test-cli:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: ./.github/actions/setup-project
22+
- name: CLI Tests
23+
run: pnpm test
24+
working-directory: ./packages/cli

.prettierignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
docs/**/*.md
22
dist/
3-
pnpm-lock.yaml
3+
pnpm-lock.yaml
4+
packages/cli/src/template/**/*.*
5+
**/locale/**
6+
stats.json

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
"packageManager": "[email protected]",
55
"scripts": {
66
"start": "pnpm --filter grapesjs start",
7-
"test": "pnpm --filter grapesjs test",
7+
"test": "pnpm -r run test",
88
"docs": "pnpm --filter @grapesjs/docs docs",
99
"docs:api": "pnpm --filter @grapesjs/docs docs:api",
1010
"lint": "eslint .",
1111
"build": "pnpm --filter \"!@grapesjs/docs\" build",
1212
"ts:check": "pnpm --filter grapesjs ts:check",
1313
"clean": "find . -type d \\( -name \"node_modules\" -o -name \"build\" -o -name \"dist\" \\) -exec rm -rf {} + && rm ./pnpm-lock.yaml",
14-
"format": "prettier . --write",
15-
"format:check": "prettier . --check"
14+
"format": "prettier . --write --ignore-path .prettierignore",
15+
"format:check": "prettier . --check --ignore-path .prettierignore"
1616
},
1717
"devDependencies": {
1818
"@babel/cli": "7.24.8",
1919
"@babel/core": "7.25.2",
2020
"@babel/preset-env": "7.25.4",
2121
"@babel/preset-typescript": "7.24.7",
22+
"@babel/runtime": "7.25.6",
23+
"babel-loader": "9.1.3",
2224
"@jest/globals": "29.7.0",
2325
"@types/jest": "29.5.12",
2426
"@types/node": "22.4.1",

packages/cli/README.md

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# GrapesJS CLI
2+
3+
[![npm](https://img.shields.io/npm/v/grapesjs-cli.svg)](https://www.npmjs.com/package/grapesjs-cli)
4+
5+
![grapesjs-cli](https://user-images.githubusercontent.com/11614725/67523496-0ed41300-f6af-11e9-9850-7175355f2946.jpg)
6+
7+
A simple CLI library for helping in GrapesJS plugin development.
8+
9+
The goal of this package is to avoid the hassle of setting up all the dependencies and configurations for the plugin development by centralizing and speeding up the necessary steps during the process.
10+
11+
- Fast project scaffolding
12+
- No need to touch Babel and Webpack configurations
13+
14+
## Plugin from 0 to 100
15+
16+
Create a production-ready plugin in a few simple steps.
17+
18+
- Create a folder for your plugin and init some preliminary steps
19+
20+
```sh
21+
mkdir grapesjs-my-plugin
22+
cd grapesjs-my-plugin
23+
npm init -y
24+
git init
25+
```
26+
27+
- Install the package
28+
29+
```sh
30+
npm i -D grapesjs-cli
31+
```
32+
33+
- Init your plugin project by following few steps
34+
35+
```sh
36+
npx grapesjs-cli init
37+
```
38+
39+
You can also skip all the questions with `-y` option or pass all the answers via options (to see all available options run `npx grapesjs-cli init --help`)
40+
41+
```sh
42+
npx grapesjs-cli init -y --user=YOUR-GITHUB-USERNAME
43+
```
44+
45+
- The command will scaffold the `src` directory and a bunch of other files inside your project. The `src/index.js` will be the entry point of your plugin. Before starting developing your plugin run the development server and open the printed URL (eg. the default is http://localhost:8080)
46+
47+
```sh
48+
npx grapesjs-cli serve
49+
```
50+
51+
If you need a custom port use the `-p` option
52+
53+
```sh
54+
npx grapesjs-cli serve -p 8081
55+
```
56+
57+
Under the hood we use `webpack-dev-server` and you can pass its option via CLI in this way
58+
59+
```sh
60+
npx grapesjs-cli serve --devServer='{"https": true}'
61+
```
62+
63+
- Once the development is finished you can build your plugin and generate the minified file ready for production
64+
65+
```sh
66+
npx grapesjs-cli build
67+
```
68+
69+
- Before publishing your package remember to complete your README.md file with all the available options, components, blocks and so on.
70+
For a better user engagement create a simple live demo by using services like [JSFiddle](https://jsfiddle.net) [CodeSandbox](https://codesandbox.io) [CodePen](https://codepen.io) and link it in your README. To help you in this process we'll print all the necessary HTML/CSS/JS in your README, so it will be just a matter of copy-pasting on some of those services.
71+
72+
## Customization
73+
74+
### Customize webpack config
75+
76+
If you need to customize the webpack configuration, you can create `webpack.config.js` file in the root dir of your project and export a function, which should return the new configuration object. Check the example below.
77+
78+
```js
79+
// YOUR-PROJECT-DIR/webpack.config.js
80+
81+
// config is the default configuration
82+
export default ({ config }) => {
83+
// This is how you can distinguish the `build` command from the `serve`
84+
const isBuild = config.mode === 'production';
85+
86+
return {
87+
...config,
88+
module: {
89+
rules: [
90+
{
91+
/* extra rule */
92+
},
93+
...config.module.rules,
94+
],
95+
},
96+
};
97+
};
98+
```
99+
100+
## Generic CLI usage
101+
102+
Show all available commands
103+
104+
```sh
105+
grapesjs-cli
106+
```
107+
108+
Show available options for a command
109+
110+
```sh
111+
grapesjs-cli COMMAND --help
112+
```
113+
114+
Run the command
115+
116+
```sh
117+
grapesjs-cli COMMAND --OPT1 --OPT2=VALUE
118+
```
119+
120+
## License
121+
122+
MIT

packages/cli/babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
};

packages/cli/index.html

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title><%= title %></title>
6+
<link
7+
href="<%= pathGjsCss ? pathGjsCss : 'https://unpkg.com/grapesjs@' + gjsVersion + '/dist/css/grapes.min.css' %>"
8+
rel="stylesheet"
9+
/>
10+
<script src="<%= pathGjs ? pathGjs : 'https://unpkg.com/grapesjs@' + gjsVersion %>"></script>
11+
<style>
12+
body,
13+
html {
14+
height: 100%;
15+
margin: 0;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<div id="gjs" style="height: 0px; overflow: hidden">
21+
<div style="margin: 100px 100px 25px; padding: 25px; font: caption">
22+
This is a demo content generated from <b>GrapesJS CLI</b>. For the development, you should create a _index.html
23+
template file (might be a copy of this one) and on the next server start the new file will be served, and it
24+
will be ignored by git.
25+
</div>
26+
</div>
27+
28+
<script type="text/javascript">
29+
window.onload = () => {
30+
window.editor = grapesjs.init({
31+
height: '100%',
32+
container: '#gjs',
33+
showOffsets: 1,
34+
noticeOnUnload: 0,
35+
storageManager: false,
36+
fromElement: true,
37+
plugins: ['<%= name %>'],
38+
});
39+
};
40+
</script>
41+
</body>
42+
</html>

packages/cli/jest.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Config } from 'jest';
2+
3+
const config: Config = {
4+
testEnvironment: 'node',
5+
verbose: true,
6+
modulePaths: ['<rootDir>/src'],
7+
testMatch: ['<rootDir>/test/**/*.(t|j)s'],
8+
};
9+
10+
export default config;

packages/cli/package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "grapesjs-cli",
3+
"version": "4.1.3",
4+
"description": "GrapesJS CLI tool for the plugin development",
5+
"bin": {
6+
"grapesjs-cli": "dist/cli.js"
7+
},
8+
"files": [
9+
"dist"
10+
],
11+
"scripts": {
12+
"build": "BUILD_MODE=production webpack --config ./webpack.cli.ts",
13+
"build:watch": "webpack --config ./webpack.cli.ts --watch",
14+
"lint": "eslint src",
15+
"patch": "npm version patch -m 'Bump v%s'",
16+
"test": "jest"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/GrapesJS/grapesjs.git"
21+
},
22+
"keywords": [
23+
"grapesjs",
24+
"plugin",
25+
"dev",
26+
"cli"
27+
],
28+
"author": "Artur Arseniev",
29+
"license": "BSD-3-Clause",
30+
"dependencies": {
31+
"@babel/core": "7.25.2",
32+
"@babel/plugin-transform-runtime": "7.25.4",
33+
"@babel/preset-env": "7.25.4",
34+
"@babel/runtime": "7.25.6",
35+
"babel-loader": "9.1.3",
36+
"chalk": "^4.1.2",
37+
"core-js": "3.38.1",
38+
"dts-bundle-generator": "^8.0.1",
39+
"html-webpack-plugin": "5.6.0",
40+
"inquirer": "^8.2.5",
41+
"listr": "^0.14.3",
42+
"lodash.template": "^4.5.0",
43+
"rimraf": "^4.1.2",
44+
"spdx-license-list": "^6.6.0",
45+
"terser-webpack-plugin": "^5.3.10",
46+
"webpack": "5.94.0",
47+
"webpack-cli": "5.1.4",
48+
"webpack-dev-server": "5.1.0",
49+
"yargs": "^17.6.2"
50+
},
51+
"devDependencies": {
52+
"@types/webpack-node-externals": "^3.0.0",
53+
"copy-webpack-plugin": "^11.0.0",
54+
"fork-ts-checker-webpack-plugin": "^8.0.0",
55+
"webpack-node-externals": "^3.0.0"
56+
}
57+
}

packages/cli/src/banner.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
  ______ _______ ________ ____
2+
  / ____/________ _____ ___ _____ / / ___/ / ____/ / / _/
3+
 / / __/ ___/ __ `/ __ \/ _ \/ ___/_ / /\__ \______/ / / / / /
4+
/ /_/ / / / /_/ / /_/ / __(__ ) /_/ /___/ /_____/ /___/ /____/ /
5+
\____/_/ \__,_/ .___/\___/____/\____//____/ \____/_____/___/
6+
  /_/

0 commit comments

Comments
 (0)