@pantoken/drupal 0.1.0
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 +59 -0
- package/dist/index.d.mts +56 -0
- package/dist/index.mjs +99 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @pantoken/drupal
|
|
2
|
+
|
|
3
|
+
Emit an Instructure-themed Drupal 10/11 sub-theme: the token stylesheet plus the `*.info.yml` and
|
|
4
|
+
`*.libraries.yml` a theme needs to load it. Drop the files into `themes/custom/<machine>/`.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm i @pantoken/drupal
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Also available as `pantoken/drupal`.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { toDrupalTheme } from "@pantoken/drupal";
|
|
18
|
+
|
|
19
|
+
const files = toDrupalTheme({ name: "Instructure" });
|
|
20
|
+
// [ instructure.info.yml, instructure.libraries.yml, css/tokens.css, css/pantoken-prose.css ]
|
|
21
|
+
for (const { path, content } of files) {
|
|
22
|
+
/* write `path` under themes/custom/instructure/ */
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or via the CLI, straight into a theme directory:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pantoken generate drupal --out ./themes/custom/instructure
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Output
|
|
33
|
+
|
|
34
|
+
- `<machine>.info.yml` — the theme manifest (`core_version_requirement: ^10 || ^11`), attaching the
|
|
35
|
+
`tokens` library.
|
|
36
|
+
- `<machine>.libraries.yml` — a `tokens` library that loads `css/tokens.css` and
|
|
37
|
+
`css/pantoken-prose.css`.
|
|
38
|
+
- `css/tokens.css` — the `@pantoken/css` token stylesheet, defining the `--instui-*` custom
|
|
39
|
+
properties your theme and modules consume.
|
|
40
|
+
- `css/pantoken-prose.css` — an InstUI-look stylesheet (from `@pantoken/components`) for rendered
|
|
41
|
+
content in a `.pantoken-prose` region (tables, headings, links, code).
|
|
42
|
+
|
|
43
|
+
`<machine>` is the display name lower-snake-cased (for example `Instructure` → `instructure`).
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
- **`toDrupalTheme(options?): DrupalFile[]`** — build the sub-theme files. `options` takes `name`
|
|
48
|
+
(display name, default `"Instructure"`) and `baseTheme` (default `false`).
|
|
49
|
+
- **`machineName(name): string`** — convert a display name to a Drupal machine name (`lower_snake`).
|
|
50
|
+
- **`DrupalFile`** — a generated file: `path` (theme-relative) and `content`.
|
|
51
|
+
- **`ToDrupalThemeOptions`** — the options `toDrupalTheme` accepts.
|
|
52
|
+
|
|
53
|
+
## Related
|
|
54
|
+
|
|
55
|
+
- Wraps `@pantoken/css` (the token stylesheet) and `@pantoken/components` (the content look).
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/** A generated file: a theme-relative path and its contents. */
|
|
3
|
+
interface DrupalFile {
|
|
4
|
+
path: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Convert a display name to a Drupal machine name (`lower_snake`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { machineName } from "@pantoken/drupal";
|
|
13
|
+
*
|
|
14
|
+
* machineName("Instructure"); // "instructure"
|
|
15
|
+
* machineName("My Canvas Theme"); // "my_canvas_theme"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function machineName(name: string): string;
|
|
19
|
+
/** Options for {@link toDrupalTheme}. */
|
|
20
|
+
interface ToDrupalThemeOptions {
|
|
21
|
+
/** The theme's human-readable name (default `"Instructure"`). */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** The base theme (default `false` — a standalone theme). */
|
|
24
|
+
baseTheme?: string | false;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build the files for a Drupal sub-theme that loads the Instructure tokens.
|
|
28
|
+
*
|
|
29
|
+
* @param options - {@link ToDrupalThemeOptions}.
|
|
30
|
+
* @returns The theme files, paths relative to the theme directory.
|
|
31
|
+
*
|
|
32
|
+
* @example Build and write a standalone sub-theme
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { writeFileSync, mkdirSync } from "node:fs";
|
|
35
|
+
* import { dirname, join } from "node:path";
|
|
36
|
+
* import { toDrupalTheme } from "@pantoken/drupal";
|
|
37
|
+
*
|
|
38
|
+
* const files = toDrupalTheme({ name: "Instructure" });
|
|
39
|
+
* // [ instructure.info.yml, instructure.libraries.yml, css/tokens.css, css/pantoken-prose.css ]
|
|
40
|
+
* for (const { path, content } of files) {
|
|
41
|
+
* const dest = join("./themes/custom/instructure", path);
|
|
42
|
+
* mkdirSync(dirname(dest), { recursive: true });
|
|
43
|
+
* writeFileSync(dest, content);
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Build a sub-theme on top of a base theme
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { toDrupalTheme } from "@pantoken/drupal";
|
|
50
|
+
*
|
|
51
|
+
* const files = toDrupalTheme({ name: "Instructure", baseTheme: "olivero" });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function toDrupalTheme(options?: ToDrupalThemeOptions): DrupalFile[];
|
|
55
|
+
//#endregion
|
|
56
|
+
export { DrupalFile, ToDrupalThemeOptions, machineName, toDrupalTheme };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { css } from "@pantoken/css";
|
|
2
|
+
import { proseCss } from "@pantoken/components";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* `@pantoken/drupal` — emit an Instructure-themed Drupal sub-theme.
|
|
6
|
+
*
|
|
7
|
+
* Produces the token stylesheet (from `@pantoken/css`) and an InstUI-look prose stylesheet (from
|
|
8
|
+
* `@pantoken/components`, styling content in a `.pantoken-prose` region), plus the `*.info.yml`
|
|
9
|
+
* and `*.libraries.yml` a Drupal 10/11 theme needs to load them. Drop the files into
|
|
10
|
+
* `themes/custom/<machine>/`.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Convert a display name to a Drupal machine name (`lower_snake`).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { machineName } from "@pantoken/drupal";
|
|
21
|
+
*
|
|
22
|
+
* machineName("Instructure"); // "instructure"
|
|
23
|
+
* machineName("My Canvas Theme"); // "my_canvas_theme"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function machineName(name) {
|
|
27
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "pantoken";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build the files for a Drupal sub-theme that loads the Instructure tokens.
|
|
31
|
+
*
|
|
32
|
+
* @param options - {@link ToDrupalThemeOptions}.
|
|
33
|
+
* @returns The theme files, paths relative to the theme directory.
|
|
34
|
+
*
|
|
35
|
+
* @example Build and write a standalone sub-theme
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { writeFileSync, mkdirSync } from "node:fs";
|
|
38
|
+
* import { dirname, join } from "node:path";
|
|
39
|
+
* import { toDrupalTheme } from "@pantoken/drupal";
|
|
40
|
+
*
|
|
41
|
+
* const files = toDrupalTheme({ name: "Instructure" });
|
|
42
|
+
* // [ instructure.info.yml, instructure.libraries.yml, css/tokens.css, css/pantoken-prose.css ]
|
|
43
|
+
* for (const { path, content } of files) {
|
|
44
|
+
* const dest = join("./themes/custom/instructure", path);
|
|
45
|
+
* mkdirSync(dirname(dest), { recursive: true });
|
|
46
|
+
* writeFileSync(dest, content);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Build a sub-theme on top of a base theme
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { toDrupalTheme } from "@pantoken/drupal";
|
|
53
|
+
*
|
|
54
|
+
* const files = toDrupalTheme({ name: "Instructure", baseTheme: "olivero" });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function toDrupalTheme(options = {}) {
|
|
58
|
+
const name = options.name ?? "Instructure";
|
|
59
|
+
const machine = machineName(name);
|
|
60
|
+
const baseTheme = options.baseTheme ?? false;
|
|
61
|
+
const info = [
|
|
62
|
+
`name: ${name}`,
|
|
63
|
+
"type: theme",
|
|
64
|
+
`base theme: ${baseTheme === false ? "false" : baseTheme}`,
|
|
65
|
+
"core_version_requirement: ^10 || ^11",
|
|
66
|
+
"libraries:",
|
|
67
|
+
` - ${machine}/tokens`,
|
|
68
|
+
""
|
|
69
|
+
].join("\n");
|
|
70
|
+
const libraries = [
|
|
71
|
+
"tokens:",
|
|
72
|
+
" version: 1.x",
|
|
73
|
+
" css:",
|
|
74
|
+
" theme:",
|
|
75
|
+
" css/tokens.css: {}",
|
|
76
|
+
" css/pantoken-prose.css: {}",
|
|
77
|
+
""
|
|
78
|
+
].join("\n");
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
path: `${machine}.info.yml`,
|
|
82
|
+
content: info
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
path: `${machine}.libraries.yml`,
|
|
86
|
+
content: libraries
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
path: "css/tokens.css",
|
|
90
|
+
content: css
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
path: "css/pantoken-prose.css",
|
|
94
|
+
content: proseCss({ scope: ".pantoken-prose" })
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { machineName, toDrupalTheme };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pantoken/drupal",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Emit an Instructure-themed Drupal sub-theme: token CSS plus *.info.yml and *.libraries.yml.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@pantoken/components": "0.1.0",
|
|
19
|
+
"@pantoken/css": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^24.13.3",
|
|
23
|
+
"typescript": "^6.0.3",
|
|
24
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
25
|
+
"vite-plus": "0.2.4"
|
|
26
|
+
},
|
|
27
|
+
"pantoken": {
|
|
28
|
+
"key": "drupal",
|
|
29
|
+
"kind": "subpath"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "vp pack",
|
|
33
|
+
"dev": "vp pack --watch",
|
|
34
|
+
"test": "vp test",
|
|
35
|
+
"check": "vp check"
|
|
36
|
+
}
|
|
37
|
+
}
|