@jahia/create-module 0.5.6 → 0.6.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.
package/README.md CHANGED
@@ -1,16 +1,15 @@
1
- # Javascript Module template create-module project
1
+ # @jahia/create-module
2
2
 
3
- This project provides a Javascript module starter project template to quickly get up and running to create Jahia Javascript modules
3
+ This CLI scaffolds a new Jahia JavaScript module.
4
4
 
5
5
  ## Usage
6
6
 
7
- npx @jahia/create-module@latest project-name [module-type] [namespace-definitions]
7
+ To create a new module, run:
8
8
 
9
- where
9
+ ```
10
+ npm init @jahia/module@latest <module-name>
11
+ ```
10
12
 
11
- - `project-name` (mandatory) can be anything you want to call your project
12
- - `module-type` (optional) Can be one of:
13
- - `templatesSet`: A collection of templates and components. A template set is required when creating a website.
14
- - `module`: Standard Jahia module. This is the default value.
15
- - `system`: Critical module for the whole platform.
16
- - `namespace-definitions` (optional) The namespace used for content definitions. Default is the project name in camel case.
13
+ It creates a new JavaScript Module in a directory named `module-name` in the current working directory.
14
+
15
+ See the [Getting Started guide](https://github.com/Jahia/javascript-modules/tree/main/docs/1-getting-started/1-dev-environment#create-a-new-project) for more information.
package/index.js CHANGED
@@ -26,7 +26,7 @@ Upgrade guide: ${styleText("underline", "https://nodejs.org/en/download")}
26
26
  console.error(
27
27
  `No module name provided.
28
28
 
29
- Usage: npm init @jahia/module ${styleText("blueBright", "<module-name>")}
29
+ Usage: npm init @jahia/module@latest ${styleText("blueBright", "<module-name>")}
30
30
 
31
31
  It will create a new module at this location with the provided name:
32
32
 
@@ -82,7 +82,7 @@ Next steps:
82
82
  "# Commit all files",
83
83
  )}
84
84
  ${styleText("magentaBright", "code .")} ${styleText("dim", "# Open the project in VSCode")}
85
- ${styleText("magentaBright", "yarn dev")} ${styleText("dim", "# Start the development server")}
85
+ ${styleText("magentaBright", "yarn build && yarn dev")} ${styleText("dim", "# Build and start the dev mode")}
86
86
  `);
87
87
  } catch (error) {
88
88
  console.error(
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@jahia/create-module",
3
- "version": "0.5.6",
3
+ "version": "0.6.1",
4
4
  "keywords": [
5
5
  "template"
6
6
  ],
7
- "homepage": "https://github.com/Jahia/javascript-modules/javascript-create-module",
7
+ "homepage": "https://github.com/Jahia/javascript-modules/tree/main/javascript-create-module#readme",
8
8
  "bugs": {
9
9
  "url": "https://github.com/Jahia/javascript-modules/issues"
10
10
  },
@@ -1,39 +1,24 @@
1
- # Jahia Javascript Module
1
+ # Welcome!
2
2
 
3
- A simple Jahia Javascript module created using the Javascript module starter project template
3
+ Your JavaScript module was successfully created. If this is your first time creating a module, you may want to consult the [Getting Started guide](https://github.com/Jahia/javascript-modules/tree/main/docs/1-getting-started/1-dev-environment#create-a-new-project).
4
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.
12
-
13
- ## Prerequisites
14
-
15
- Yarn is required to build the project.
5
+ This README assumes you have a working development environment with Node.js, Yarn and Docker installed and configured. Please refer to the [Getting Started](https://github.com/Jahia/javascript-modules/tree/main/docs/1-getting-started/1-dev-environment#pre-requisites) guide if you need help setting up your environment.
16
6
 
17
- Please follow the instructions at [Node.js Downloads](https://nodejs.org/en/download) to install Node.js and Yarn. In the dropdown menus, make sure to select Yarn (the _with_) and your operating system (the _for_).
7
+ ## Scripts
18
8
 
19
- Note: If you are using a Windows machine, you need to run your `yarn` commands in PowerShell (not cmd.exe!). It comes preinstalled on modern Windows versions. In case this is not the case on your machine, [please see Microsoft documentation](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.5).
9
+ This module comes with some scripts to help you develop your module. You can run them with `yarn <script>`:
20
10
 
21
- ## Development
11
+ | Category | Script | Description |
12
+ | ------------ | --------------------- | ----------------------------------------------------------------------- |
13
+ | Build | `build` | Produces a deployable artifact that can be uploaded to a Jahia instance |
14
+ | Build | `deploy` | Pushes the build artifact to a Jahia instance |
15
+ | Development | `dev` (alias `watch`) | Watches for changes and rebuilds the module |
16
+ | Code quality | `format` | Runs Prettier (a code formatter) on your code |
17
+ | Code quality | `lint` | Runs ESLint (a linter) on your code |
18
+ | Utils | `clean` | Removes build artifacts |
19
+ | Utils | `package` | Packs distributions files in a `.tgz` archive inside the `dist/` folder |
20
+ | Utils | `watch:callback` | Called every time a build succeeds in watch mode |
22
21
 
23
- 1. To compile and package the project:
24
-
25
- ```
26
- yarn build
27
- ```
28
-
29
- 2. To deploy the generated package to your Jahia instance (configured in your [`.env`](.env)):
30
-
31
- ```
32
- yarn deploy
33
- ```
34
-
35
- 3. Alternatively, to deploy during development using watch mode:
22
+ ## Configuration
36
23
 
37
- ```
38
- yarn watch
39
- ```
24
+ If you don't use default configuration for the Docker container name or for Jahia deployments, please modify the provided `.env` file
@@ -1,12 +1,14 @@
1
1
  <jnt = 'http://www.jahia.org/jahia/nt/1.0'>
2
2
  <jmix = 'http://www.jahia.org/jahia/mix/1.0'>
3
3
  <$MODULE = 'https://example.com/$MODULE/1.0'>
4
+ <$MODULEmix = 'https://example.com/$MODULEmix/1.0'>
4
5
 
5
6
  // Defining the content types is similar to defining a data model: once deployed, you cannot change the type of a property.
6
7
  // If you need to do changes during the development phase, it is possible to remove the definitions from the tools:
7
8
  // http://localhost:8080/cms/login?redirect=/modules/tools/definitionsBrowser.jsp however that will remove content created with this type.
8
- // Learn more about content types definitions here: https://academy.jahia.com/developer/content-types"
9
+ // Learn more about content types definitions here:
10
+ // https://github.com/Jahia/javascript-modules/tree/main/docs/3-reference/1-cnd-format/
9
11
 
10
12
  // This mixin creates a category to regroup types in the content type selector UI. Apply it to any definition you want
11
13
  // to see in this category.
12
- [$MODULE:component] > jmix:droppableContent, jmix:accessControllableContent mixin
14
+ [$MODULEmix:component] > jmix:droppableContent, jmix:accessControllableContent mixin
@@ -26,7 +26,7 @@
26
26
  jcr:mixinTypes="jmix:isAreaList"
27
27
  jcr:primaryType="jnt:contentList"
28
28
  >
29
- <hello-world jcr:primaryType="$MODULE:HelloWorld">
29
+ <hello-world jcr:primaryType="$MODULE:helloWorld">
30
30
  <j:translation_en
31
31
  jcr:language="en"
32
32
  jcr:primaryType="jnt:translation"
@@ -38,7 +38,7 @@
38
38
  name="le monde"
39
39
  />
40
40
  <read-the-documentation
41
- jcr:primaryType="$MODULE:HelloCard"
41
+ jcr:primaryType="$MODULE:helloCard"
42
42
  illustration="read"
43
43
  >
44
44
  <j:translation_en
@@ -53,7 +53,7 @@
53
53
  />
54
54
  </read-the-documentation>
55
55
  <code-a-new-component
56
- jcr:primaryType="$MODULE:HelloCard"
56
+ jcr:primaryType="$MODULE:helloCard"
57
57
  illustration="code"
58
58
  >
59
59
  <j:translation_en
@@ -68,7 +68,7 @@
68
68
  />
69
69
  </code-a-new-component>
70
70
  <explore-the-interface
71
- jcr:primaryType="$MODULE:HelloCard"
71
+ jcr:primaryType="$MODULE:helloCard"
72
72
  illustration="interface"
73
73
  >
74
74
  <j:translation_en
@@ -83,7 +83,7 @@
83
83
  />
84
84
  </explore-the-interface>
85
85
  <create-content
86
- jcr:primaryType="$MODULE:HelloCard"
86
+ jcr:primaryType="$MODULE:helloCard"
87
87
  illustration="write"
88
88
  >
89
89
  <j:translation_en
@@ -1,15 +1,15 @@
1
1
  $MODULE_component=$MODULE - Components
2
2
 
3
- $MODULE_HelloWorld=Hello World
4
- $MODULE_HelloWorld.name=Name
3
+ $MODULE_helloWorld=Hello World
4
+ $MODULE_helloWorld.name=Name
5
5
 
6
- $MODULE_HelloCard=Hello Card
7
- $MODULE_HelloCard.title=Title
8
- $MODULE_HelloCard.illustration=Illustration
9
- $MODULE_HelloCard.illustration.code=A developer coding
10
- $MODULE_HelloCard.illustration.coffee=Buying coffee
11
- $MODULE_HelloCard.illustration.interface=Consulting an interface
12
- $MODULE_HelloCard.illustration.read=Looking at a bookshelf
13
- $MODULE_HelloCard.illustration.write=Writing with a typewriter
6
+ $MODULE_helloCard=Hello Card
7
+ $MODULE_helloCard.title=Title
8
+ $MODULE_helloCard.illustration=Illustration
9
+ $MODULE_helloCard.illustration.code=A developer coding
10
+ $MODULE_helloCard.illustration.coffee=Buying coffee
11
+ $MODULE_helloCard.illustration.interface=Consulting an interface
12
+ $MODULE_helloCard.illustration.read=Looking at a bookshelf
13
+ $MODULE_helloCard.illustration.write=Writing with a typewriter
14
14
 
15
- $MODULE_LanguageSwitcher=Language Switcher
15
+ $MODULE_languageSwitcher=Language Switcher
@@ -1,15 +1,15 @@
1
1
  $MODULE_component=$MODULE - Composants
2
2
 
3
- $MODULE_HelloWorld=Bienvenue
4
- $MODULE_HelloWorld.name=Nom
3
+ $MODULE_helloWorld=Bienvenue
4
+ $MODULE_helloWorld.name=Nom
5
5
 
6
- $MODULE_HelloCard=Carte de bienvenue
7
- $MODULE_HelloCard.title=Titre
8
- $MODULE_HelloCard.illustration=Illustration
9
- $MODULE_HelloCard.illustration.code=Un développeur qui code
10
- $MODULE_HelloCard.illustration.coffee=Acheter un café
11
- $MODULE_HelloCard.illustration.interface=Observer une interface
12
- $MODULE_HelloCard.illustration.read=Consulter une bibliothèque
13
- $MODULE_HelloCard.illustration.write=Écrire avec une machine à écrire
6
+ $MODULE_helloCard=Carte de bienvenue
7
+ $MODULE_helloCard.title=Titre
8
+ $MODULE_helloCard.illustration=Illustration
9
+ $MODULE_helloCard.illustration.code=Un développeur qui code
10
+ $MODULE_helloCard.illustration.coffee=Acheter un café
11
+ $MODULE_helloCard.illustration.interface=Observer une interface
12
+ $MODULE_helloCard.illustration.read=Consulter une bibliothèque
13
+ $MODULE_helloCard.illustration.write=Écrire avec une machine à écrire
14
14
 
15
- $MODULE_LanguageSwitcher=Changeur de langue
15
+ $MODULE_languageSwitcher=Changeur de langue
@@ -1,16 +1,15 @@
1
- import { jahiaComponent, useUrlBuilder } from "@jahia/javascript-modules-library";
1
+ import { buildModuleFileUrl, jahiaComponent } from "@jahia/javascript-modules-library";
2
2
  import classes from "./component.module.css";
3
3
 
4
4
  jahiaComponent(
5
5
  {
6
- nodeType: "$MODULE:HelloCard",
6
+ nodeType: "$MODULE:helloCard",
7
7
  componentType: "view",
8
8
  },
9
9
  ({ illustration, title }: { illustration: string; title: string }) => {
10
- const { buildStaticUrl } = useUrlBuilder();
11
10
  return (
12
11
  <article className={classes.card}>
13
- <img src={buildStaticUrl({ assetPath: `illustrations/${illustration}.svg` })} alt="" />
12
+ <img src={buildModuleFileUrl(`static/illustrations/${illustration}.svg`)} alt="" />
14
13
  <p>{title}</p>
15
14
  </article>
16
15
  );
@@ -1,3 +1,3 @@
1
- [$MODULE:HelloCard] > $MODULE:component, jnt:content
1
+ [$MODULE:helloCard] > jnt:content, $MODULEmix:component
2
2
  - illustration (string, choicelist[resourceBundle]) mandatory < code, coffee, interface, read, write
3
3
  - title (string) i18n mandatory primary
@@ -66,7 +66,8 @@
66
66
  font-weight: bold;
67
67
  cursor: pointer;
68
68
 
69
- &:hover, &:focus {
69
+ &:hover,
70
+ &:focus {
70
71
  transform: scale(1.1);
71
72
  box-shadow: 0 0.25rem 1rem 0 #4884;
72
73
  }
@@ -1,10 +1,8 @@
1
1
  import {
2
- AddContentButtons,
3
2
  HydrateInBrowser,
4
- Render,
5
- getChildNodes,
3
+ RenderChildren,
4
+ buildModuleFileUrl,
6
5
  jahiaComponent,
7
- useUrlBuilder,
8
6
  } from "@jahia/javascript-modules-library";
9
7
  import { t } from "i18next";
10
8
  import { Trans } from "react-i18next";
@@ -13,12 +11,11 @@ import classes from "./component.module.css";
13
11
 
14
12
  jahiaComponent(
15
13
  {
16
- nodeType: "$MODULE:HelloWorld",
14
+ nodeType: "$MODULE:helloWorld",
17
15
  displayName: "Hello World Component",
18
16
  componentType: "view",
19
17
  },
20
- ({ name }: { name: string }, { renderContext, currentNode }) => {
21
- const { buildStaticUrl } = useUrlBuilder();
18
+ ({ name }: { name: string }, { renderContext }) => {
22
19
  return (
23
20
  <>
24
21
  <section className={classes.section}>
@@ -33,7 +30,7 @@ jahiaComponent(
33
30
  {renderContext.isEditMode() && (
34
31
  <div className={classes.hint} style={{ alignItems: "center" }}>
35
32
  <img
36
- src={buildStaticUrl({ assetPath: "arrows/left.svg" })}
33
+ src={buildModuleFileUrl("static/arrows/left.svg")}
37
34
  alt="←"
38
35
  width="80"
39
36
  height="16"
@@ -44,13 +41,7 @@ jahiaComponent(
44
41
  </header>
45
42
  <p>{t("7l9zetMbU4cKpL4NxSOtL")}</p>
46
43
  <div className={classes.grid}>
47
- {getChildNodes(currentNode, -1, 0, (node) => node.isNodeType("jnt:content")).map(
48
- (node) => (
49
- // @ts-expect-error Fix the types
50
- <Render key={node.getIdentifier()} node={node} />
51
- ),
52
- )}
53
- <AddContentButtons />
44
+ <RenderChildren />
54
45
  </div>
55
46
 
56
47
  <p className={classes.attribution}>
@@ -71,7 +62,7 @@ jahiaComponent(
71
62
  {renderContext.isEditMode() && (
72
63
  <div className={classes.hint} style={{ marginLeft: "calc(50% - 0.5rem)" }}>
73
64
  <img
74
- src={buildStaticUrl({ assetPath: "arrows/bottom.svg" })}
65
+ src={buildModuleFileUrl("static/arrows/down.svg")}
75
66
  alt="↓"
76
67
  width="70"
77
68
  height="100"
@@ -1,3 +1,3 @@
1
- [$MODULE:HelloWorld] > $MODULE:component, jnt:content orderable
1
+ [$MODULE:helloWorld] > jnt:content, $MODULEmix:component orderable
2
2
  - name (string) i18n mandatory
3
- + * ($MODULE:HelloCard) = $MODULE:HelloCard
3
+ + * ($MODULE:helloCard) = $MODULE:helloCard
@@ -1,4 +1,4 @@
1
- import { buildUrl, jahiaComponent } from "@jahia/javascript-modules-library";
1
+ import { buildNodeUrl, getSiteLocales, jahiaComponent } from "@jahia/javascript-modules-library";
2
2
  import { t } from "i18next";
3
3
  import { Fragment } from "react";
4
4
  import classes from "./component.module.css";
@@ -6,26 +6,18 @@ import classes from "./component.module.css";
6
6
  jahiaComponent(
7
7
  {
8
8
  componentType: "view",
9
- nodeType: "$MODULE:LanguageSwitcher",
9
+ nodeType: "$MODULE:languageSwitcher",
10
10
  displayName: "Language Switcher",
11
11
  // Disable cache for this component
12
12
  properties: { "cache.timeout": "0" },
13
13
  },
14
- (_, { renderContext, mainNode, currentResource }) => {
15
- const locales = renderContext.isLiveMode()
16
- ? renderContext.getSite().getActiveLiveLanguagesAsLocales()
17
- : renderContext.getSite().getLanguagesAsLocales();
18
- const currentLanguage = currentResource.getLocale().getLanguage();
14
+ (_, { mainNode, currentResource }) => {
15
+ const currentLanguage = currentResource.getLocale().toString();
19
16
  return (
20
17
  <p style={{ textAlign: "center" }}>
21
18
  {t("JI87mYV8J5pAEST4RIUcb")}{" "}
22
- {locales.map((locale, i) => {
23
- const language = locale.getLanguage();
24
- const href = buildUrl(
25
- { path: mainNode.getPath(), language },
26
- renderContext,
27
- currentResource,
28
- );
19
+ {Object.entries(getSiteLocales()).map(([language, locale], i, { length }) => {
20
+ const href = buildNodeUrl(mainNode, { language });
29
21
  return (
30
22
  <Fragment key={language}>
31
23
  <a
@@ -35,7 +27,7 @@ jahiaComponent(
35
27
  >
36
28
  {locale.getDisplayLanguage(locale)}
37
29
  </a>
38
- {i < locales.length - 1 && " • "}
30
+ {i < length - 1 && " • "}
39
31
  </Fragment>
40
32
  );
41
33
  })}
@@ -1 +1 @@
1
- [$MODULE:LanguageSwitcher] > $MODULE:component, jnt:content
1
+ [$MODULE:languageSwitcher] > jnt:content, $MODULEmix:component
@@ -1,4 +1,8 @@
1
- import { AddResources, useServerContext, useUrlBuilder } from "@jahia/javascript-modules-library";
1
+ import {
2
+ AddResources,
3
+ buildModuleFileUrl,
4
+ useServerContext,
5
+ } from "@jahia/javascript-modules-library";
2
6
  import type { ReactNode } from "react";
3
7
 
4
8
  import "modern-normalize/modern-normalize.css";
@@ -6,16 +10,12 @@ import "./global.css";
6
10
 
7
11
  /** Places `children` in an html page. */
8
12
  export const Layout = ({ title, children }: { title: string; children: ReactNode }) => {
9
- const { buildStaticUrl } = useUrlBuilder();
10
13
  const { currentResource } = useServerContext();
11
14
  const lang = currentResource.getLocale().getLanguage();
12
15
  return (
13
16
  <html lang={lang}>
14
17
  <head>
15
- <AddResources
16
- type="css"
17
- resources={buildStaticUrl({ assetPath: "../dist/server/style.css" })}
18
- />
18
+ <AddResources type="css" resources={buildModuleFileUrl("dist/server/style.css")} />
19
19
  <title>{title}</title>
20
20
  </head>
21
21
  <body>{children}</body>
@@ -0,0 +1,15 @@
1
+ import { jahiaComponent, Render } from "@jahia/javascript-modules-library";
2
+ import { Layout } from "../Layout.jsx";
3
+
4
+ jahiaComponent(
5
+ {
6
+ componentType: "template",
7
+ nodeType: "jmix:mainResource",
8
+ priority: -1, // allow to overwrite this template by defining a component with a higher priority. When not specified, the default priority is 0
9
+ },
10
+ ({ "jcr:title": title }, { currentNode }) => (
11
+ <Layout title={title}>
12
+ <Render node={currentNode} view="fullPage" />
13
+ </Layout>
14
+ ),
15
+ );
@@ -1,12 +1,12 @@
1
1
  import { Area, jahiaComponent } from "@jahia/javascript-modules-library";
2
- import { Layout } from "./Layout.jsx";
2
+ import { Layout } from "../Layout.jsx";
3
3
 
4
4
  jahiaComponent(
5
5
  {
6
+ componentType: "template",
6
7
  nodeType: "jnt:page",
7
8
  name: "basic",
8
9
  displayName: "Basic page",
9
- componentType: "template",
10
10
  },
11
11
  ({ "jcr:title": title }) => (
12
12
  <Layout title={title}>
@@ -4,6 +4,7 @@
4
4
 
5
5
  body {
6
6
  background: #fff;
7
+ line-height: 1.5;
7
8
  }
8
9
 
9
10
  a {
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  },
23
23
  // This function is called every time a build succeeds in watch mode
24
24
  watchCallback() {
25
- spawnSync("yarn", ["watch:callback"], { stdio: "inherit" });
25
+ spawnSync("yarn", ["watch:callback"], { stdio: "inherit", shell: true });
26
26
  },
27
27
  }),
28
28
  ],
File without changes