@jahia/create-module 0.0.1

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 (58) hide show
  1. package/.eslintrc.cjs +28 -0
  2. package/.github/dependabot.yml +15 -0
  3. package/.github/workflows/lint.yml +35 -0
  4. package/.github/workflows/publish-release.yml +22 -0
  5. package/LICENSE +21 -0
  6. package/README.md +10 -0
  7. package/babel.config.cjs.disabled +3 -0
  8. package/handlebars/README.md +11 -0
  9. package/handlebars/components/MODULE_NAMESPACE/hello/hello.cnd +6 -0
  10. package/handlebars/components/MODULE_NAMESPACE/hello/hello.default.hbs +1 -0
  11. package/handlebars/components/MODULE_NAMESPACE/hello/hello.icon.png +0 -0
  12. package/handlebars/components/jnt/page/page.home.hbs +18 -0
  13. package/handlebars/components/jnt/page/page.home.png +0 -0
  14. package/handlebars/components/jnt/page/page.home.properties +2 -0
  15. package/handlebars/definitions.cnd +8 -0
  16. package/handlebars/dotenv +4 -0
  17. package/handlebars/doteslintrc.cjs +29 -0
  18. package/handlebars/dotgitignore +15 -0
  19. package/handlebars/dotnpmignore +4 -0
  20. package/handlebars/import.xml +8 -0
  21. package/handlebars/locales/de.json +3 -0
  22. package/handlebars/locales/en.json +3 -0
  23. package/handlebars/locales/fr.json +3 -0
  24. package/handlebars/package.json +41 -0
  25. package/handlebars/resources/MODULE_NAME.properties +2 -0
  26. package/handlebars/resources/MODULE_NAME_fr.properties +2 -0
  27. package/handlebars/settings/README.txt +9 -0
  28. package/handlebars/src/index.js +0 -0
  29. package/handlebars/webpack.config.js +49 -0
  30. package/handlebars/yarn.lock +0 -0
  31. package/index.js +164 -0
  32. package/jsx/README.md +11 -0
  33. package/jsx/css/styles.css +8 -0
  34. package/jsx/definitions.cnd +11 -0
  35. package/jsx/dotenv +4 -0
  36. package/jsx/doteslintrc.cjs +29 -0
  37. package/jsx/dotgitignore +15 -0
  38. package/jsx/dotnpmignore +10 -0
  39. package/jsx/import.xml +9 -0
  40. package/jsx/locales/de.json +4 -0
  41. package/jsx/locales/en.json +4 -0
  42. package/jsx/locales/fr.json +4 -0
  43. package/jsx/package.json +56 -0
  44. package/jsx/resources/MODULE_NAME.properties +3 -0
  45. package/jsx/resources/MODULE_NAME_fr.properties +3 -0
  46. package/jsx/settings/README.txt +9 -0
  47. package/jsx/src/client/index.jsx +5 -0
  48. package/jsx/src/server/components/index.js +1 -0
  49. package/jsx/src/server/index.js +6 -0
  50. package/jsx/src/server/templates/index.js +1 -0
  51. package/jsx/src/server/templates/page/PageHome.jsx +24 -0
  52. package/jsx/src/server/templates/page/index.js +1 -0
  53. package/jsx/src/server/views/hello/HelloDefault.jsx +18 -0
  54. package/jsx/src/server/views/hello/index.js +1 -0
  55. package/jsx/src/server/views/index.js +1 -0
  56. package/jsx/webpack.config.js +162 -0
  57. package/jsx/yarn.lock +0 -0
  58. package/package.json +47 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true
