@jahia/create-module 0.0.2 → 0.0.4

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 (67) hide show
  1. package/.github/workflows/lint.yml +5 -3
  2. package/.github/workflows/publish-release.yml +2 -2
  3. package/.yarn/releases/yarn-4.5.0.cjs +925 -0
  4. package/.yarnrc.yml +3 -0
  5. package/README.md +9 -4
  6. package/index.js +34 -67
  7. package/package.json +7 -10
  8. package/template/.babelrc +9 -0
  9. package/template/.yarn/releases/yarn-4.3.1.cjs +894 -0
  10. package/template/.yarnrc.yml +3 -0
  11. package/{jsx → template}/README.md +20 -0
  12. package/{handlebars → template}/dotenv +1 -1
  13. package/template/dotgitignore +18 -0
  14. package/{jsx → template}/dotnpmignore +1 -1
  15. package/{jsx → template}/package.json +16 -16
  16. package/template/settings/README.md +30 -0
  17. package/{jsx → template/settings}/definitions.cnd +6 -0
  18. package/template/settings/locales/de.json +5 -0
  19. package/template/settings/locales/en.json +5 -0
  20. package/template/settings/locales/fr.json +5 -0
  21. package/template/src/server/templates/page/PageHome.jsx +29 -0
  22. package/template/src/server/views/hello/HelloDefault.jsx +19 -0
  23. package/{jsx → template}/webpack.config.js +49 -23
  24. package/babel.config.cjs.disabled +0 -3
  25. package/handlebars/README.md +0 -11
  26. package/handlebars/components/MODULE_NAMESPACE/hello/hello.cnd +0 -6
  27. package/handlebars/components/MODULE_NAMESPACE/hello/hello.default.hbs +0 -1
  28. package/handlebars/components/MODULE_NAMESPACE/hello/hello.icon.png +0 -0
  29. package/handlebars/components/jnt/page/page.home.hbs +0 -18
  30. package/handlebars/components/jnt/page/page.home.png +0 -0
  31. package/handlebars/components/jnt/page/page.home.properties +0 -2
  32. package/handlebars/definitions.cnd +0 -8
  33. package/handlebars/doteslintrc.cjs +0 -29
  34. package/handlebars/dotgitignore +0 -15
  35. package/handlebars/dotnpmignore +0 -4
  36. package/handlebars/import.xml +0 -8
  37. package/handlebars/locales/de.json +0 -3
  38. package/handlebars/locales/en.json +0 -3
  39. package/handlebars/locales/fr.json +0 -3
  40. package/handlebars/package.json +0 -41
  41. package/handlebars/resources/MODULE_NAME.properties +0 -2
  42. package/handlebars/resources/MODULE_NAME_fr.properties +0 -2
  43. package/handlebars/settings/README.txt +0 -9
  44. package/handlebars/src/index.js +0 -0
  45. package/handlebars/webpack.config.js +0 -49
  46. package/jsx/dotenv +0 -4
  47. package/jsx/dotgitignore +0 -15
  48. package/jsx/locales/de.json +0 -4
  49. package/jsx/locales/en.json +0 -4
  50. package/jsx/locales/fr.json +0 -4
  51. package/jsx/settings/README.txt +0 -9
  52. package/jsx/src/server/templates/page/PageHome.jsx +0 -24
  53. package/jsx/src/server/views/hello/HelloDefault.jsx +0 -18
  54. package/jsx/yarn.lock +0 -0
  55. /package/{jsx → template}/css/styles.css +0 -0
  56. /package/{jsx → template}/doteslintrc.cjs +0 -0
  57. /package/{jsx → template/settings}/import.xml +0 -0
  58. /package/{jsx → template/settings}/resources/MODULE_NAME.properties +0 -0
  59. /package/{jsx → template/settings}/resources/MODULE_NAME_fr.properties +0 -0
  60. /package/{jsx → template}/src/client/index.jsx +0 -0
  61. /package/{jsx → template}/src/server/components/index.js +0 -0
  62. /package/{jsx → template}/src/server/index.js +0 -0
  63. /package/{jsx → template}/src/server/templates/index.js +0 -0
  64. /package/{jsx → template}/src/server/templates/page/index.js +0 -0
  65. /package/{jsx → template}/src/server/views/hello/index.js +0 -0
  66. /package/{jsx → template}/src/server/views/index.js +0 -0
  67. /package/{handlebars → template}/yarn.lock +0 -0
