@tridion-sites/extensions-cli 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -7
- package/dist/addon/template/extension/.eslintrc.json.hbs +11 -2
- package/dist/addon/template/extension/package.json.hbs +2 -0
- package/dist/addon/template/extension/webpack.dev.config.js.hbs +1 -1
- package/dist/addon/template/extension/webpack.prod.config.js.hbs +1 -1
- package/dist/cli.js +1 -1
- package/package.json +2 -2
- /package/dist/addon/template/extension/src/{index.tsx.hbs → index.ts.hbs} +0 -0
package/README.md
CHANGED
|
@@ -1,16 +1,124 @@
|
|
|
1
1
|
# Tridion Sites Extensions CLI
|
|
2
2
|
|
|
3
|
-
Command-line interface to create, develop, build and package
|
|
4
|
-
|
|
5
|
-
## Features
|
|
3
|
+
Command-line interface to create, develop, build and package addons for Tridion Sites
|
|
6
4
|
|
|
7
5
|
## Creating a new addon
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
$ npx @tridion-sites/extensions-cli create
|
|
8
|
+
$ npx @tridion-sites/extensions-cli@latest create
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
_💡 **Tip:** Using `@latest` will ensure that the latest version of `@tridion-sites/extensions-cli` is used. See [here](https://github.com/npm/cli/issues/4108) for details._
|
|
12
|
+
|
|
13
|
+
The CLI will then provide a series of prompts, including the ID of the addon, the name of the frontend extension, and the URL for a compatible Tridion Sites installation. It will also automatically install all required dependencies.
|
|
14
|
+
|
|
15
|
+
## Addon structure
|
|
16
|
+
|
|
17
|
+
After completing the prompts, CLI is going to create the following folder structure:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
<addon_id>/
|
|
21
|
+
<extension_name>/
|
|
22
|
+
...
|
|
23
|
+
manifest.json
|
|
24
|
+
<addon_id>.config.json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This structure allows you to have multiple extensions developed and packages together into a single addon. For example, you can have a backend extension that retrieves data from an external service and a frontend extension that defines how to present this data.
|
|
28
|
+
|
|
29
|
+
_💡 **Tip:** For frontend-only addons you don't have to split functionality into separate projects as it is possible to define multiple frontend extensions in a single project. For more information see [examples](https://github.com/RWS/tridion-sites-extensions-examples)_
|
|
30
|
+
|
|
31
|
+
The entry point for any addon is `manifest.json`. It contains all metadata information about the addon as well as about extensions included in it. You can find more information [`here`](https://docs.rws.com/986894/707998/tridion-sites-9-6-main-documentation/basic-structure-of-the-add-on-manifest-file)
|
|
32
|
+
|
|
33
|
+
Optional config file is generated for every addon to simplify adding configuration options in the future.
|
|
34
|
+
|
|
35
|
+
_💡 **Tip:** As the config file is optional by default, you can skip it when you deploy an addon package._
|
|
36
|
+
|
|
37
|
+
CLI also generates the folder structure for a frontend extension in a folder with the provided `<extension_name>`. The next section describes what is included in a frontend extension by default.
|
|
38
|
+
|
|
39
|
+
## Frontend extension structure
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
<extension_name>/
|
|
43
|
+
src/
|
|
44
|
+
globals.ts
|
|
45
|
+
index.ts
|
|
46
|
+
.browserslistrc
|
|
47
|
+
.editorconfig
|
|
48
|
+
.eslintrc.json
|
|
49
|
+
.gitignore
|
|
50
|
+
.prettierrc
|
|
51
|
+
babel.config.js
|
|
52
|
+
debServer.js
|
|
53
|
+
package.json
|
|
54
|
+
tsconfig.json
|
|
55
|
+
webpack.dev.config.js
|
|
56
|
+
webpack.prod.config.js
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| File | Description |
|
|
60
|
+
| :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
61
|
+
| `src/globals.ts` | Provides access to global functionality: addon configuration, translations etc |
|
|
62
|
+
| `src/index.ts` | Entry point for the extension. Defines extension module |
|
|
63
|
+
| `.browserslistrc` | Specifies which browsers should be supported by the extension. Used by [Babel](https://babeljs.io/docs/babel-preset-env#browserslist-integration) |
|
|
64
|
+
| `.editorconfig` | Defines editor configuration that is supported by most IDEs. [More info](https://editorconfig.org/) |
|
|
65
|
+
| `.eslintrc.json` | [ESLint](https://eslint.org/) rules that address common code problems. Out of the box we provide rules for TypeScript, React hooks and imports |
|
|
66
|
+
| `.gitignore` | Allows to ignore folders and files when making Git commits so that they won't be pushed to the remote repository. [More info](https://git-scm.com/docs/gitignore) |
|
|
67
|
+
| `.prettierrc` | Ensures consistent code style in the extension. Supported by most IDEs. More info about [Prettier](https://prettier.io/) |
|
|
68
|
+
| `babel.config.js` | By default, the project is setup to use [Babel](https://babeljs.io/) for TypeScript compilation |
|
|
69
|
+
| `devServer.js` | Development server allows to develop extensions locally without deploying them to a remote environment |
|
|
70
|
+
| `package.json` | Manifest file for the frontend extension package. [More info](https://docs.npmjs.com/about-packages-and-modules#about-packages) |
|
|
71
|
+
| `tsconfig.json` | Configuration used by TypeScript compiler. [More info](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) |
|
|
72
|
+
| `webpack.dev.config.js` | Development configuration for the [Webpack bundler](https://webpack.js.org/) |
|
|
73
|
+
| `webpack.prod.config.js` | Production configuration for the [Webpack bundler](https://webpack.js.org/) |
|
|
74
|
+
|
|
75
|
+
All files or dependencies can be adjusted for the needs of a specific extension project. For example, adding a [third-party component library](https://github.com/RWS/tridion-sites-extensions-examples/blob/main/activities-explorer/work-items-column-addon/work-items-column/package.json#L29) or [using CSS Modules](https://github.com/RWS/tridion-sites-extensions-examples/tree/main/primary-navigation/async-page-addon/async-page)
|
|
76
|
+
|
|
77
|
+
**Important note:** Do not update versions of existing packages in peerDependencies of `package.json`. These libraries are provided at runtime and a version mismatch might prevent your extension from running!
|
|
78
|
+
|
|
79
|
+
## Developing a frontend extension
|
|
80
|
+
|
|
81
|
+
Frontend extensions are developed using [`React`](https://react.dev/) & [`TypeScript`](https://www.typescriptlang.org/docs/handbook/intro.html) and make use of the `@tridion-sites/extensions` API.
|
|
82
|
+
|
|
83
|
+
First, let's switch into the extension folder
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
$ cd ./<extension-name>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
_💡 **Tip:** It is recommended to open your IDE in the extension directory so the root point is the extension itself._
|
|
90
|
+
|
|
91
|
+
As dependencies are installed automatically when you generate a new addon, you don't have to do any additional setup.
|
|
92
|
+
|
|
93
|
+
In order to add code for your extension, navigate to `src/index.ts` and update `initialize` method of the extension module.
|
|
94
|
+
For example:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// Don't forget to use constants for build-in actions.
|
|
98
|
+
import { activitiesExplorerActionId } from '@tridion-sites/extensions';
|
|
99
|
+
|
|
100
|
+
const extensionModule: ExtensionModule = {
|
|
101
|
+
runtimeInfo: packageJson as RuntimeInformation,
|
|
102
|
+
initializeGlobals,
|
|
103
|
+
initialize: builder => {
|
|
104
|
+
// This is going to remove `Refresh` action from the context menu of Content Explorer Table
|
|
105
|
+
builder.contentExplorer.table.contextMenu.removeAction(activitiesExplorerActionId.refresh);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Now let's run the extension
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
$ npm run dev
|
|
11
114
|
```
|
|
12
115
|
|
|
13
|
-
|
|
116
|
+
This is going to start a development server on `localhost:3000` by default and show your extension on the `target` environment that you provided while creating the addon.
|
|
117
|
+
|
|
118
|
+
_**Important note:** When making changes that might result in changes to the dist package (adding or removing files) make sure the files array in the `manifest.json` is updated._
|
|
119
|
+
|
|
120
|
+
## Packaging an addon
|
|
121
|
+
|
|
122
|
+
When the extension is ready, first run `npm run build`. This command outputs into `/dist` folder in the addon folder (one level above the extension folder). In order to simplify the packing procedure every frontend extension outputs results into the same `/dist` folder.
|
|
14
123
|
|
|
15
|
-
|
|
16
|
-
http://developers.rws.com/tridion-sites-extensions-api-docs/open-api-client.html
|
|
124
|
+
After all extensions are built, run `npm run pack` inside any extension folder to package the addon for use with Tridion Sites.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"plugin:react-hooks/recommended",
|
|
14
14
|
"prettier"
|
|
15
15
|
],
|
|
16
|
-
"plugins": ["react", "
|
|
16
|
+
"plugins": ["@typescript-eslint", "react", "simple-import-sort", "unused-imports"],
|
|
17
17
|
"env": {
|
|
18
18
|
"es6": true,
|
|
19
19
|
"browser": true
|
|
@@ -24,7 +24,16 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"rules": {
|
|
27
|
+
"@typescript-eslint/consistent-type-imports": ["warn"],
|
|
27
28
|
"@typescript-eslint/no-unused-vars": "off",
|
|
28
|
-
"import/no-default-export": "off"
|
|
29
|
+
"import/no-default-export": "off",
|
|
30
|
+
"simple-import-sort/imports": [
|
|
31
|
+
"error",
|
|
32
|
+
{
|
|
33
|
+
"groups": [["^\\u0000"], ["^@?\\w"], ["^@(.*|$)"], ["^[^.]"], ["^\\."]]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"unused-imports/no-unused-imports": "error",
|
|
37
|
+
"unused-imports/no-unused-vars": "off"
|
|
29
38
|
}
|
|
30
39
|
}
|
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
"eslint-formatter-pretty": "5.0.0",
|
|
51
51
|
"eslint-plugin-react": "7.32.2",
|
|
52
52
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
53
|
+
"eslint-plugin-simple-import-sort": "9.0.0",
|
|
54
|
+
"eslint-plugin-unused-imports": "2.0.0",
|
|
53
55
|
"fork-ts-checker-webpack-plugin": "8.0.0",
|
|
54
56
|
"prettier": "2.8.8",
|
|
55
57
|
"react": "18.2.0",
|
|
@@ -8,7 +8,7 @@ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
|
|
8
8
|
/** @type { import('webpack').Configuration } */
|
|
9
9
|
export default env => ({
|
|
10
10
|
mode: 'development',
|
|
11
|
-
entry: './src/index.
|
|
11
|
+
entry: './src/index.ts',
|
|
12
12
|
output: {
|
|
13
13
|
library: {
|
|
14
14
|
type: 'system',
|
package/dist/cli.js
CHANGED
|
@@ -76,7 +76,7 @@ const copyTemplate = ({ addonId, addonRootFolderPath, author, extensionDescripti
|
|
|
76
76
|
'devServer.js',
|
|
77
77
|
'tsconfig.json',
|
|
78
78
|
'src/globals.ts',
|
|
79
|
-
'src/index.
|
|
79
|
+
'src/index.ts',
|
|
80
80
|
].forEach(fileName => {
|
|
81
81
|
createFileFromTemplate(resolve(templatePath, `extension/${fileName}.hbs`), resolve(extensionRootFolderPath, fileName));
|
|
82
82
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tridion-sites/extensions-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "CLI to create, develop, build and package extensions for Tridion Sites",
|
|
5
5
|
"author": "RWS",
|
|
6
6
|
"homepage": "https://www.rws.com",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "sites-extensions"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tridion-sites/extensions": "1.0.
|
|
27
|
+
"@tridion-sites/extensions": "1.0.2",
|
|
28
28
|
"@tridion-sites/models": "1.0.0",
|
|
29
29
|
"@tridion-sites/open-api-client": "2.0.0",
|
|
30
30
|
"archiver": "5.3.1",
|
|
File without changes
|