@tridion-sites/extensions-cli 0.3.2

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE.md +322 -0
  3. package/dist/addon/template/addonId.config.json.hbs +6 -0
  4. package/dist/addon/template/extension/.browserslistrc.hbs +5 -0
  5. package/dist/addon/template/extension/.editorconfig.hbs +10 -0
  6. package/dist/addon/template/extension/.eslintrc.json.hbs +30 -0
  7. package/dist/addon/template/extension/.gitignore.hbs +1 -0
  8. package/dist/addon/template/extension/.npmrc.hbs +1 -0
  9. package/dist/addon/template/extension/.prettierrc.hbs +10 -0
  10. package/dist/addon/template/extension/babel.config.js.hbs +8 -0
  11. package/dist/addon/template/extension/devServer.js.hbs +43 -0
  12. package/dist/addon/template/extension/package.json.hbs +64 -0
  13. package/dist/addon/template/extension/src/globals.ts.hbs +5 -0
  14. package/dist/addon/template/extension/src/index.css.hbs +0 -0
  15. package/dist/addon/template/extension/src/index.tsx.hbs +18 -0
  16. package/dist/addon/template/extension/tsconfig.json.hbs +28 -0
  17. package/dist/addon/template/extension/types/css.d.ts.hbs +4 -0
  18. package/dist/addon/template/extension/webpack.dev.config.js.hbs +94 -0
  19. package/dist/addon/template/extension/webpack.prod.config.js.hbs +85 -0
  20. package/dist/addonManifest-30c25a45.js +225 -0
  21. package/dist/cli.js +281 -0
  22. package/dist/extensionPoints/primaryNavigation/template/PageComponent/PageComponent.module.css.hbs +4 -0
  23. package/dist/extensionPoints/primaryNavigation/template/PageComponent/PageComponent.tsx.hbs +9 -0
  24. package/dist/extensionPoints/primaryNavigation/template/PageComponent/index.ts.hbs +1 -0
  25. package/dist/extensionPoints/primaryNavigation/template/extensionPoint.hbs +15 -0
  26. package/dist/index.d.ts +34 -0
  27. package/dist/index.js +83 -0
  28. package/dist/tsdoc-metadata.json +11 -0
  29. package/package.json +65 -0
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "{{extensionName}}",
3
+ "version": "1.0.0",
4
+ "description": "{{extensionDescription}}",
5
+ "author": "{{author}}",
6
+ "homepage": "https://www.rws.com",
7
+ "license": "Apache-2.0",
8
+ "type": "module",
9
+ "main": "../dist/{{extensionName}}/main.js",
10
+ "files": [
11
+ "../dist/{{extensionName}}/*"
12
+ ],
13
+ "private": true,
14
+ "scripts": {
15
+ "build": "webpack --config ./webpack.prod.config.js --progress",
16
+ "dev": "webpack serve --config ./webpack.dev.config.js --progress --env target={{sitesUrl}} manifest=../manifest.json config=../{{addonId}}.config.json",
17
+ "pack": "sites-extensions pack --manifest=../manifest.json --input=../dist --output=../",
18
+ "lint": "eslint . --fix && prettier --write \"src/**/*\""
19
+ },
20
+ "peerDependencies": {
21
+ "@tridion-sites/extensions": "{{extensionsApiVersion}}",
22
+ "@tridion-sites/models": "{{modelsVersion}}",
23
+ "@tridion-sites/open-api-client": "{{openApiClientVersion}}",
24
+ "react": "18.2.0",
25
+ "react-dom": "18.2.0",
26
+ "styled-components": "5.3.6",
27
+ "tinymce": "6.3.1"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/core": "7.20.12",
31
+ "@babel/plugin-transform-runtime": "7.19.6",
32
+ "@babel/preset-env": "7.20.2",
33
+ "@babel/preset-react": "7.18.6",
34
+ "@babel/preset-typescript": "7.18.6",
35
+ "@babel/runtime": "7.20.13",
36
+ "@tridion-sites/extensions-cli": "{{extensionsCliVersion}}",
37
+ "@types/react": "18.0.27",
38
+ "@types/react-dom": "18.0.10",
39
+ "@types/react-is": "17.0.3",
40
+ "@types/styled-components": "5.1.26",
41
+ "@typescript-eslint/eslint-plugin": "5.45.0",
42
+ "@typescript-eslint/parser": "5.49.0",
43
+ "autoprefixer": "10.4.13",
44
+ "babel-loader": "9.1.2",
45
+ "babel-plugin-styled-components": "2.0.7",
46
+ "css-loader": "6.7.3",
47
+ "cssnano": "5.1.14",
48
+ "eslint": "8.32.0",
49
+ "eslint-config-prettier": "8.6.0",
50
+ "eslint-formatter-pretty": "4.1.0",
51
+ "eslint-plugin-react": "7.32.1",
52
+ "eslint-plugin-react-hooks": "4.6.0",
53
+ "fork-ts-checker-webpack-plugin": "7.3.0",
54
+ "mini-css-extract-plugin": "2.7.2",
55
+ "postcss": "8.4.21",
56
+ "postcss-loader": "7.0.2",
57
+ "prettier": "2.8.3",
58
+ "tsconfig-paths-webpack-plugin": "4.0.0",
59
+ "typescript": "4.9.4",
60
+ "webpack": "5.75.0",
61
+ "webpack-cli": "5.0.1",
62
+ "webpack-dev-server": "4.11.1"
63
+ }
64
+ }
@@ -0,0 +1,5 @@
1
+ import { createExtensionGlobals } from '@tridion-sites/extensions';
2
+
3
+ const { initialize: initializeGlobals, t, getConfiguration } = createExtensionGlobals();
4
+
5
+ export { initializeGlobals, t, getConfiguration };
@@ -0,0 +1,18 @@
1
+ import './index.css';
2
+
3
+ import type { ExtensionModule, RuntimeInformation } from '@tridion-sites/extensions';
4
+
5
+ import packageJson from '../package.json';
6
+ import { initializeGlobals } from './globals';
7
+
8
+ const extensionModule: ExtensionModule = {
9
+ runtimeInfo: packageJson as RuntimeInformation,
10
+ initializeGlobals,
11
+ initialize: builder => {
12
+ /**
13
+ * This section is intended for initializing extensions.
14
+ */
15
+ },
16
+ };
17
+
18
+ export default extensionModule;
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "module": "es6",
5
+ "target": "ES6",
6
+ "lib": ["es6", "dom"],
7
+ "jsx": "react-jsx",
8
+ "moduleResolution": "node",
9
+ "isolatedModules": true,
10
+ "declaration": false,
11
+ "sourceMap": false,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "useDefineForClassFields": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "esModuleInterop": true,
16
+ "resolveJsonModule": true,
17
+ "noEmitOnError": true,
18
+ "noImplicitReturns": true,
19
+ "noImplicitThis": true,
20
+ "noImplicitAny": true,
21
+ "skipLibCheck": true,
22
+ "strict": true,
23
+ "allowJs": false,
24
+ "downlevelIteration": true
25
+ },
26
+
27
+ "include": ["./src/**/*.ts", "./src/**/*.tsx", "./types"]
28
+ }
@@ -0,0 +1,4 @@
1
+ declare module '*.css' {
2
+ const styles: { [className: string]: string };
3
+ export default styles;
4
+ }
@@ -0,0 +1,94 @@
1
+ import { resolve, dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import autoprefixer from 'autoprefixer';
4
+ import cssnano from 'cssnano';
5
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
6
+ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
7
+ import { extensionsRequestBasePath } from '@tridion-sites/extensions-cli';
8
+ import { getDevServerConfig } from './devServer.js';
9
+ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
10
+
11
+ /** @type { import('webpack').Configuration } */
12
+ export default env => ({
13
+ mode: 'development',
14
+ entry: './src/index.tsx',
15
+ output: {
16
+ library: {
17
+ type: 'system',
18
+ },
19
+ path: resolve(dirname(fileURLToPath(import.meta.url)), '../dist/{{extensionName}}'),
20
+ publicPath: `${extensionsRequestBasePath}/{{extensionName}}/dist/{{extensionName}}`,
21
+ clean: true,
22
+ },
23
+ devServer: getDevServerConfig({
24
+ targetUrl: env.target,
25
+ manifestPath: env.manifest,
26
+ addonConfigPath: env.config,
27
+ }),
28
+ devtool: 'eval-source-map',
29
+ externals: [
30
+ 'react',
31
+ 'react-dom',
32
+ 'styled-components',
33
+ 'tinymce',
34
+ '@tridion-sites/extensions',
35
+ '@tridion-sites/models',
36
+ '@tridion-sites/open-api-client',
37
+ ],
38
+ resolve: {
39
+ extensions: ['.tsx', '.ts', '.jsx', '.js', '.css'],
40
+ plugins: [new TsconfigPathsPlugin()],
41
+ },
42
+ module: {
43
+ rules: [
44
+ {
45
+ test: /\.tsx?$/,
46
+ exclude: /node_modules/,
47
+ use: [{ loader: 'babel-loader' }],
48
+ },
49
+ {
50
+ test: /\.css$/,
51
+ use: [
52
+ {
53
+ loader: MiniCssExtractPlugin.loader,
54
+ },
55
+ {
56
+ loader: 'css-loader',
57
+ options: {
58
+ modules: {
59
+ localIdentName: '[name]__[local]__[hash:base64]',
60
+ exportLocalsConvention: 'camelCaseOnly',
61
+ },
62
+ },
63
+ },
64
+ {
65
+ loader: 'postcss-loader',
66
+ options: {
67
+ postcssOptions: {
68
+ plugins: [
69
+ autoprefixer(),
70
+ cssnano({
71
+ safe: true,
72
+ autoprefixer: false,
73
+ }),
74
+ ],
75
+ },
76
+ },
77
+ },
78
+ ],
79
+ },
80
+ ],
81
+ },
82
+ plugins: [
83
+ new MiniCssExtractPlugin({ filename: '[name].css' }),
84
+
85
+ new ForkTsCheckerWebpackPlugin({
86
+ typescript: {
87
+ diagnosticOptions: {
88
+ semantic: true,
89
+ syntactic: true,
90
+ },
91
+ },
92
+ }),
93
+ ],
94
+ });
@@ -0,0 +1,85 @@
1
+ import { resolve, dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import autoprefixer from 'autoprefixer';
4
+ import cssnano from 'cssnano';
5
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
6
+ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
7
+ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
8
+
9
+ /** @type { import('webpack').Configuration } */
10
+ export default {
11
+ mode: 'production',
12
+ entry: './src/index.tsx',
13
+ output: {
14
+ library: {
15
+ type: 'system',
16
+ },
17
+ path: resolve(dirname(fileURLToPath(import.meta.url)), '../dist/{{extensionName}}'),
18
+ clean: true,
19
+ },
20
+ externals: [
21
+ 'react',
22
+ 'react-dom',
23
+ 'styled-components',
24
+ 'tinymce',
25
+ '@tridion-sites/extensions',
26
+ '@tridion-sites/models',
27
+ '@tridion-sites/open-api-client',
28
+ ],
29
+ resolve: {
30
+ extensions: ['.tsx', '.ts', '.jsx', '.js', '.css'],
31
+ plugins: [new TsconfigPathsPlugin()],
32
+ },
33
+ module: {
34
+ rules: [
35
+ {
36
+ test: /\.tsx?$/,
37
+ exclude: /node_modules/,
38
+ use: [{ loader: 'babel-loader' }],
39
+ },
40
+ {
41
+ test: /\.css$/,
42
+ use: [
43
+ {
44
+ loader: MiniCssExtractPlugin.loader,
45
+ },
46
+ {
47
+ loader: 'css-loader',
48
+ options: {
49
+ modules: {
50
+ localIdentName: '[name]__[local]__[hash:base64]',
51
+ exportLocalsConvention: 'camelCaseOnly',
52
+ },
53
+ },
54
+ },
55
+ {
56
+ loader: 'postcss-loader',
57
+ options: {
58
+ postcssOptions: {
59
+ plugins: [
60
+ autoprefixer(),
61
+ cssnano({
62
+ safe: true,
63
+ autoprefixer: false,
64
+ }),
65
+ ],
66
+ },
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ },
73
+ plugins: [
74
+ new MiniCssExtractPlugin({ filename: '[name].css' }),
75
+
76
+ new ForkTsCheckerWebpackPlugin({
77
+ typescript: {
78
+ diagnosticOptions: {
79
+ semantic: true,
80
+ syntactic: true,
81
+ },
82
+ },
83
+ }),
84
+ ],
85
+ };
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from 'node:path';
3
+ import { readFileSync, writeFileSync } from 'node:fs';
4
+
5
+ const readJsonFile = (path) => {
6
+ const file = readFileSync(path, { encoding: 'utf-8' });
7
+ return JSON.parse(file);
8
+ };
9
+ const writeJsonFile = (path, value) => {
10
+ const json = JSON.stringify(value, null, 4);
11
+ writeFileSync(path, json);
12
+ };
13
+
14
+ class AddonExtension {
15
+ constructor(name, type) {
16
+ Object.defineProperty(this, "name", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "type", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ this.name = name;
29
+ this.type = type;
30
+ }
31
+ }
32
+
33
+ const frontendExtensionType = 'ExperienceSpaceExtension';
34
+ class FrontendExtension extends AddonExtension {
35
+ constructor({ name, files, main }) {
36
+ super(name, frontendExtensionType);
37
+ Object.defineProperty(this, "main", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ Object.defineProperty(this, "files", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ this.main = main;
50
+ this.files = files;
51
+ }
52
+ }
53
+
54
+ class UnknownExtension extends AddonExtension {
55
+ constructor(name, type, extensionData) {
56
+ super(name, type);
57
+ Object.defineProperty(this, "extensionData", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ this.extensionData = extensionData;
64
+ }
65
+ }
66
+
67
+ class AddonManifest {
68
+ constructor({ id, author, description, name, version, requireConfiguration }) {
69
+ Object.defineProperty(this, "id", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ Object.defineProperty(this, "author", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: void 0
80
+ });
81
+ Object.defineProperty(this, "description", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: void 0
86
+ });
87
+ Object.defineProperty(this, "name", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ Object.defineProperty(this, "version", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
99
+ Object.defineProperty(this, "manifestVersion", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: void 0
104
+ });
105
+ Object.defineProperty(this, "requireConfiguration", {
106
+ enumerable: true,
107
+ configurable: true,
108
+ writable: true,
109
+ value: void 0
110
+ });
111
+ Object.defineProperty(this, "extensions", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: void 0
116
+ });
117
+ Object.defineProperty(this, "addFrontendExtension", {
118
+ enumerable: true,
119
+ configurable: true,
120
+ writable: true,
121
+ value: (name, fileUrls, mainFileUrl) => {
122
+ this.extensions.set(name, new FrontendExtension({
123
+ name,
124
+ main: mainFileUrl,
125
+ files: fileUrls,
126
+ }));
127
+ return this;
128
+ }
129
+ });
130
+ Object.defineProperty(this, "addUnknownExtension", {
131
+ enumerable: true,
132
+ configurable: true,
133
+ writable: true,
134
+ value: (name, type, extensionData) => {
135
+ this.extensions.set(name, new UnknownExtension(name, type, extensionData));
136
+ return this;
137
+ }
138
+ });
139
+ Object.defineProperty(this, "getFrontendExtensions", {
140
+ enumerable: true,
141
+ configurable: true,
142
+ writable: true,
143
+ value: () => {
144
+ const frontendExtensions = [];
145
+ this.extensions.forEach(extension => {
146
+ if (extension instanceof FrontendExtension) {
147
+ frontendExtensions.push(extension);
148
+ }
149
+ });
150
+ return frontendExtensions;
151
+ }
152
+ });
153
+ Object.defineProperty(this, "writeFile", {
154
+ enumerable: true,
155
+ configurable: true,
156
+ writable: true,
157
+ value: (path) => {
158
+ const extensionsJson = [];
159
+ this.extensions.forEach(extension => {
160
+ if (extension instanceof FrontendExtension) {
161
+ extensionsJson.push({
162
+ name: extension.name,
163
+ type: extension.type,
164
+ properties: {
165
+ main: extension.main,
166
+ files: extension.files,
167
+ },
168
+ });
169
+ }
170
+ else if (extension instanceof UnknownExtension) {
171
+ extensionsJson.push(extension.extensionData);
172
+ }
173
+ });
174
+ const manifestPath = resolve(path, 'manifest.json');
175
+ writeJsonFile(manifestPath, {
176
+ id: this.id,
177
+ name: this.name,
178
+ author: this.author,
179
+ description: this.description,
180
+ manifestVersion: this.manifestVersion,
181
+ requireConfiguration: this.requireConfiguration,
182
+ version: this.version,
183
+ extensions: extensionsJson,
184
+ });
185
+ }
186
+ });
187
+ this.id = id;
188
+ this.author = author || '';
189
+ this.description = description;
190
+ this.name = name;
191
+ this.manifestVersion = '1.0.0';
192
+ this.requireConfiguration = requireConfiguration || 'optional';
193
+ this.version = version;
194
+ this.extensions = new Map();
195
+ }
196
+ }
197
+ Object.defineProperty(AddonManifest, "fromFile", {
198
+ enumerable: true,
199
+ configurable: true,
200
+ writable: true,
201
+ value: (manifestPath) => {
202
+ const manifestFile = readJsonFile(manifestPath);
203
+ const manifest = new AddonManifest({
204
+ id: manifestFile.id,
205
+ author: manifestFile.author,
206
+ description: manifestFile.description,
207
+ name: manifestFile.name,
208
+ version: manifestFile.version,
209
+ requireConfiguration: manifestFile.requireConfiguration,
210
+ });
211
+ for (const extension of manifestFile.extensions) {
212
+ if (extension.type === frontendExtensionType) {
213
+ const main = extension.properties.main;
214
+ const files = extension.properties.files;
215
+ manifest.addFrontendExtension(extension.name, files, main);
216
+ }
217
+ else {
218
+ manifest.addUnknownExtension(extension.name, extension.type, extension);
219
+ }
220
+ }
221
+ return manifest;
222
+ }
223
+ });
224
+
225
+ export { AddonManifest as A, readJsonFile as r, writeJsonFile as w };