package/.yarnrc.yml ADDED
@@ -0,0 +1,3 @@
1
+ nodeLinker: node-modules
2
+
3
+ yarnPath: .yarn/releases/yarn-4.5.0.cjs
package/README.md CHANGED
@@ -4,7 +4,12 @@ This project provides an NPM/NPX starter project template to quickly get up and
4
4
 
5
5
  ## Usage
6
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
7
+ npx @jahia/create-module@latest project-name [module-type] [namespace-definitions]
8
+
9
+ where
10
+ - `project-name` (mandatory) can be anything you want to call your project
11
+ - `module-type` (optional) Can be one of:
12
+ - `templatesSet`: A collection of templates and components. A template set is required when creating a website.
13
+ - `module`: Standard Jahia module. This is the default value.
14
+ - `system`: Critical module for the whole platform.
15
+ - `namespace-definitions` (optional) The namespace used for content definitions. Default is the project name in camel case.
package/index.js CHANGED
@@ -5,53 +5,49 @@
5
5
  import fs from 'fs';
6
6
  import path from 'path';
7
7
  import {fileURLToPath} from 'url';
8
- import replace from 'replace-in-file';
8
+ import {replaceInFileSync} from 'replace-in-file';
9
9
  import camelCase from 'camelcase';
10
10
  import {execSync} from 'child_process';
11
11
 
12
12
  const __filename = fileURLToPath(import.meta.url);
13
13
  const __dirname = path.dirname(__filename);
14
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]');
15
+ // Show help if no argment is provided
16
+ // eslint-disable-next-line no-unused-vars
17
+ const [nodeCommand, npxCommand, projectName, moduleType = 'module', namespace = camelCase(projectName)] = process.argv;
18
+
19
+ if (!projectName) {
20
+ console.log(`\x1B[1m## Usage\x1B[0m
21
+
22
+ npx @jahia/create-module@latest project-name [module-type] [namespace-definitions]
23
+
24
+ where
25
+ - \x1B[1mproject-name\x1B[0m (mandatory) can be anything you want to call your project
26
+ - \x1B[1mmodule-type\x1B[0m (optional) Can be one of:
27
+ - \x1B[3mtemplatesSet\x1B[0m A collection of templates and components. A template set is required when creating a website.
28
+ - \x1B[3mmodule\x1B[0m sStandard Jahia module. This is the default value.
29
+ - \x1B[3msystem\x1B[0m Critical module for the whole platform .
30
+ - \x1B[1mnamespace-definitions\x1B[0m (optional) The namespace used for content definitions. Default is the project name in camel case.
31
+ `);
20
32
  process.exit(9);
21
33
  }
22
34
 
23
- const projectName = process.argv[2];
24
- const camelProjectName = camelCase(projectName);
25
-
26
35
  // First let's do some version checks
27
36
  console.log('Node version detected:', process.versions.node);
28
37
  const yarnVersion = execSync('yarn --version', {encoding: 'utf8'});
29
38
  console.log('Yarn version:', yarnVersion);
30
39
 
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
40
  // Create a project directory with the project name.
47
41
  const currentDir = process.cwd();
48
42
  const projectDir = path.resolve(currentDir, projectName);
49
43
  fs.mkdirSync(projectDir, {recursive: true});
50
44
 
45
+ console.log(`Creating a new Jahia module project \x1B[1m${projectName}\x1B[0m of type \x1B[1m${moduleType}\x1B[0m and definitions namespace \x1B[1m${namespace}\x1B[0m`);
46
+
51
47
  // A common approach to building a starter template is to
52
48
  // create a `template` folder which will house the template
53
49
  // and the files we want to create.
54
- const templateDir = path.resolve(__dirname, projectType);
50
+ const templateDir = path.resolve(__dirname, 'template');
55
51
  fs.cpSync(templateDir, projectDir, {recursive: true});
56
52
 
