Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ changelog:
- fix
- title: Other Changes
labels:
- "*"
- "*"
4 changes: 2 additions & 2 deletions .github/workflows/delivery-pr-chores.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
- opened
- reopened
- edited
- synchronize
- synchronize
pull_request_review:

jobs:
WF:
uses: Jahia/jahia-modules-action/.github/workflows/reusable-delivery-pr-chores.yml@v2
secrets: inherit
secrets: inherit
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pluginCypress from "eslint-plugin-cypress/flat";
export default tseslint.config(
{
languageOptions: {
globals: { ...globals.browser, ...globals.node },
globals: { ...globals.browser, ...globals.jest, ...globals.node },
},
},

Expand Down
17 changes: 17 additions & 0 deletions javascript-create-module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Intellij
.idea/
*.iml
*.ipr

node_modules/
**.tgz

#Yarn
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
yarn-error.log
21 changes: 21 additions & 0 deletions javascript-create-module/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Jahia Forge - Code Repository

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions javascript-create-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Javascript Module template create-module project

This project provides a Javascript module starter project template to quickly get up and running to create Jahia Javascript modules

## Usage

npx @jahia/create-module@latest project-name [module-type] [namespace-definitions]

where

- `project-name` (mandatory) can be anything you want to call your project
- `module-type` (optional) Can be one of:
- `templatesSet`: A collection of templates and components. A template set is required when creating a website.
- `module`: Standard Jahia module. This is the default value.
- `system`: Critical module for the whole platform.
- `namespace-definitions` (optional) The namespace used for content definitions. Default is the project name in camel case.
3 changes: 3 additions & 0 deletions javascript-create-module/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["@babel/preset-env", "@babel/preset-react"],
};
155 changes: 155 additions & 0 deletions javascript-create-module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env node

// Usage: npx @jahia/create-module@latest module-name [namespace]

import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { replaceInFileSync } from "replace-in-file";
import camelCase from "camelcase";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Show help if no argument is provided
const [
,
,
projectName,
moduleType = "module",
namespace = camelCase(projectName || ""),
] = process.argv;

if (!projectName) {
console.log(`\x1B[1m## Usage\x1B[0m

npx @jahia/create-module@latest project-name [module-type] [namespace-definitions]

where
- \x1B[1mproject-name\x1B[0m (mandatory) can be anything you want to call your project
- \x1B[1mmodule-type\x1B[0m (optional) Can be one of:
- \x1B[3mtemplatesSet\x1B[0m A collection of templates and components. A template set is required when creating a website.
- \x1B[3mmodule\x1B[0m sStandard Jahia module. This is the default value.
- \x1B[3msystem\x1B[0m Critical module for the whole platform .
- \x1B[1mnamespace-definitions\x1B[0m (optional) The namespace used for content definitions. Default is the project name in camel case.
`);
process.exit(9);
}

// First let's do some version checks
console.log("Node version detected:", process.versions.node);

