@jahia/create-module 0.0.4 → 0.0.5
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/index.js +48 -35
- package/package.json +1 -1
- package/template/doteslintrc.cjs +1 -0
- package/template/dotgitignore +3 -0
- package/template/package.json +2 -2
- package/template/settings/content-types-icons/MODULE_NAMESPACE_simpleContent.png +0 -0
- package/template/settings/definitions.cnd +2 -2
- package/template/settings/resources/MODULE_NAME.properties +2 -2
- package/template/settings/resources/MODULE_NAME_fr.properties +2 -2
- package/template/settings/template-thumbnail.png +0 -0
- package/template/src/client/index.jsx +1 -1
- package/template/src/server/templates/page/PageHome.jsx +16 -14
- package/template/src/server/views/index.js +1 -1
- package/template/src/server/views/simpleContent/SimpleContentDefault.jsx +19 -0
- package/template/src/server/views/simpleContent/index.js +1 -0
- package/template/src/server/views/hello/HelloDefault.jsx +0 -19
- package/template/src/server/views/hello/index.js +0 -1
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ const __dirname = path.dirname(__filename);
|
|
|
14
14
|
|
|
15
15
|
// Show help if no argment is provided
|
|
16
16
|
// eslint-disable-next-line no-unused-vars
|
|
17
|
-
const [nodeCommand, npxCommand, projectName, moduleType = 'module', namespace = camelCase(projectName)] = process.argv;
|
|
17
|
+
const [nodeCommand, npxCommand, projectName, moduleType = 'module', namespace = camelCase(projectName || '')] = process.argv;
|
|
18
18
|
|
|
19
19
|
if (!projectName) {
|
|
20
20
|
console.log(`\x1B[1m## Usage\x1B[0m
|
|
@@ -48,7 +48,40 @@ console.log(`Creating a new Jahia module project \x1B[1m${projectName}\x1B[0m of
|
|
|
48
48
|
// create a `template` folder which will house the template
|
|
49
49
|
// and the files we want to create.
|
|
50
50
|
const templateDir = path.resolve(__dirname, 'template');
|
|
51
|
-
|
|
51
|
+
const isTemplatesSet = moduleType === 'templatesSet';
|
|
52
|
+
fs.cpSync(templateDir, projectDir, {
|
|
53
|
+
recursive: true,
|
|
54
|
+
filter: src => {
|
|
55
|
+
// The file template-thumbnail.png is only used for the type templatesSet
|
|
56
|
+
return (isTemplatesSet || src !== path.join(templateDir, 'settings', 'template-thumbnail.png'));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Find and replace all markers with the appropriate substitution values
|
|
61
|
+
// Doing it before renaming the dotfiles so they are not excluded
|
|
62
|
+
const targetFiles = `${projectDir}/**`;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
replaceInFileSync({
|
|
66
|
+
files: targetFiles,
|
|
67
|
+
from: /\$\$MODULE_TYPE\$\$/g,
|
|
68
|
+
to: moduleType
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
replaceInFileSync({
|
|
72
|
+
files: targetFiles,
|
|
73
|
+
from: /\$\$MODULE_NAME\$\$/g,
|
|
74
|
+
to: projectName
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
replaceInFileSync({
|
|
78
|
+
files: targetFiles,
|
|
79
|
+
from: /\$\$MODULE_NAMESPACE\$\$/g,
|
|
80
|
+
to: namespace
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Error occurred:', error);
|
|
84
|
+
}
|
|
52
85
|
|
|
53
86
|
// It is good practice to have dotfiles stored in the
|
|
54
87
|
// template without the dot (so they do not get picked
|
|
@@ -74,48 +107,28 @@ fs.renameSync(
|
|
|
74
107
|
|
|
75
108
|
// Rename the resource file to use the project name
|
|
76
109
|
fs.renameSync(
|
|
77
|
-
path.join(projectDir, 'settings
|
|
78
|
-
path.join(projectDir, 'settings
|
|
110
|
+
path.join(projectDir, 'settings', 'resources', 'MODULE_NAME.properties'),
|
|
111
|
+
path.join(projectDir, 'settings', 'resources', projectName + '.properties')
|
|
79
112
|
);
|
|
80
113
|
|
|
81
114
|
fs.renameSync(
|
|
82
|
-
path.join(projectDir, 'settings
|
|
83
|
-
path.join(projectDir, 'settings
|
|
115
|
+
path.join(projectDir, 'settings', 'resources', 'MODULE_NAME_fr.properties'),
|
|
116
|
+
path.join(projectDir, 'settings', 'resources', projectName + '_fr.properties')
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
fs.renameSync(
|
|
120
|
+
path.join(projectDir, 'settings', 'content-types-icons', 'MODULE_NAMESPACE_simpleContent.png'),
|
|
121
|
+
path.join(projectDir, 'settings', 'content-types-icons', namespace + '_simpleContent.png')
|
|
84
122
|
);
|
|
85
123
|
|
|
86
124
|
// Create empty directories for static resources and configurations
|
|
87
125
|
fs.mkdirSync(path.join(projectDir, 'css'), {recursive: true});
|
|
88
126
|
fs.mkdirSync(path.join(projectDir, 'images'), {recursive: true});
|
|
89
127
|
fs.mkdirSync(path.join(projectDir, 'javascript'), {recursive: true});
|
|
90
|
-
fs.mkdirSync(path.join(projectDir, 'settings
|
|
91
|
-
fs.mkdirSync(path.join(projectDir, 'settings
|
|
92
|
-
fs.mkdirSync(path.join(projectDir, 'settings
|
|
93
|
-
fs.mkdirSync(path.join(projectDir, 'settings
|
|
94
|
-
|
|
95
|
-
// Find and replace all markers with the appropriate substitution values
|
|
96
|
-
const targetFiles = `${projectDir}/**`;
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
replaceInFileSync({
|
|
100
|
-
files: targetFiles,
|
|
101
|
-
from: /\$\$MODULE_TYPE\$\$/g,
|
|
102
|
-
to: camelCase(moduleType)
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
replaceInFileSync({
|
|
106
|
-
files: targetFiles,
|
|
107
|
-
from: /\$\$MODULE_NAME\$\$/g,
|
|
108
|
-
to: projectName
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
replaceInFileSync({
|
|
112
|
-
files: targetFiles,
|
|
113
|
-
from: /\$\$MODULE_NAMESPACE\$\$/g,
|
|
114
|
-
to: namespace
|
|
115
|
-
});
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.error('Error occurred:', error);
|
|
118
|
-
}
|
|
128
|
+
fs.mkdirSync(path.join(projectDir, 'settings', 'configurations'), {recursive: true});
|
|
129
|
+
fs.mkdirSync(path.join(projectDir, 'settings', 'content-editor-forms'), {recursive: true});
|
|
130
|
+
fs.mkdirSync(path.join(projectDir, 'settings', 'content-editor-forms', 'forms'), {recursive: true});
|
|
131
|
+
fs.mkdirSync(path.join(projectDir, 'settings', 'content-editor-forms', 'fieldsets'), {recursive: true});
|
|
119
132
|
|
|
120
133
|
console.log(`Created \x1B[1m${projectName}\x1B[0m at \x1B[1m${projectDir}\x1B[0m`);
|
|
121
134
|
console.log('Success! Your new project is ready.');
|
package/package.json
CHANGED
package/template/doteslintrc.cjs
CHANGED
package/template/dotgitignore
CHANGED
package/template/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build:production": "webpack --mode=production && jahia-pack",
|
|
9
9
|
"deploy": "jahia-deploy",
|
|
10
10
|
"watch": "webpack --mode=development --watch",
|
|
11
|
-
"lint": "eslint .",
|
|
11
|
+
"lint": "eslint --ext js,jsx .",
|
|
12
12
|
"test": "yarn lint"
|
|
13
13
|
},
|
|
14
14
|
"jahia": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"module-type": "$$MODULE_TYPE$$",
|
|
17
17
|
"module-type-comment": "Use templatesSet in the module type to declare a template set",
|
|
18
18
|
"server": "dist/main.js",
|
|
19
|
-
"static-resources": "/css,/images,/javascript,/locales"
|
|
19
|
+
"static-resources": "/css,/icons,/images,/javascript,/locales"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@jahia/js-server-core": "^0.0.13",
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
// to see in this category.
|
|
14
14
|
[$$MODULE_NAMESPACE$$mix:$$MODULE_NAMESPACE$$Components] > jmix:droppableContent, jmix:accessControllableContent mixin
|
|
15
15
|
|
|
16
|
-
[$$MODULE_NAMESPACE$$:
|
|
17
|
-
-
|
|
16
|
+
[$$MODULE_NAMESPACE$$:simpleContent] > jnt:content, $$MODULE_NAMESPACE$$mix:$$MODULE_NAMESPACE$$Components
|
|
17
|
+
- title (string) = 'Hello world !' i18n
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
$$MODULE_NAMESPACE$$mix_$$MODULE_NAMESPACE$$Components = $$MODULE_NAMESPACE$$ Components
|
|
2
|
-
$$MODULE_NAMESPACE$$
|
|
3
|
-
$$MODULE_NAMESPACE$$
|
|
2
|
+
$$MODULE_NAMESPACE$$_simpleContent=Simple Content
|
|
3
|
+
$$MODULE_NAMESPACE$$_simpleContent.title=Title
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
$$MODULE_NAMESPACE$$mix_$$MODULE_NAMESPACE$$Components = Composants $$MODULE_NAMESPACE$$
|
|
2
|
-
$$MODULE_NAMESPACE$$
|
|
3
|
-
$$MODULE_NAMESPACE$$
|
|
2
|
+
$$MODULE_NAMESPACE$$_simpleContent=Contenu simple
|
|
3
|
+
$$MODULE_NAMESPACE$$_simpleContent.title=Titre
|
|
Binary file
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// Since JS can be aggregated by Jahia on live, the path of the original file is lost
|
|
3
3
|
// Also the context of the server should be handled properly
|
|
4
4
|
// eslint-disable-next-line camelcase, no-undef
|
|
5
|
-
__webpack_public_path__ = `${window.__APPSHELL_INIT_DATA__.moduleBaseUrl}/$$MODULE_NAME$$/javascript/client/`;
|
|
5
|
+
__webpack_public_path__ = `${window.__APPSHELL_INIT_DATA__.moduleBaseUrl}/$$MODULE_NAME$$/javascript/client/`;
|
|
@@ -6,20 +6,22 @@ export const PageHome = () => {
|
|
|
6
6
|
const {t} = useTranslation();
|
|
7
7
|
const {currentResource} = useServerContext();
|
|
8
8
|
const lang = currentResource.getLocale().getLanguage();
|
|
9
|
-
return (
|
|
10
|
-
<
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
return (
|
|
10
|
+
<html lang={lang}>
|
|
11
|
+
<head>
|
|
12
|
+
<AddResources type="css" resources="styles.css"/>
|
|
13
|
+
<title>Home</title>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<main>
|
|
17
|
+
{/* Using i18next defined in locales */}
|
|
18
|
+
<h1>{t('homeTitle')}</h1>
|
|
19
|
+
<Area name="pagecontent"/>
|
|
20
|
+
</main>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
23
25
|
|
|
24
26
|
PageHome.jahiaComponent = defineJahiaComponent({
|
|
25
27
|
nodeType: 'jnt:page',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './simpleContent';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {useServerContext, getNodeProps, defineJahiaComponent} from '@jahia/js-server-core';
|
|
3
|
+
|
|
4
|
+
export const SimpleContentDefault = () => {
|
|
5
|
+
const {currentNode} = useServerContext();
|
|
6
|
+
const simpleContent = getNodeProps(currentNode, ['title']);
|
|
7
|
+
return (
|
|
8
|
+
<div>
|
|
9
|
+
<h2>{simpleContent.title}</h2>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
SimpleContentDefault.jahiaComponent = defineJahiaComponent({
|
|
15
|
+
name: 'default',
|
|
16
|
+
nodeType: '$$MODULE_NAMESPACE$$:simpleContent',
|
|
17
|
+
displayName: 'Simple Content (default)',
|
|
18
|
+
componentType: 'view'
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SimpleContentDefault';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import {useServerContext, getNodeProps, defineJahiaComponent} 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 = defineJahiaComponent({
|
|
15
|
-
name: 'default',
|
|
16
|
-
nodeType: '$$MODULE_NAMESPACE$$:hello',
|
|
17
|
-
displayName: 'Hello (default)',
|
|
18
|
-
componentType: 'view'
|
|
19
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './HelloDefault';
|