5
+ },
6
+ extends: '@jahia',
7
+ overrides: [
8
+ {
9
+ env: {
10
+ node: true
11
+ },
12
+ files: [
13
+ '.eslintrc.{js,cjs}'
14
+ ],
15
+ parserOptions: {
16
+ sourceType: 'script'
17
+ }
18
+ }
19
+ ],
20
+ parserOptions: {
21
+ requireConfigFile: false,
22
+ ecmaVersion: 'latest',
23
+ sourceType: 'module'
24
+ },
25
+ ignorePatterns: ['dist'],
26
+ rules: {
27
+ }
28
+ };
@@ -0,0 +1,15 @@
1
+ # See: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
2
+ version: 2
3
+ updates:
4
+ - package-ecosystem: "npm"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "daily"
8
+ allow:
9
+ - dependency-type: "production"
10
+ - package-ecosystem: "maven"
11
+ directory: "/"
12
+ schedule:
13
+ interval: "daily"
14
+ allow:
15
+ - dependency-type: "production"
@@ -0,0 +1,35 @@
1
+ name: Lint
2
+ # This workflow is triggered on pushes to the repository.
3
+ on:
4
+ push:
5
+ branches:
6
+ - '**'
7
+
8
+ jobs:
9
+ lint:
10
+ name: Linting
11
+ runs-on: ubuntu-latest
12
+
13
+ container:
14
+ image: node:lts-alpine
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - run: yarn set version stable
19
+ - run: yarn
20
+ - run: yarn run lint
21
+
22
+ build:
23
+ needs: [lint]
24
+ name: Build
25
+ runs-on: ubuntu-latest
26
+ # if: github.event_name == 'push' && github.ref == 'refs/heads/master'
27
+
28
+ container:
29
+ image: node:lts-alpine
30
+
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - run: yarn set version stable
34
+ - run: yarn
35
+ - run: yarn jahia-pack
@@ -0,0 +1,22 @@
1
+ name: Publish Release to Registry
2
+ on:
3
+ release:
4
+ types: [published]
5
+
6
+ jobs:
7
+ npm_publish:
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@master
12
+ - uses: actions/setup-node@v2
13
+ with:
14
+ node-version: 'lts/*'
15
+ - run: corepack enable
16
+ - run: yarn set version stable
17
+ - run: yarn
18
+ - run: whoami && node -v && ls -lah
19
+ - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPMJS_PUBLISH_TOKEN }}" > .npmrc
20
+ - run: npm --no-git-tag-version version ${{ github.event.release.tag_name }}
21
+ - run: ls -lah ./
22
+ - run: npm publish --access public
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Jahia Forge - Code Repository
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # NPM Module template create-module project
2
+
3
+ This project provides an NPM/NPX starter project template to quickly get up and running to create Jahia NPM modules
4
+
5
+ ## Usage
6
+
7
+ npx @jahia/create-module@latest my-module-name my-module-type
8
+
9
+ where `my-module-name` can be anything you want to call your project
10
+ and `my-module-type`is jsx or handlebars
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ['@babel/preset-env', '@babel/preset-react']
3
+ };
@@ -0,0 +1,11 @@
1
+ # $$MODULE_NAME$$
2
+
3
+ A simple Jahia NPM module created using the NPM module starter project template
4
+
5
+ ## Configuration
6
+
7
+ If you don't use default configuration for the Docker container name or for Jahia deployments, please modify the provided `.env` file
8
+
9
+ ## Documentation
10
+
11
+ You can find the documentation on how to use this module on the [Jahia Academy](https://academy.jahia.com/get-started/developers/templating) templating tutorial.
@@ -0,0 +1,6 @@
1
+ <jnt = 'http://www.jahia.org/jahia/nt/1.0'>
2
+ <jmix = 'http://www.jahia.org/jahia/mix/1.0'>
3
+ <$$MODULE_NAMESPACE$$ = 'http://www.acme.org/$$MODULE_NAME$$/nt/1.0'>
4
+
5
+ [$$MODULE_NAMESPACE$$:hello] > jnt:content, jmix:droppableContent
6
+ - textHello (string) = 'Hello world !' i18n
@@ -0,0 +1 @@
1
+ <h1>{{currentContent.properties.textHello}}</h1>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="no-js">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <title>Home Template</title>
9
+ </head>
10
+
11
+ <body>
12
+ <h1>Home Template</h1>
13
+ <main>
14
+ {{jArea name="pagecontent"}}
15
+ </main>
16
+ </body>
17
+
18
+ </html>
@@ -0,0 +1,2 @@
1
+ name=Home page
2
+ componentType=template
@@ -0,0 +1,8 @@
1
+ <jnt = 'http://www.jahia.org/jahia/nt/1.0'>
2
+ <jmix = 'http://www.jahia.org/jahia/mix/1.0'>
3
+ <$$MODULE_NAMESPACE$$ = 'http://www.acme.org/$$MODULE_NAME$$/nt/1.0'>
4
+ <$$MODULE_NAMESPACE$$mix = 'http://www.acme.org/$$MODULE_NAME$$/mix/1.0'>
5
+
6
+ // This mixin creates a category to regroup types in the content type selector UI. Apply it to any definition you want
7
+ // to see in this category.
8
+ [$$MODULE_NAMESPACE$$mix:$$MODULE_NAMESPACE$$Components] > jmix:droppableContent, jmix:accessControllableContent mixin
@@ -0,0 +1,4 @@
1
+ JAHIA_USER=root:root1234
2
+ JAHIA_HOST=http://localhost:8080
3
+ JAHIA_DOCKER_NAME=jahia-ee-dev
4
+ JAHIA_DEPLOY_METHOD=curl
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ browser: true,
5
+ es2021: true
6
+ },
7
+ extends: '@jahia',
8
+ overrides: [
9
+ {
10
+ env: {
11
+ node: true
12
+ },
13
+ files: [
14
+ '.eslintrc.{js,cjs}'
15
+ ],
16
+ parserOptions: {
17
+ sourceType: 'script'
18
+ }
19
+ }
20
+ ],
21
+ parserOptions: {
22
+ requireConfigFile: false,
23
+ ecmaVersion: 'latest',
24
+ sourceType: 'module'
25
+ },
26
+ ignorePatterns: ['dist'],
27
+ rules: {
28
+ }
29
+ };
@@ -0,0 +1,15 @@
1
+ # Intellij
2
+ .idea
3
+ *.iml
4
+ *.ipr
5
+
6
+ # Node
7
+ dist
8
+ node_modules
9
+
10
+ # yarn v2
11
+ .yarn/cache
12
+ .yarn/unplugged
13
+ .yarn/build-state.yml
14
+ .yarn/install-state.gz
15
+ .pnp.*
@@ -0,0 +1,4 @@
1
+ .env
2
+ .eslintrc.cjs
3
+ .idea
4
+ *.tgz
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <content xmlns:j="http://www.jahia.org/jahia/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
3
+ <modules jcr:primaryType="jnt:modules">
4
+ <$$MODULE_NAME$$>
5
+ <home j:isHomePage="true" j:templateName="home" jcr:primaryType="jnt:page" />
6
+ </$$MODULE_NAME$$>
7
+ </modules>
8
+ </content>
@@ -0,0 +1,3 @@
1
+ {
2
+ "greeting": "Hallo !"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "greeting": "Hello !"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "greeting": "Salut !"
3
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "$$MODULE_NAME$$",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "scripts": {
6
+ "build": "webpack --mode=development",
7
+ "deploy": "jahia-deploy",
8
+ "watch": "yarn build --env deploy=true --watch",
9
+ "lint": "eslint .",
10
+ "test": "yarn lint",
11
+ "postinstall": "yarn dlx @yarnpkg/sdks vscode"
12
+ },
13
+ "jahia": {
14
+ "module-dependencies" : "default",
15
+ "module-type": "templatesSet",
16
+ "server": "dist/main.js",
17
+ "static-resources" : "/css,/images,/javascript"
18
+ },
19
+ "devDependencies": {
20
+ "@jahia/eslint-config": "^2.1.2",
21
+ "@jahia/scripts": "^1.3.3",
22
+ "eslint": "^8.43.0",
23
+ "eslint-plugin-jest": "latest",
24
+ "eslint-plugin-react": "latest",
25
+ "eslint-plugin-react-hooks": "latest",
26
+ "extra-watch-webpack-plugin": "latest",
27
+ "handlebars-loader": "^1.7.3",
28
+ "typescript": "^5.3.3",
29
+ "webpack": "^5.88.1",
30
+ "webpack-cli": "^5.1.4",
31
+ "webpack-shell-plugin-next": "^2.3.1"
32
+ },
33
+ "dependencies": {
34
+ "handlebars": "^4.7.7",
35
+ "@jahia/js-server-core" : "^0.0.4"
36
+ },
37
+ "engines": {
38
+ "node": ">=16.0.0",
39
+ "yarn": ">=3.0.0"
40
+ }
41
+ }
@@ -0,0 +1,2 @@
1
+ $$MODULE_NAMESPACE$$_hello=Hello
2
+ $$MODULE_NAMESPACE$$_hello.textHello=Hello world !
@@ -0,0 +1,2 @@
1
+ $$MODULE_NAMESPACE$$_hello=Bonjour
2
+ $$MODULE_NAMESPACE$$_hello.textHello=Bonjour le monde !
@@ -0,0 +1,9 @@
1
+ In this directory you can put directly :
2
+ - Rule files (*.drl, *.dsl)
3
+ - URL rewrite XML files
4
+
5
+ In the configurations directory you can put :
6
+ - OSGi configuration files (*.cfg, *.yml)
7
+
8
+ In the jahia-content-editor-forms you can put content editor form and field set overrides,
9
+ see examples here : https://academy.jahia.com/documentation/jahia/jahia-8/developer/extending-and-customizing-jahia-ui/customizing-content-editor-forms/examples-of-content-definition-json-overrides
File without changes
@@ -0,0 +1,49 @@
1
+ const path = require('path');
2
+ const WebpackShellPluginNext = require('webpack-shell-plugin-next');
3
+ const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
4
+
5
+ module.exports = env => {
6
+ const config = {
7
+ entry: {
8
+ main: path.resolve(__dirname, 'src/index')
9
+ },
10
+ output: {
11
+ path: path.resolve(__dirname, 'dist')
12
+ },
13
+ externals: {
14
+ '@jahia/js-server-core': 'jsServerCoreLibraryBuilder.getLibrary()',
15
+ handlebars: 'jsServerCoreLibraryBuilder.getSharedLibrary(\'handlebars\')'
16
+ },
17
+ plugins: [
18
+ new ExtraWatchWebpackPlugin({
19
+ files: [
20
+ 'src/**/*',
21
+ 'components/**/*',
22
+ 'views/**/*',
23
+ 'images/**/*',
24
+ 'css/**/*',
25
+ 'javascript/**/*',
26
+ 'locales/**/*.json',
27
+ 'resources/**/*.properties',
28
+ 'settings/**/*',
29
+ 'definitions.cnd',
30
+ 'import.xml',
31
+ 'package.json'
32
+ ]
33
+ })
34
+ ],
35
+ devtool: 'inline-source-map'
36
+ };
37
+
38
+ if (env.deploy) {
39
+ config.plugins.push(
40
+ new WebpackShellPluginNext({
41
+ onAfterDone: {
42
+ scripts: ['yarn jahia-deploy pack']
43
+ }
44
+ })
45
+ );
46
+ }
47
+
48
+ return config;
49
+ };
File without changes
package/index.js ADDED
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Usage: npx @jahia/create-module@latest module-name [namespace]
4
+
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import {fileURLToPath} from 'url';
8
+ import replace from 'replace-in-file';
9
+ import camelCase from 'camelcase';
10
+ import {execSync} from 'child_process';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+
15
+ // The first argument will be the project name.
16
+ // The second argument will be the project type (handlebars or jsx)
17
+ // The third argument is optional, it will be the namespace of the module.
18
+ if (process.argv.length < 3) {
19
+ console.error('Missing module-name parameter. Ex: npx @jahia/create-module@latest module-name module-type [namespace]');
20
+ process.exit(9);
21
+ }
22
+
23
+ const projectName = process.argv[2];
24
+ const camelProjectName = camelCase(projectName);
25
+
26
+ // First let's do some version checks
27
+ console.log('Node version detected:', process.versions.node);
28
+ const yarnVersion = execSync('yarn --version', {encoding: 'utf8'});
29
+ console.log('Yarn version:', yarnVersion);
30
+
31
+ let projectType;
32
+ if (process.argv[3] === 'handlebars' || process.argv[3] === 'jsx') {
33
+ projectType = process.argv[3];
34
+ } else {
35
+ console.error(`Invalid module-type parameter, should be handlebars or jsx, got:${process.argv[3]}. Ex: npx @jahia/create-module@latest module-name module-type [namespace]`);
36
+ process.exit(9);
37
+ }
38
+
39
+ let namespace;
40
+ if (process.argv.length > 4) {
41
+ namespace = process.argv[4];
42
+ } else {
43
+ namespace = camelProjectName;
44
+ }
45
+
46
+ // Create a project directory with the project name.
47
+ const currentDir = process.cwd();
48
+ const projectDir = path.resolve(currentDir, projectName);
49
+ fs.mkdirSync(projectDir, {recursive: true});
50
+
51
+ // A common approach to building a starter template is to
52
+ // create a `template` folder which will house the template
53
+ // and the files we want to create.
54
+ const templateDir = path.resolve(__dirname, projectType);
55
+ fs.cpSync(templateDir, projectDir, {recursive: true});
56
+
57
+ // It is good practice to have dotfiles stored in the
58
+ // template without the dot (so they do not get picked
59
+ // up by the starter template repository). We can rename
60
+ // the dotfiles after we have copied them over to the
61
+ // new project directory.
62
+ fs.renameSync(
63
+ path.join(projectDir, 'dotgitignore'),
64
+ path.join(projectDir, '.gitignore')
65
+ );
66
+ fs.renameSync(
67
+ path.join(projectDir, 'dotnpmignore'),
68
+ path.join(projectDir, '.npmignore')
69
+ );
70
+ fs.renameSync(
71
+ path.join(projectDir, 'dotenv'),
72
+ path.join(projectDir, '.env')
73
+ );
74
+ fs.renameSync(
75
+ path.join(projectDir, 'doteslintrc.cjs'),
76
+ path.join(projectDir, '.eslintrc.cjs')
77
+ );
78
+
79
+ // Rename the resource file to use the project name
80
+ fs.renameSync(
81
+ path.join(projectDir, 'resources/MODULE_NAME.properties'),
82
+ path.join(projectDir, 'resources/' + projectName + '.properties')
83
+ );
84
+
85
+ fs.renameSync(
86
+ path.join(projectDir, 'resources/MODULE_NAME_fr.properties'),
87
+ path.join(projectDir, 'resources/' + projectName + '_fr.properties')
88
+ );
89
+
90
+ // Rename the resource file to use the project name
91
+ if (process.argv[3] === 'handlebars') {
92
+ fs.renameSync(
93
+ path.join(projectDir, 'components/MODULE_NAMESPACE'),
94
+ path.join(projectDir, 'components/' + namespace)
95
+ );
96
+ }
97
+
98
+ // Create empty directories for static resources and configurations
99
+ fs.mkdirSync(path.join(projectDir, 'css'), {recursive: true});
100
+ fs.mkdirSync(path.join(projectDir, 'images'), {recursive: true});
101
+ fs.mkdirSync(path.join(projectDir, 'javascript'), {recursive: true});
102
+ fs.mkdirSync(path.join(projectDir, 'settings/configurations'), {recursive: true});
103
+ fs.mkdirSync(path.join(projectDir, 'settings/jahia-content-editor-forms'), {recursive: true});
104
+ fs.mkdirSync(path.join(projectDir, 'settings/jahia-content-editor-forms/forms'), {recursive: true});
105
+ fs.mkdirSync(path.join(projectDir, 'settings/jahia-content-editor-forms/fieldsets'), {recursive: true});
106
+
107
+ // Find and replace all markers with the appropriate substitution values
108
+ const targetFiles = [
109
+ path.join(projectDir, 'README.md'),
110
+ path.join(projectDir, 'import.xml'),
111
+ path.join(projectDir, 'package.json'),
112
+ path.join(projectDir, 'definitions.cnd'),
113
+ path.join(projectDir, 'resources/' + projectName + '.properties'),
114
+ path.join(projectDir, 'resources/' + projectName + '_fr.properties')
115
+ ];
116
+
117
+ if (projectType === 'jsx') {
118
+ targetFiles.push(path.join(projectDir, 'src/server/templates/page/PageHome.jsx'));
119
+ targetFiles.push(path.join(projectDir, 'src/server/views/hello/HelloDefault.jsx'));
120
+ targetFiles.push(path.join(projectDir, 'src/client/index.jsx'));
121
+ targetFiles.push(path.join(projectDir, 'webpack.config.js'));
122
+ }
123
+
124
+ if (projectType === 'handlebars') {
125
+ targetFiles.push(path.join(projectDir, 'components/' + namespace + '/hello/hello.cnd'));
126
+ }
127
+
128
+ try {
129
+ replace.sync({
130
+ files: targetFiles,
131
+ from: /\$\$CAMEL_MODULE_NAME\$\$/g,
132
+ to: camelProjectName,
133
+ disableGlobs: true // This is required otherwise the replaces fail under Windows (see https://jira.jahia.org/browse/BACKLOG-21353)
134
+ });
135
+
136
+ replace.sync({
137
+ files: targetFiles,
138
+ from: /\$\$MODULE_NAME\$\$/g,
139
+ to: projectName,
140
+ disableGlobs: true // This is required otherwise the replaces fail under Windows (see https://jira.jahia.org/browse/BACKLOG-21353)
141
+ });
142
+
143
+ replace.sync({
144
+ files: targetFiles,
145
+ from: /\$\$MODULE_NAMESPACE\$\$/g,
146
+ to: namespace,
147
+ disableGlobs: true // This is required otherwise the replaces fail under Windows (see https://jira.jahia.org/browse/BACKLOG-21353)
148
+ });
149
+ } catch (error) {
150
+ console.error('Error occurred:', error);
151
+ }
152
+
153
+ console.log(`Created ${projectName} at ${projectDir}`);
154
+ console.log('Success! Your new project is ready.');
155
+ console.log('You can now change into your project and launch "yarn" to install everything to get started.');
156
+ console.log('---');
157
+ console.log('Available project scripts will then be :');
158
+ console.log(' - yarn build : build the project');
159
+ console.log(' - yarn deploy : deploy the project. Make sure you have updated the .env file to match your setup if needed.');
160
+ console.log(' - yarn watch : will build and watch for file modifications, and deploy automatically when changes are detected. Use CTRL+C to stop watching.');
161
+ console.log(' - yarn lint : use to check that your code follows the recommended syntax guidelines. Append --fix to automatically fix most problems.');
162
+ console.log(' - yarn test : to test your project. By default only performs yarn lint but you are encouraged to add your own testing system here.');
163
+ console.log('---');
164
+ console.log('You can also check the documentation available here for more details: https://academy.jahia.com/get-started/developers/templating');
package/jsx/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # $$MODULE_NAME$$
2
+
3
+ A simple Jahia NPM module created using the NPM module starter project template
4
+
5
+ ## Configuration
6
+
7
+ If you don't use default configuration for the Docker container name or for Jahia deployments, please modify the provided `.env` file
8
+
9
+ ## Documentation
10
+
11
+ You can find the documentation on how to use this module on the [Jahia Academy](https://academy.jahia.com/get-started/developers/templating) templating tutorial.
@@ -0,0 +1,8 @@
1
+ body {
2
+ font-family: 'Helvetica Neue', Arial, sans-serif;
3
+ margin: 0;
4
+ padding: 40px;
5
+ background-color: #f5f5f5;
6
+ color: #333;
7
+ line-height: 1.6;
8
+ }
@@ -0,0 +1,11 @@
1
+ <jnt = 'http://www.jahia.org/jahia/nt/1.0'>
2
+ <jmix = 'http://www.jahia.org/jahia/mix/1.0'>
3
+ <$$MODULE_NAMESPACE$$ = 'http://www.acme.org/$$MODULE_NAME$$/nt/1.0'>
4
+ <$$MODULE_NAMESPACE$$mix = 'http://www.acme.org/$$MODULE_NAME$$/mix/1.0'>
5
+
6
+ // This mixin creates a category to regroup types in the content type selector UI. Apply it to any definition you want
7
+ // to see in this category.
8
+ [$$MODULE_NAMESPACE$$mix:$$MODULE_NAMESPACE$$Components] > jmix:droppableContent, jmix:accessControllableContent mixin
9
+
10
+ [$$MODULE_NAMESPACE$$:hello] > jnt:content, $$MODULE_NAMESPACE$$mix:$$MODULE_NAMESPACE$$Components
11
+ - textHello (string) = 'Hello world !' i18n
package/jsx/dotenv ADDED
@@ -0,0 +1,4 @@
1
+ JAHIA_USER=root:root1234
2
+ JAHIA_HOST=http://localhost:8080
3
+ JAHIA_DOCKER_NAME=jahia-ee-dev
4
+ JAHIA_DEPLOY_METHOD=curl
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ browser: true,
5
+ es2021: true
6
+ },
7
+ extends: '@jahia',
8
+ overrides: [
9
+ {
10
+ env: {
11
+ node: true
12
+ },
13
+ files: [
14
+ '.eslintrc.{js,cjs}'
15
+ ],
16
+ parserOptions: {
17
+ sourceType: 'script'
18
+ }
19
+ }
20
+ ],
21
+ parserOptions: {
22
+ requireConfigFile: false,
23
+ ecmaVersion: 'latest',
24
+ sourceType: 'module'
25
+ },
26
+ ignorePatterns: ['dist', 'css', 'javascript'],
27
+ rules: {
28
+ }
29
+ };
@@ -0,0 +1,15 @@
1
+ # Intellij
2
+ .idea
3
+ *.iml
4
+ *.ipr
5
+
6
+ # Node
7
+ dist
8
+ node_modules
9
+
10
+ # yarn v2
11
+ .yarn/cache
12
+ .yarn/unplugged
13
+ .yarn/build-state.yml
14
+ .yarn/install-state.gz
15
+ .pnp.*
@@ -0,0 +1,10 @@
1
+ .env
2
+ .eslintrc.cjs
3
+ .idea
4
+ *.tgz
5
+ .yarn
6
+ .vscode
7
+ webpack.config.js
8
+ README.md
9
+ settings/README.txt
10
+ src
package/jsx/import.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <content xmlns:j="http://www.jahia.org/jahia/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
3
+ <modules jcr:primaryType="jnt:modules">
4
+ <$$MODULE_NAME$$>
5
+ <home j:isHomePage="true" j:templateName="home" jcr:primaryType="jnt:page">
6
+ </home>
7
+ </$$MODULE_NAME$$>
8
+ </modules>
9
+ </content>
@@ -0,0 +1,4 @@
1
+ {
2
+ "greeting": "Hallo !",
3
+ "welcomeTitle" : "Willkommen bei Jahia!"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "greeting": "Hello !",
3
+ "welcomeTitle" : "Welcome to Jahia !"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "greeting": "Salut !",
3
+ "welcomeTitle" : "Bienvenue chez Jahia !"
4
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "$$MODULE_NAME$$",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "license": "MIT",
6
+ "scripts": {
7
+ "build": "webpack --mode=development",
8
+ "build:production": "webpack --mode=production",
9
+ "deploy": "jahia-deploy pack",
10
+ "watch": "yarn build --env deploy=true --watch",
11
+ "lint": "eslint .",
12
+ "test": "yarn lint",
13
+ "postinstall": "yarn dlx @yarnpkg/sdks vscode"
14
+ },
15
+ "jahia": {
16
+ "module-dependencies": "default",
17
+ "module-type": "templatesSet",
18
+ "server": "dist/main.js",
19
+ "static-resources": "/css,/images,/javascript,/locales"
20
+ },
21
+ "dependencies": {
22
+ "@apollo/client": "3.5.5",
23
+ "@jahia/data-helper": "1.0.4",
24
+ "@jahia/js-server-core": "^0.0.4",
25
+ "graphql": "^16.7.1",
26
+ "react": "^18.2.0",
27
+ "react-dom": "^18.2.0"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/cli": "^7.16.0",
31
+ "@babel/core": "^7.16.0",
32
+ "@babel/preset-env": "^7.16.4",
33
+ "@babel/preset-react": "^7.16.0",
34
+ "@jahia/eslint-config": "^2.1.2",
35
+ "@jahia/scripts": "^1.3.3",
36
+ "babel-loader": "^8.2.3",
37
+ "clean-webpack-plugin": "^4.0.0",
38
+ "copy-webpack-plugin": "^10.0.0",
39
+ "dotenv-cli": "^4.0.0",
40
+ "eslint": "^8.43.0",
41
+ "eslint-plugin-jest": "latest",
42
+ "eslint-plugin-react": "latest",
43
+ "eslint-plugin-react-hooks": "latest",
44
+ "extra-watch-webpack-plugin": "^1.0.3",
45
+ "styled-jsx": "^5.1.2",
46
+ "typescript": "^5.3.3",
47
+ "webpack": "^5.64.4",
48
+ "webpack-cli": "^4.9.1",
49
+ "webpack-shell-plugin-next": "^2.3.1"
50
+ },
51
+ "engines": {
52
+ "node": ">=16.0.0",
53
+ "yarn": ">=3.0.0"
54
+ },
55
+ "packageManager": "yarn@4.1.0"
56
+ }
@@ -0,0 +1,3 @@
1
+ $$MODULE_NAMESPACE$$mix_$$MODULE_NAMESPACE$$Components = $$MODULE_NAMESPACE$$ Components
2
+ $$MODULE_NAMESPACE$$_hello=Hello
3
+ $$MODULE_NAMESPACE$$_hello.textHello=Hello world !
@@ -0,0 +1,3 @@
1
+ $$MODULE_NAMESPACE$$mix_$$MODULE_NAMESPACE$$Components = Composants $$MODULE_NAMESPACE$$
2
+ $$MODULE_NAMESPACE$$_hello=Bonjour
3
+ $$MODULE_NAMESPACE$$_hello.textHello=Bonjour le monde !
@@ -0,0 +1,9 @@
1
+ In this directory you can put directly :
2
+ - Rule files (*.drl, *.dsl)
3
+ - URL rewrite XML files
4
+
5
+ In the configurations directory you can put :
6
+ - OSGi configuration files (*.cfg, *.yml)
7
+
8
+ In the jahia-content-editor-forms you can put content editor form and field set overrides,
9
+ see examples here : https://academy.jahia.com/documentation/jahia/jahia-8/developer/extending-and-customizing-jahia-ui/customizing-content-editor-forms/examples-of-content-definition-json-overrides
@@ -0,0 +1,5 @@
1
+ // PublicPath is used to make webpack able to download the chunks and assets from the correct location
2
+ // Since JS can be aggregated by Jahia on live, the path of the original file is lost
3
+ // Also the context of the server should be handled properly
4
+ // eslint-disable-next-line camelcase, no-undef
5
+ __webpack_public_path__ = `${window.__APPSHELL_INIT_DATA__.moduleBaseUrl}/$$MODULE_NAME$$/javascript/client/`;
@@ -0,0 +1 @@
1
+ // Export here any components that were added to this directory
@@ -0,0 +1,6 @@
1
+ import * as jahiaTemplates from './templates';
2
+ import * as jahiaViews from './views';
3
+ import {registerJahiaComponents} from '@jahia/js-server-core';
4
+
5
+ registerJahiaComponents(jahiaTemplates);
6
+ registerJahiaComponents(jahiaViews);
@@ -0,0 +1 @@
1
+ export * from './page';
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import {Area, AddResources} from '@jahia/js-server-core';
3
+
4
+ export const PageHome = () => {
5
+ return (<>
6
+ <head>
7
+ <AddResources type='css' resources='styles.css' />
8
+ <title>Home</title>
9
+ </head>
10
+ <body>
11
+ <h1>Home Template</h1>
12
+ <main>
13
+ <Area name="pagecontent" />
14
+ </main>
15
+ </body>
16
+ </>);
17
+ }
18
+
19
+ PageHome.jahiaComponent = { // This object is used to register the template in Jahia
20
+ nodeType: 'jnt:page', // The content node type the template applies to
21
+ name: 'home', // The name of the template
22
+ displayName: 'Home page', // The display name of the page template
23
+ componentType: 'template' // the component type is set to template (as opposed to view component types)
24
+ }
@@ -0,0 +1 @@
1
+ export * from './PageHome';
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import { useServerContext, getNodeProps } from '@jahia/js-server-core'
3
+
4
+ export const HelloDefault = () => {
5
+ const { currentNode } = useServerContext();
6
+ const props = getNodeProps(currentNode, ['textHello']);
7
+ return (
8
+ <div>
9
+ <h2>{props.textHello}</h2>
10
+ </div>
11
+ )
12
+ }
13
+
14
+ HelloDefault.jahiaComponent = { // this object is used to register the view in Jahia
15
+ nodeType: '$$MODULE_NAMESPACE$$:hello', // The content node type the template applies to
16
+ displayName: 'Hello (default)', // The display name of the view
17
+ componentType: 'view' // the component type is set to view (as opposed to template component types)
18
+ }
@@ -0,0 +1 @@
1
+ export * from './HelloDefault';
@@ -0,0 +1 @@
1
+ export * from './hello';
@@ -0,0 +1,162 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
4
+ const WebpackShellPluginNext = require('webpack-shell-plugin-next');
5
+ const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
6
+
7
+ const deps = require('./package.json').dependencies;
8
+
9
+ // Read all files in the client components directory in order to expose them with webpack module federation more easily
10
+ // Those components are exposed in order to be hydrate/rendered client side
11
+ const componentsDir = './src/client';
12
+ const exposes = {};
13
+ fs.readdirSync(componentsDir).forEach(file => {
14
+ if (file !== 'index.js') {
15
+ const componentName = path.basename(file, path.extname(file));
16
+ exposes[componentName] = path.resolve(componentsDir, file);
17
+ }
18
+ });
19
+ const moduleName = '$$MODULE_NAME$$';
20
+
21
+ module.exports = env => {
22
+ let configs = [
23
+ {
24
+ entry: {
25
+ [moduleName]: path.resolve(__dirname, './src/client/index')
26
+ },
27
+ output: {
28
+ path: path.resolve(__dirname, 'javascript/client')
29
+ },
30
+ resolve: {
31
+ mainFields: ['module', 'main'],
32
+ extensions: ['.mjs', '.js', '.jsx']
33
+ },
34
+ module: {
35
+ rules: [
36
+ {
37
+ test: /\.jsx$/,
38
+ include: [path.join(__dirname, 'src/client')],
39
+ use: {
40
+ loader: 'babel-loader',
41
+ options: {
42
+ presets: [
43
+ ['@babel/preset-env', {modules: false, targets: {safari: '7', ie: '10'}}],
44
+ '@babel/preset-react'
45
+ ],
46
+ plugins: [
47
+ 'styled-jsx/babel'
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ ]
53
+ },
54
+ plugins: [
55
+ new ModuleFederationPlugin({
56
+ name: moduleName,
57
+ library: {type: 'assign', name: `window.appShell = (typeof appShell === "undefined" ? {} : appShell); window.appShell['${moduleName}']`},
58
+ filename: '../client/remote.js',
59
+ exposes: exposes,
60
+ shared: {
61
+ react: {
62
+ requiredVersion: deps.react,
63
+ singleton: true
64
+ },
65
+ 'react-i18next': {},
66
+ i18next: {}
67
+ }
68
+ })
69
+ ],
70
+ devtool: 'inline-source-map',
71
+ mode: 'development'
72
+ },
73
+ {
74
+ entry: {
75
+ main: path.resolve(__dirname, 'src/server')
76
+ },
77
+ output: {
78
+ path: path.resolve(__dirname, 'dist')
79
+ },
80
+ externals: {
81
+ '@jahia/js-server-core': 'jsServerCoreLibraryBuilder.getLibrary()',
82
+ react: 'jsServerCoreLibraryBuilder.getSharedLibrary(\'react\')',
83
+ 'styled-jsx/style': 'jsServerCoreLibraryBuilder.getSharedLibrary(\'styled-jsx\')'
84
+ },
85
+ resolve: {
86
+ mainFields: ['module', 'main'],
87
+ extensions: ['.mjs', '.js', '.jsx']
88
+ },
89
+ module: {
90
+ rules: [
91
+ {
92
+ test: /\.jsx$/,
93
+ include: [
94
+ path.join(__dirname, 'src/server'),
95
+ path.join(__dirname, 'src/client')
96
+ ],
97
+ use: {
98
+ loader: 'babel-loader',
99
+ options: {
100
+ presets: [
101
+ ['@babel/preset-env', {modules: false, targets: {safari: '7', ie: '10'}}],
102
+ '@babel/preset-react'
103
+ ],
104
+ plugins: [
105
+ 'styled-jsx/babel'
106
+ ]
107
+ }
108
+ }
109
+ },
110
+ {
111
+ test: /\.s[ac]ss$/i,
112
+ use: [
113
+ 'style-loader',
114
+ {
115
+ loader: 'css-loader',
116
+ options: {
117
+ modules: true
118
+ }
119
+ },
120
+ 'sass-loader'
121
+ ]
122
+ }
123
+ ]
124
+ },
125
+ plugins: [
126
+ new ExtraWatchWebpackPlugin({
127
+ files: [
128
+ 'src/server/**/*',
129
+ 'images/**/*',
130
+ 'css/**/*',
131
+ 'javascript/**/*',
132
+ 'locales/**/*.json',
133
+ 'resources/**/*.properties',
134
+ 'settings/**/*',
135
+ 'definitions.cnd',
136
+ 'import.xml',
137
+ 'package.json'
138
+ ]
139
+ })
140
+ ],
141
+ devtool: 'inline-source-map',
142
+ mode: 'development'
143
+ }
144
+ ];
145
+
146
+ const webpackShellPlugin = new WebpackShellPluginNext({
147
+ onAfterDone: {
148
+ scripts: ['yarn jahia-deploy pack']
149
+ }
150
+ });
151
+
152
+ if (env.deploy) {
153
+ let config = configs[configs.length - 1];
154
+ if (!config.plugins) {
155
+ config.plugins = [];
156
+ }
157
+
158
+ config.plugins.push(webpackShellPlugin);
159
+ }
160
+
161
+ return configs;
162
+ };
package/jsx/yarn.lock ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@jahia/create-module",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "bin": "./index.js",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Jahia/npm-create-module.git"
10
+ },
11
+ "keywords": [
12
+ "template"
13
+ ],
14
+ "author": "Jahia <support@jahia.com>",
15
+ "bugs": {
16
+ "url": "https://github.com/Jahia/npm-create-module/issues"
17
+ },
18
+ "homepage": "https://github.com/Jahia/npm-create-module#readme",
19
+ "dependencies": {
20
+ "camelcase": "^8.0.0",
21
+ "path": "^0.12.7",
22
+ "replace-in-file": "^7.0.1",
23
+ "semver": "^7.5.4",
24
+ "url": "^0.11.1"
25
+ },
26
+ "devDependencies": {
27
+ "@jahia/eslint-config": "^2.1.2",
28
+ "@jahia/scripts": "^1.3.3",
29
+ "eslint": "^8.43.0",
30
+ "eslint-plugin-jest": "latest",
31
+ "eslint-plugin-react": "latest",
32
+ "eslint-plugin-react-hooks": "latest"
33
+ },
34
+ "scripts": {
35
+ "lint": "eslint .",
36
+ "posttest": "yarn lint",
37
+ "test-hbs": "rm -rf test-project-hbs && node index.js test-project-hbs handlebars && cd test-project-hbs && yarn && yarn build && yarn lint && yarn test && cd ..",
38
+ "test-jsx": "rm -rf test-project-jsx && node index.js test-project-jsx jsx && cd test-project-jsx && yarn && yarn build && yarn lint && yarn test && cd ..",
39
+ "test": "yarn test-hbs && yarn test-jsx",
40
+ "version": "git add README.md"
41
+ },
42
+ "engines": {
43
+ "node": ">=16.0.0",
44
+ "yarn": ">=3.0.0"
45
+ },
46
+ "packageManager": "yarn@4.1.1"
47
+ }