57
53
  // It is good practice to have dotfiles stored in the
@@ -78,23 +74,15 @@ fs.renameSync(
78
74
 
79
75
  // Rename the resource file to use the project name
80
76
  fs.renameSync(
81
- path.join(projectDir, 'resources/MODULE_NAME.properties'),
82
- path.join(projectDir, 'resources/' + projectName + '.properties')
77
+ path.join(projectDir, 'settings/resources/MODULE_NAME.properties'),
78
+ path.join(projectDir, 'settings/resources/' + projectName + '.properties')
83
79
  );
84
80
 
85
81
  fs.renameSync(
86
- path.join(projectDir, 'resources/MODULE_NAME_fr.properties'),
87
- path.join(projectDir, 'resources/' + projectName + '_fr.properties')
82
+ path.join(projectDir, 'settings/resources/MODULE_NAME_fr.properties'),
83
+ path.join(projectDir, 'settings/resources/' + projectName + '_fr.properties')
88
84
  );
89
85
 
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
86
  // Create empty directories for static resources and configurations
99
87
  fs.mkdirSync(path.join(projectDir, 'css'), {recursive: true});
100
88
  fs.mkdirSync(path.join(projectDir, 'images'), {recursive: true});
@@ -105,52 +93,31 @@ fs.mkdirSync(path.join(projectDir, 'settings/jahia-content-editor-forms/forms'),
105
93
  fs.mkdirSync(path.join(projectDir, 'settings/jahia-content-editor-forms/fieldsets'), {recursive: true});
106
94
 
107
95
  // 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
- }
96
+ const targetFiles = `${projectDir}/**`;
127
97
 
128
98
  try {
129
- replace.sync({
99
+ replaceInFileSync({
130
100
  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)
101
+ from: /\$\$MODULE_TYPE\$\$/g,
102
+ to: camelCase(moduleType)
134
103
  });
135
104
 
136
- replace.sync({
105
+ replaceInFileSync({
137
106
  files: targetFiles,
138
107
  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)
108
+ to: projectName
141
109
  });
142
110
 
143
- replace.sync({
111
+ replaceInFileSync({
144
112
  files: targetFiles,
145
113
  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)
114
+ to: namespace
148
115
  });
149
116
  } catch (error) {
150
117
  console.error('Error occurred:', error);
151
118
  }
152
119
 
153
- console.log(`Created ${projectName} at ${projectDir}`);
120
+ console.log(`Created \x1B[1m${projectName}\x1B[0m at \x1B[1m${projectDir}\x1B[0m`);
154
121
  console.log('Success! Your new project is ready.');
155
122
  console.log('You can now change into your project and launch "yarn" to install everything to get started.');
156
123
  console.log('---');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/create-module",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": "./index.js",
@@ -19,13 +19,13 @@
19
19
  "dependencies": {
20
20
  "camelcase": "^8.0.0",
21
21
  "path": "^0.12.7",
22
- "replace-in-file": "^7.0.1",
22
+ "replace-in-file": "^8.2.0",
23
23
  "semver": "^7.5.4",
24
24
  "url": "^0.11.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@jahia/eslint-config": "^2.1.2",
28
- "@jahia/scripts": "^1.3.3",
28
+ "@jahia/scripts": "^1.3.5",
29
29
  "eslint": "^8.43.0",
30
30
  "eslint-plugin-jest": "latest",
31
31
  "eslint-plugin-react": "latest",
@@ -34,14 +34,11 @@
34
34
  "scripts": {
35
35
  "lint": "eslint .",
36
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"
37
+ "test": "rm -rf test-project && node index.js test-project && cd test-project && yarn && yarn build && yarn lint && yarn test && cd .."
41
38
  },
42
39
  "engines": {
43
- "node": ">=16.0.0",
44
- "yarn": ">=3.0.0"
40
+ "node": ">=18.0.0",
41
+ "yarn": ">=4.0.0"
45
42
  },
46
- "packageManager": "yarn@4.1.1"
43
+ "packageManager": "yarn@4.5.0"
47
44
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ "@babel/preset-react"
5
+ ],
6
+ "plugins": [
7
+ "styled-jsx/babel"
8
+ ]
9
+ }