// Create a project directory with the project name.
const currentDir = process.cwd();
const projectDir = path.resolve(currentDir, projectName);
fs.mkdirSync(projectDir, { recursive: true });

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`,
);

// A common approach to building a starter template is to
// create a `template` folder which will house the template
// and the files we want to create.
const templateDir = path.resolve(__dirname, "template");
const isTemplatesSet = moduleType === "templatesSet";
fs.cpSync(templateDir, projectDir, {
recursive: true,
filter: (src) => {
// The file template-thumbnail.png is only used for the type templatesSet
return isTemplatesSet || src !== path.join(templateDir, "settings", "template-thumbnail.png");
},
});

// Find and replace all markers with the appropriate substitution values
// Doing it before renaming the dotfiles so they are not excluded
const targetFiles = `${projectDir}/**`;

try {
replaceInFileSync({
files: targetFiles,
from: /\$\$MODULE_TYPE\$\$/g,
to: moduleType,
});

replaceInFileSync({
files: targetFiles,
from: /\$\$MODULE_NAME\$\$/g,
to: projectName,
});

replaceInFileSync({
files: targetFiles,
from: /\$\$MODULE_NAMESPACE\$\$/g,
to: namespace,
});
} catch (error) {
console.error("Error occurred:", error);
}

// It is good practice to have dotfiles stored in the
// template without the dot (so they do not get picked
// up by the starter template repository). We can rename
// the dotfiles after we have copied them over to the
// new project directory.
fs.renameSync(path.join(projectDir, "dotgitignore"), path.join(projectDir, ".gitignore"));
fs.renameSync(path.join(projectDir, "dotnpmignore"), path.join(projectDir, ".npmignore"));
fs.renameSync(path.join(projectDir, "dotenv"), path.join(projectDir, ".env"));
fs.renameSync(path.join(projectDir, "doteslintrc.cjs"), path.join(projectDir, ".eslintrc.cjs"));

// Rename the resource file to use the project name
fs.renameSync(
path.join(projectDir, "settings", "resources", "MODULE_NAME.properties"),
path.join(projectDir, "settings", "resources", projectName + ".properties"),
);

fs.renameSync(
path.join(projectDir, "settings", "resources", "MODULE_NAME_fr.properties"),
path.join(projectDir, "settings", "resources", projectName + "_fr.properties"),
);

fs.renameSync(
path.join(projectDir, "settings", "content-types-icons", "MODULE_NAMESPACE_simpleContent.png"),
path.join(projectDir, "settings", "content-types-icons", namespace + "_simpleContent.png"),
);

// Create empty directories for static resources and configurations
fs.mkdirSync(path.join(projectDir, "static", "css"), { recursive: true });
fs.mkdirSync(path.join(projectDir, "static", "images"), { recursive: true });
fs.mkdirSync(path.join(projectDir, "static", "javascript"), { recursive: true });
fs.mkdirSync(path.join(projectDir, "settings", "configurations"), { recursive: true });
fs.mkdirSync(path.join(projectDir, "settings", "content-editor-forms"), { recursive: true });
fs.mkdirSync(path.join(projectDir, "settings", "content-editor-forms", "forms"), {
recursive: true,
});
fs.mkdirSync(path.join(projectDir, "settings", "content-editor-forms", "fieldsets"), {
recursive: true,
});

// Add an empty yarn.lock in case any parent folder is using yarn
fs.writeFileSync(path.join(projectDir, "yarn.lock"), "", "utf8");

console.log(`Created \x1B[1m${projectName}\x1B[0m at \x1B[1m${projectDir}\x1B[0m`);
console.log("Success! Your new project is ready.");
console.log(
'You can now change into your project and launch "yarn" to install everything to get started.',
);
console.log("---");
console.log("Available project scripts will then be :");
console.log(" - yarn build : build the project");
console.log(
" - yarn deploy : deploy the project. Make sure you have updated the .env file to match your setup if needed.",
);
console.log(
" - yarn watch : will build and watch for file modifications, and deploy automatically when changes are detected. Use CTRL+C to stop watching.",
);
console.log(
" - yarn lint : use to check that your code follows the recommended syntax guidelines. Append --fix to automatically fix most problems.",
);
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.",
);
console.log("---");
console.log(
"You can also check the documentation available here for more details: https://academy.jahia.com/get-started/developers/templating",
);
52 changes: 52 additions & 0 deletions javascript-create-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@jahia/javascript-create-module",
"version": "0.6.0-SNAPSHOT",
"keywords": [
"template"
],
"homepage": "https://github.com/Jahia/javascript-modules/javascript-create-module",
"bugs": {
"url": "https://github.com/Jahia/javascript-modules/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com:Jahia/javascript-modules.git",
"directory": "javascript-create-module"
},
"license": "MIT",
"author": "Jahia <support@jahia.com>",
"type": "module",
"bin": "./index.js",
"scripts": {
"lint": "yarn run --top-level lint",
"test": "jest tests/",
"build": "mkdir -p dist && yarn pack --out dist/package.tgz && publint",
"posttest": "yarn lint"
},
"jest": {
"testTimeout": 60000
},
"dependencies": {
"camelcase": "^8.0.0",
"path": "^0.12.7",
"replace-in-file": "^8.2.0",
"semver": "^7.5.4",
"url": "^0.11.1"
},
"devDependencies": {
"@jahia/eslint-config": "^2.1.2",
"@jahia/scripts": "^1.3.7",
"eslint": "^8.43.0",
"eslint-plugin-jest": "latest",
"eslint-plugin-react": "latest",
"eslint-plugin-react-hooks": "latest",
"jest": "^29.7.0",
"jest-each": "^29.7.0",
"publint": "^0.3.6",
"tar": "^7.4.3"
},
"engines": {
"node": ">=18.0.0",
"yarn": ">=4.0.0"
}
}
Loading