@master/create-css 2.0.0-rc.88 → 3.0.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 +13 -13
- package/dist/bin/index.js +1 -2
- package/dist/constants.d.ts +10 -12
- package/dist/constants.js +21 -19
- package/dist/core.d.ts +2 -4
- package/dist/core.js +11 -10
- package/dist/index.d.ts +32 -28
- package/dist/index.js +105 -38
- package/dist/modes.d.ts +4 -7
- package/dist/modes.js +5 -11
- package/dist/transforms.d.ts +20 -19
- package/dist/transforms.js +87 -52
- package/package.json +55 -50
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ Add Master CSS to an existing project.
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm create @master/css@
|
|
8
|
+
npm create @master/css@latest -- --yes
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
or run the package directly:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npx @master/create-css@
|
|
14
|
+
npx @master/create-css@latest add --yes
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
The recommended workflow adds Master CSS to the detected framework and includes the development guardrails Master CSS expects by default:
|
|
@@ -26,46 +26,46 @@ Without `--yes`, TTY sessions ask about ESLint, MCP, AI guidance, and dependency
|
|
|
26
26
|
|
|
27
27
|
Use `--minimal` for core framework setup only, or disable individual recommended integrations with `--no-eslint`, `--no-mcp`, or `--no-ai`.
|
|
28
28
|
|
|
29
|
-
Use `--mode <mode>` when the framework integration should be configured for a specific rendering mode during setup:
|
|
29
|
+
Without `--mode`, the installer configures static rendering. Use `--mode <mode>` when the framework integration should be configured for a specific rendering mode during setup:
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
npm create @master/css@
|
|
32
|
+
npm create @master/css@latest -- --framework nextjs --mode static --yes
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
The installer accepts `static`, `runtime`, `prerender`, and `progressive` for `vite`, `react`, `react-router`, `tanstack-start`, `vue`, `nextjs`, `nuxt`, `astro`, `webpack`, `rspack`, `rsbuild`, and `lit`. The [rendering modes guide](https://css.master.co/guide/rendering-modes) explains where each integration generates CSS. `laravel` accepts `static` only; `angular` and `none` accept `static` and `runtime`. SvelteKit setup is delegated to the Svelte CLI add-on and does not accept `--mode` here.
|
|
36
36
|
|
|
37
37
|
If you do not have a project yet, create one first:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
npm create vite@latest my-app
|
|
41
41
|
cd my-app
|
|
42
|
-
npm create @master/css@
|
|
42
|
+
npm create @master/css@latest -- --yes
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## Examples
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
npx @master/create-css@
|
|
48
|
+
npx @master/create-css@latest add --yes
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
|
-
npx @master/create-css@
|
|
52
|
+
npx @master/create-css@latest add --minimal
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
|
-
npx @master/create-css@
|
|
56
|
+
npx @master/create-css@latest add --no-mcp --no-ai
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
npx @master/create-css@
|
|
60
|
+
npx @master/create-css@latest add --json --minimal --eslint
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
```bash
|
|
64
|
-
npx @master/create-css@
|
|
64
|
+
npx @master/create-css@latest add --framework nextjs --mode runtime --yes
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
npx @master/create-css@
|
|
68
|
+
npx @master/create-css@latest add --framework webpack --mode static --yes
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Supported `--framework` values:
|
|
@@ -77,5 +77,5 @@ auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astr
|
|
|
77
77
|
SvelteKit setup is delegated to the Svelte CLI add-on:
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
|
-
npx sv add @master/css-
|
|
80
|
+
npx sv add @master/css-svelte-addon
|
|
81
81
|
```
|
package/dist/bin/index.js
CHANGED
package/dist/constants.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
declare const MASTER_CSS_VERSION = "rc";
|
|
1
|
+
declare const MASTER_CSS_VERSION: string;
|
|
3
2
|
declare const MASTER_CSS_PACKAGES: {
|
|
4
3
|
readonly css: '@master/css';
|
|
5
4
|
readonly runtime: '@master/css-runtime';
|
|
6
5
|
readonly preset: '@master/css-preset';
|
|
7
6
|
readonly cli: '@master/css-cli';
|
|
8
|
-
readonly vite: '@master/css
|
|
9
|
-
readonly next: '@master/css
|
|
10
|
-
readonly nuxt: '@master/css
|
|
11
|
-
readonly astro: '@master/css
|
|
12
|
-
readonly svelte: '@master/css
|
|
13
|
-
readonly svelteAddon: '@master/css-
|
|
14
|
-
readonly webpack: '@master/css
|
|
7
|
+
readonly vite: '@master/css-vite';
|
|
8
|
+
readonly next: '@master/css-next';
|
|
9
|
+
readonly nuxt: '@master/css-nuxt';
|
|
10
|
+
readonly astro: '@master/css-astro';
|
|
11
|
+
readonly svelte: '@master/css-svelte';
|
|
12
|
+
readonly svelteAddon: '@master/css-svelte-addon';
|
|
13
|
+
readonly webpack: '@master/css-webpack';
|
|
15
14
|
readonly eslintConfig: '@master/eslint-config-css';
|
|
16
15
|
readonly mcp: '@master/css-mcp';
|
|
17
16
|
};
|
|
18
|
-
declare const CANONICAL_ESLINT_CONFIG = "import
|
|
19
|
-
declare const AGENT_RULES_BLOCK = "## Master CSS\n\n-
|
|
20
|
-
//#endregion
|
|
17
|
+
declare const CANONICAL_ESLINT_CONFIG = "import masterCSS from '@master/eslint-config-css'\n\nexport default masterCSS\n";
|
|
18
|
+
declare const AGENT_RULES_BLOCK = "## Master CSS\n\n- Read installed Master CSS versions and the active manifest before choosing matching documentation; the preview documentation is https://rc.css.master.co.\n- Use the official master-css skill for UI work. Install it for your chosen agent with: npx skills add master-co/css --skill master-css. Check its compatibility with the installed project version.\n- Inspect the framework, package manager, CSS entry, rendering mode, theme tokens, component classes, mixins, custom media, and validation commands before editing styles.\n- Prefer existing @theme tokens and native CSS in @layer defaults or @layer components. Use @utility for on-demand classes and @mixin for CSS reuse and native property names for direct declarations. Write native declarations and selectors in stylesheets.\n- Use fixed utilities such as flex and items-center, direct-value utilities such as p(16), named tokens such as bg-brand, and parenthesized native declarations such as (gap:1rem). Query the active manifest rather than guessing token values.\n- Reuse selector and conditional wrappers with @mixin, @contents and @apply; classes use @apply(--name(...)). Keep wrapper suffixes in their authored nesting order. Choose a class layer with @layer(base|defaults|components|utilities), and use outer @layer blocks in CSS.\n- Use static rendering by default, explicit CSS variables for dynamic values, and enable native pruning only when intended.\n- Use the Master CSS MCP server with project context when available. A manifest load failure is an error, never permission to switch to the preset.\n- When available, mastercss_suggest_classes proposes classes for isolated CSS declaration blocks. Preserve its remainingCss and review cascade changes; generated CSS alone does not verify browser rendering.\n- Distinguish matching, CSS value validity, and browser support; preserve unknown native CSS and report known invalid values.\n- Use ESLint for class policy diagnostics and the Master CSS Language Service for completion, hover, colors, highlighting, and directive formatting.\n- Do not invent Master CSS APIs, directives, package names, or Tailwind-style syntax.\n- Preserve semantic HTML, accessibility attributes, and behavior.\n";
|
|
21
19
|
export { AGENT_RULES_BLOCK, CANONICAL_ESLINT_CONFIG, MASTER_CSS_PACKAGES, MASTER_CSS_VERSION };
|
package/dist/constants.js
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
const MASTER_CSS_VERSION = "rc";
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const MASTER_CSS_VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version || "rc";
|
|
3
3
|
const MASTER_CSS_PACKAGES = {
|
|
4
4
|
css: "@master/css",
|
|
5
5
|
runtime: "@master/css-runtime",
|
|
6
6
|
preset: "@master/css-preset",
|
|
7
7
|
cli: "@master/css-cli",
|
|
8
|
-
vite: "@master/css
|
|
9
|
-
next: "@master/css
|
|
10
|
-
nuxt: "@master/css
|
|
11
|
-
astro: "@master/css
|
|
12
|
-
svelte: "@master/css
|
|
13
|
-
svelteAddon: "@master/css-
|
|
14
|
-
webpack: "@master/css
|
|
8
|
+
vite: "@master/css-vite",
|
|
9
|
+
next: "@master/css-next",
|
|
10
|
+
nuxt: "@master/css-nuxt",
|
|
11
|
+
astro: "@master/css-astro",
|
|
12
|
+
svelte: "@master/css-svelte",
|
|
13
|
+
svelteAddon: "@master/css-svelte-addon",
|
|
14
|
+
webpack: "@master/css-webpack",
|
|
15
15
|
eslintConfig: "@master/eslint-config-css",
|
|
16
16
|
mcp: "@master/css-mcp"
|
|
17
17
|
};
|
|
18
|
-
const CANONICAL_ESLINT_CONFIG = `import
|
|
19
|
-
import css from '@master/eslint-config-css'
|
|
18
|
+
const CANONICAL_ESLINT_CONFIG = `import masterCSS from '@master/eslint-config-css'
|
|
20
19
|
|
|
21
|
-
export default
|
|
22
|
-
...css
|
|
23
|
-
])
|
|
20
|
+
export default masterCSS
|
|
24
21
|
`;
|
|
25
22
|
const AGENT_RULES_BLOCK = `## Master CSS
|
|
26
23
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
- Use
|
|
24
|
+
- Read installed Master CSS versions and the active manifest before choosing matching documentation; the preview documentation is https://rc.css.master.co.
|
|
25
|
+
- Use the official master-css skill for UI work. Install it for your chosen agent with: npx skills add master-co/css --skill master-css. Check its compatibility with the installed project version.
|
|
26
|
+
- Inspect the framework, package manager, CSS entry, rendering mode, theme tokens, component classes, mixins, custom media, and validation commands before editing styles.
|
|
27
|
+
- Prefer existing @theme tokens and native CSS in @layer defaults or @layer components. Use @utility for on-demand classes and @mixin for CSS reuse and native property names for direct declarations. Write native declarations and selectors in stylesheets.
|
|
28
|
+
- Use fixed utilities such as flex and items-center, direct-value utilities such as p(16), named tokens such as bg-brand, and parenthesized native declarations such as (gap:1rem). Query the active manifest rather than guessing token values.
|
|
29
|
+
- Reuse selector and conditional wrappers with @mixin, @contents and @apply; classes use @apply(--name(...)). Keep wrapper suffixes in their authored nesting order. Choose a class layer with @layer(base|defaults|components|utilities), and use outer @layer blocks in CSS.
|
|
30
|
+
- Use static rendering by default, explicit CSS variables for dynamic values, and enable native pruning only when intended.
|
|
31
|
+
- Use the Master CSS MCP server with project context when available. A manifest load failure is an error, never permission to switch to the preset.
|
|
32
|
+
- When available, mastercss_suggest_classes proposes classes for isolated CSS declaration blocks. Preserve its remainingCss and review cascade changes; generated CSS alone does not verify browser rendering.
|
|
33
|
+
- Distinguish matching, CSS value validity, and browser support; preserve unknown native CSS and report known invalid values.
|
|
31
34
|
- Use ESLint for class policy diagnostics and the Master CSS Language Service for completion, hover, colors, highlighting, and directive formatting.
|
|
32
35
|
- Do not invent Master CSS APIs, directives, package names, or Tailwind-style syntax.
|
|
33
36
|
- Preserve semantic HTML, accessibility attributes, and behavior.
|
|
34
37
|
`;
|
|
35
|
-
//#endregion
|
|
36
38
|
export { AGENT_RULES_BLOCK, CANONICAL_ESLINT_CONFIG, MASTER_CSS_PACKAGES, MASTER_CSS_VERSION };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/core.d.ts
|
|
1
|
+
import { MasterCSSRenderingMode } from "@master/css-schema/integration";
|
|
3
2
|
type CommandFramework = 'none' | 'vite' | 'react' | 'react-router' | 'tanstack-start' | 'vue' | 'nextjs' | 'svelte' | 'nuxt' | 'astro' | 'webpack' | 'rspack' | 'rsbuild' | 'laravel' | 'lit' | 'angular';
|
|
4
3
|
type CommandFrameworkOption = CommandFramework | 'auto';
|
|
5
4
|
type CommandPackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
@@ -14,7 +13,7 @@ interface CommandOptions {
|
|
|
14
13
|
dryRun?: boolean;
|
|
15
14
|
json?: boolean;
|
|
16
15
|
yes?: boolean;
|
|
17
|
-
mode?:
|
|
16
|
+
mode?: MasterCSSRenderingMode;
|
|
18
17
|
}
|
|
19
18
|
type InstallResolution = CommandPackageManager | false | 'detected' | undefined;
|
|
20
19
|
type PromptQuestion = (question: string) => Promise<string>;
|
|
@@ -26,5 +25,4 @@ interface ResolvedCommandOptions {
|
|
|
26
25
|
}
|
|
27
26
|
declare function runProgram(argv?: string[]): Promise<void>;
|
|
28
27
|
declare function resolveCommandOptions(options: CommandOptions, prompt?: PromptQuestion): Promise<ResolvedCommandOptions>;
|
|
29
|
-
//#endregion
|
|
30
28
|
export { CommandOptions, InstallResolution, PromptQuestion, ResolvedCommandOptions, runProgram as default, resolveCommandOptions };
|
package/dist/core.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
+
import { MASTER_CSS_VERSION } from "./constants.js";
|
|
1
2
|
import { formatRenderingModes, isRenderingMode } from "./modes.js";
|
|
2
|
-
import {
|
|
3
|
+
import { applyMasterCSSSetupPlan, planMasterCSSSetup } from "./index.js";
|
|
3
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
5
|
import { dirname, join, resolve } from "node:path";
|
|
5
6
|
import { createInterface } from "node:readline/promises";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { Command, InvalidArgumentError } from "commander";
|
|
8
|
-
|
|
9
|
-
const
|
|
9
|
+
// src/core.ts
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
10
12
|
const pkg = JSON.parse(readFileSync(resolve(__dirname, "../package.json"), "utf8"));
|
|
11
13
|
const newProjectCommands = [
|
|
12
14
|
"npm create vite@latest my-app",
|
|
13
15
|
"cd my-app",
|
|
14
|
-
|
|
16
|
+
`npm create @master/css@${MASTER_CSS_VERSION} -- --yes`
|
|
15
17
|
];
|
|
16
18
|
async function runProgram(argv = process.argv) {
|
|
17
19
|
const program = new Command();
|
|
18
20
|
program.name("create-css").description(pkg.description).version(pkg.version || "0.0.0");
|
|
19
|
-
const configure = (command) => command.option("-C, --cwd <path>", "Project root to update.").option("--framework <framework>", "Framework: auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none.", "auto").option("--eslint", "Add the Master CSS recommended ESLint flat config.").option("--no-eslint", "Skip the Master CSS recommended ESLint flat config.").option("--mcp", "Add the Master CSS MCP package and print the stdio registration command.").option("--no-mcp", "Skip the Master CSS MCP package and registration command.").option("--ai", "Add Master CSS guidance to AGENTS.md.").option("--no-ai", "Skip Master CSS guidance for coding agents.").option("--minimal", "Only add core Master CSS framework setup.").option("--mode <mode>", `Rendering mode: ${formatRenderingModes()}.`, parseRenderingModeOption).option("--install <package-manager>", "Run dependency installation with npm, pnpm, yarn, or bun after edits.").option("--no-install", "Do not run dependency installation.").option("--dry-run", "Print the setup plan without writing files.").option("--json", "Print machine-readable JSON.").option("-y, --yes", "Accept recommended defaults and run package installation with the detected package manager.");
|
|
21
|
+
const configure = (command) => command.option("-C, --cwd <path>", "Project root to update.").option("--framework <framework>", "Framework: auto, vite, react, react-router, tanstack-start, vue, nextjs, svelte, nuxt, astro, webpack, rspack, rsbuild, laravel, lit, angular, none.", "auto").option("--eslint", "Add the Master CSS recommended ESLint flat config.").option("--no-eslint", "Skip the Master CSS recommended ESLint flat config.").option("--mcp", "Add the Master CSS MCP package and print the stdio registration command.").option("--no-mcp", "Skip the Master CSS MCP package and registration command.").option("--ai", "Add Master CSS guidance to AGENTS.md.").option("--no-ai", "Skip Master CSS guidance for coding agents.").option("--minimal", "Only add core Master CSS framework setup.").option("--mode <mode>", `Rendering mode: ${formatRenderingModes()}. Defaults to static.`, parseRenderingModeOption).option("--install <package-manager>", "Run dependency installation with npm, pnpm, yarn, or bun after edits.").option("--no-install", "Do not run dependency installation.").option("--dry-run", "Print the setup plan without writing files.").option("--json", "Print machine-readable JSON.").option("-y, --yes", "Accept recommended defaults and run package installation with the detected package manager.");
|
|
20
22
|
configure(program).argument("[project name]", "Deprecated. The installer now updates the current project; use --cwd for another root.").action(async (projectName, options) => {
|
|
21
23
|
if (projectName && projectName !== "add") program.error(`Project scaffolding is not provided by @master/create-css. Create a Vite project first, then run the installer from the project root:\n\n${formatNewProjectCommands()}`);
|
|
22
24
|
await runAdd(options);
|
|
23
25
|
});
|
|
24
|
-
configure(program.command("add").description("Add Master CSS to an existing project.")).action(runAdd);
|
|
26
|
+
configure(program.command("add").description("Add Master CSS to an existing project.")).action((_options, command) => runAdd(command.optsWithGlobals()));
|
|
25
27
|
await program.parseAsync(argv);
|
|
26
28
|
}
|
|
27
29
|
async function runAdd(options) {
|
|
@@ -52,12 +54,12 @@ async function runAdd(options) {
|
|
|
52
54
|
process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
applyMasterCSSSetupPlan(plan, { install: resolvedOptions.install === "detected" ? plan.packageManager : resolvedOptions.install });
|
|
56
58
|
if (!options.json) printSummary(plan);
|
|
57
59
|
}
|
|
58
60
|
function createCommandSetupPlan(options) {
|
|
59
61
|
try {
|
|
60
|
-
return
|
|
62
|
+
return planMasterCSSSetup(options);
|
|
61
63
|
} catch (error) {
|
|
62
64
|
if (error instanceof Error) {
|
|
63
65
|
process.stderr.write(`${error.message}\n`);
|
|
@@ -129,7 +131,6 @@ function printSummary(plan) {
|
|
|
129
131
|
process.stdout.write(`Files created: ${plan.summary.filesToCreate}\n`);
|
|
130
132
|
process.stdout.write(`Files updated: ${plan.summary.filesToUpdate}\n`);
|
|
131
133
|
for (const warning of plan.warnings) process.stdout.write(`Warning: ${warning}\n`);
|
|
132
|
-
for (const command of plan.commands) process.stdout.write(`Next: ${command.command}\n`);
|
|
134
|
+
for (const command of plan.commands) process.stdout.write(`Next: ${[command.executable, ...command.args].join(" ")}\n`);
|
|
133
135
|
}
|
|
134
|
-
//#endregion
|
|
135
136
|
export { runProgram as default, resolveCommandOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
interface SetupOptions {
|
|
1
|
+
import { MasterCSSRenderingMode } from "@master/css-schema/integration";
|
|
2
|
+
type MasterCSSSetupFramework = 'none' | 'vite' | 'react' | 'react-router' | 'tanstack-start' | 'vue' | 'nextjs' | 'svelte' | 'nuxt' | 'astro' | 'webpack' | 'rspack' | 'rsbuild' | 'laravel' | 'lit' | 'angular';
|
|
3
|
+
type MasterCSSSetupFrameworkOption = MasterCSSSetupFramework | 'auto';
|
|
4
|
+
type MasterCSSSetupPackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
5
|
+
type MasterCSSSetupFileAction = 'create' | 'update' | 'skip';
|
|
6
|
+
interface MasterCSSSetupOptions {
|
|
8
7
|
root?: string;
|
|
9
|
-
framework?:
|
|
8
|
+
framework?: MasterCSSSetupFrameworkOption;
|
|
10
9
|
eslint?: boolean;
|
|
11
10
|
mcp?: boolean;
|
|
12
11
|
ai?: boolean;
|
|
13
12
|
minimal?: boolean;
|
|
14
|
-
install?:
|
|
13
|
+
install?: MasterCSSSetupPackageManager | false;
|
|
15
14
|
yes?: boolean;
|
|
16
15
|
packageTag?: string;
|
|
17
|
-
mode?:
|
|
16
|
+
mode?: MasterCSSRenderingMode;
|
|
18
17
|
}
|
|
19
|
-
interface
|
|
18
|
+
interface MasterCSSSetupDependency {
|
|
20
19
|
name: string;
|
|
21
20
|
version: string;
|
|
22
21
|
dev: boolean;
|
|
23
22
|
}
|
|
24
|
-
interface
|
|
23
|
+
interface MasterCSSSetupFilePrecondition {
|
|
24
|
+
exists: boolean;
|
|
25
|
+
digest: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface MasterCSSSetupFileChange {
|
|
25
28
|
path: string;
|
|
26
|
-
action:
|
|
29
|
+
action: MasterCSSSetupFileAction;
|
|
27
30
|
content?: string;
|
|
28
31
|
reason: string;
|
|
32
|
+
precondition: MasterCSSSetupFilePrecondition;
|
|
29
33
|
}
|
|
30
|
-
interface
|
|
31
|
-
|
|
34
|
+
interface MasterCSSSetupCommand {
|
|
35
|
+
executable: string;
|
|
36
|
+
args: readonly string[];
|
|
32
37
|
reason: string;
|
|
33
38
|
}
|
|
34
|
-
interface
|
|
39
|
+
interface MasterCSSSetupPlan {
|
|
35
40
|
version: 1;
|
|
36
41
|
root: string;
|
|
37
|
-
framework:
|
|
38
|
-
packageManager:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
framework: MasterCSSSetupFramework;
|
|
43
|
+
packageManager: MasterCSSSetupPackageManager;
|
|
44
|
+
packageJSONPrecondition: MasterCSSSetupFilePrecondition;
|
|
45
|
+
dependencies: readonly MasterCSSSetupDependency[];
|
|
46
|
+
files: readonly MasterCSSSetupFileChange[];
|
|
47
|
+
commands: readonly MasterCSSSetupCommand[];
|
|
48
|
+
warnings: readonly string[];
|
|
49
|
+
mode?: MasterCSSRenderingMode;
|
|
44
50
|
summary: {
|
|
45
51
|
dependencies: number;
|
|
46
52
|
filesToCreate: number;
|
|
@@ -49,8 +55,6 @@ interface SetupPlan {
|
|
|
49
55
|
warnings: number;
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
|
-
declare function
|
|
53
|
-
declare function
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
export { FileAction, Framework, FrameworkOption, PackageManager, PlannedCommand, PlannedDependency, PlannedFileChange, type RenderingMode, SetupOptions, SetupPlan, applySetup, applySetupPlan, createSetupPlan };
|
|
58
|
+
declare function planMasterCSSSetup(options?: MasterCSSSetupOptions): MasterCSSSetupPlan;
|
|
59
|
+
declare function applyMasterCSSSetupPlan(plan: MasterCSSSetupPlan, options?: MasterCSSSetupOptions): void;
|
|
60
|
+
export { MasterCSSSetupCommand, MasterCSSSetupDependency, MasterCSSSetupFileAction, MasterCSSSetupFileChange, MasterCSSSetupFilePrecondition, MasterCSSSetupFramework, MasterCSSSetupFrameworkOption, MasterCSSSetupOptions, MasterCSSSetupPackageManager, MasterCSSSetupPlan, applyMasterCSSSetupPlan, planMasterCSSSetup };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import { AGENT_RULES_BLOCK, CANONICAL_ESLINT_CONFIG, MASTER_CSS_PACKAGES } from "./constants.js";
|
|
1
|
+
import { AGENT_RULES_BLOCK, CANONICAL_ESLINT_CONFIG, MASTER_CSS_PACKAGES, MASTER_CSS_VERSION } from "./constants.js";
|
|
2
|
+
import { addAngularRuntimeSetup, addGeneratedStylesheetImport, addLitShadowRuntime, addLitShadowStylesheet, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig } from "./transforms.js";
|
|
2
3
|
import { resolveRenderingMode } from "./modes.js";
|
|
3
|
-
import { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig } from "./transforms.js";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
5
|
import { spawnSync } from "node:child_process";
|
|
7
|
-
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
// src/index.ts
|
|
8
9
|
const lockfiles = {
|
|
9
|
-
pnpm: "pnpm-lock.yaml",
|
|
10
|
-
npm: "package-lock.json",
|
|
11
|
-
yarn: "yarn.lock",
|
|
12
|
-
bun: "bun.lockb"
|
|
10
|
+
pnpm: ["pnpm-lock.yaml"],
|
|
11
|
+
npm: ["package-lock.json"],
|
|
12
|
+
yarn: ["yarn.lock"],
|
|
13
|
+
bun: ["bun.lock", "bun.lockb"]
|
|
13
14
|
};
|
|
14
|
-
function
|
|
15
|
+
function planMasterCSSSetup(options = {}) {
|
|
15
16
|
const root = resolve(options.root || process.cwd());
|
|
16
17
|
const packageJSON = readPackageJSON(root);
|
|
17
18
|
const packageManager = resolvePackageManager(root, packageJSON, options.install || void 0);
|
|
18
19
|
const framework = resolveFramework(root, packageJSON, options.framework || "auto");
|
|
19
20
|
const mode = resolveRenderingMode(options.mode);
|
|
20
21
|
assertFrameworkSupportsMode(framework, mode);
|
|
21
|
-
const version = options.packageTag ||
|
|
22
|
+
const version = options.packageTag || MASTER_CSS_VERSION;
|
|
22
23
|
const eslint = resolveRecommendedOption(options.eslint, options.minimal);
|
|
23
24
|
const mcp = resolveRecommendedOption(options.mcp, options.minimal);
|
|
24
25
|
const ai = resolveRecommendedOption(options.ai, options.minimal);
|
|
@@ -27,13 +28,36 @@ function createSetupPlan(options = {}) {
|
|
|
27
28
|
const commands = [];
|
|
28
29
|
const warnings = [];
|
|
29
30
|
if (framework === "svelte") commands.push({
|
|
30
|
-
|
|
31
|
+
executable: packageManager === "pnpm" ? "pnpm" : packageManager === "yarn" ? "yarn" : packageManager === "bun" ? "bunx" : "npx",
|
|
32
|
+
args: packageManager === "pnpm" || packageManager === "yarn" ? [
|
|
33
|
+
"dlx",
|
|
34
|
+
"sv",
|
|
35
|
+
"add",
|
|
36
|
+
"@master/css-svelte-addon"
|
|
37
|
+
] : [
|
|
38
|
+
"sv",
|
|
39
|
+
"add",
|
|
40
|
+
"@master/css-svelte-addon"
|
|
41
|
+
],
|
|
31
42
|
reason: "SvelteKit file setup is delegated to the official Svelte CLI add-on."
|
|
32
43
|
});
|
|
33
44
|
else {
|
|
34
|
-
for (const dependency of dependenciesForFramework(framework, version)) pushDependency(dependencies, dependency.name, dependency.dev, dependency.version);
|
|
45
|
+
for (const dependency of dependenciesForFramework(framework, version, mode)) pushDependency(dependencies, dependency.name, dependency.dev, dependency.version);
|
|
35
46
|
files.push(...filesForFramework(root, framework, warnings, mode));
|
|
36
47
|
}
|
|
48
|
+
if ((framework === "angular" || framework === "none") && (!mode || mode === "static")) {
|
|
49
|
+
commands.push({
|
|
50
|
+
executable: "npx",
|
|
51
|
+
args: [
|
|
52
|
+
"master-css",
|
|
53
|
+
"generate",
|
|
54
|
+
"--output",
|
|
55
|
+
"src/master.generated.css"
|
|
56
|
+
],
|
|
57
|
+
reason: "Generate static CSS before the application build. Add --watch in a separate terminal during development."
|
|
58
|
+
});
|
|
59
|
+
warnings.push("Run the proposed CSS generation command after installation and before the application build; it does not run automatically.");
|
|
60
|
+
}
|
|
37
61
|
if (eslint) {
|
|
38
62
|
pushDependency(dependencies, MASTER_CSS_PACKAGES.eslintConfig, true, version);
|
|
39
63
|
pushDependency(dependencies, "eslint", true, "^9.0.0 || ^10.0.0");
|
|
@@ -42,11 +66,30 @@ function createSetupPlan(options = {}) {
|
|
|
42
66
|
if (mcp) {
|
|
43
67
|
pushDependency(dependencies, MASTER_CSS_PACKAGES.mcp, true, version);
|
|
44
68
|
commands.push({
|
|
45
|
-
|
|
69
|
+
executable: "npx",
|
|
70
|
+
args: [
|
|
71
|
+
"-y",
|
|
72
|
+
`@master/css-mcp@${version}`,
|
|
73
|
+
"--root",
|
|
74
|
+
root
|
|
75
|
+
],
|
|
46
76
|
reason: "Use this stdio command when registering the Master CSS MCP server in an MCP client."
|
|
47
77
|
});
|
|
48
78
|
}
|
|
49
|
-
if (ai)
|
|
79
|
+
if (ai) {
|
|
80
|
+
files.push(planTextFile(root, "AGENTS.md", appendAgentRules, AGENT_RULES_BLOCK, "Add Master CSS instructions for local coding agents."));
|
|
81
|
+
commands.push({
|
|
82
|
+
executable: "npx",
|
|
83
|
+
args: [
|
|
84
|
+
"skills",
|
|
85
|
+
"add",
|
|
86
|
+
"master-co/css",
|
|
87
|
+
"--skill",
|
|
88
|
+
"master-css"
|
|
89
|
+
],
|
|
90
|
+
reason: "Install the official Master CSS skill for your chosen coding agent. This command is guidance only and is not run by setup; verify skill compatibility with the installed Master CSS version."
|
|
91
|
+
});
|
|
92
|
+
}
|
|
50
93
|
if (!existsSync(join(root, "package.json"))) warnings.push("No package.json was found. Dependency changes will be skipped until a package.json exists.");
|
|
51
94
|
if (framework === "none") warnings.push("No supported framework was detected. The plan adds base Master CSS packages and a standalone stylesheet entry only.");
|
|
52
95
|
return {
|
|
@@ -54,6 +97,7 @@ function createSetupPlan(options = {}) {
|
|
|
54
97
|
root,
|
|
55
98
|
framework,
|
|
56
99
|
packageManager,
|
|
100
|
+
packageJSONPrecondition: createFilePrecondition(join(root, "package.json")),
|
|
57
101
|
dependencies,
|
|
58
102
|
files,
|
|
59
103
|
commands,
|
|
@@ -68,7 +112,8 @@ function createSetupPlan(options = {}) {
|
|
|
68
112
|
}
|
|
69
113
|
};
|
|
70
114
|
}
|
|
71
|
-
function
|
|
115
|
+
function applyMasterCSSSetupPlan(plan, options = {}) {
|
|
116
|
+
assertPlanPreconditions(plan);
|
|
72
117
|
applyDependencyChanges(plan.root, plan.dependencies);
|
|
73
118
|
for (const file of plan.files) {
|
|
74
119
|
if (file.action === "skip" || file.content === void 0) continue;
|
|
@@ -86,11 +131,6 @@ function applySetupPlan(plan, options = {}) {
|
|
|
86
131
|
if (result.status) throw new Error(`${install} install failed with exit code ${result.status}`);
|
|
87
132
|
}
|
|
88
133
|
}
|
|
89
|
-
function applySetup(options = {}) {
|
|
90
|
-
const plan = createSetupPlan(options);
|
|
91
|
-
applySetupPlan(plan, options);
|
|
92
|
-
return plan;
|
|
93
|
-
}
|
|
94
134
|
function filesForFramework(root, framework, warnings, mode) {
|
|
95
135
|
switch (framework) {
|
|
96
136
|
case "vite": return [planTextFile(root, firstExistingPath(root, [
|
|
@@ -124,7 +164,7 @@ function filesForFramework(root, framework, warnings, mode) {
|
|
|
124
164
|
return files;
|
|
125
165
|
}
|
|
126
166
|
case "tanstack-start": {
|
|
127
|
-
const pluginMode = mode ?? "
|
|
167
|
+
const pluginMode = mode ?? "static";
|
|
128
168
|
const files = [planTextFile(root, firstExistingPath(root, [
|
|
129
169
|
"vite.config.ts",
|
|
130
170
|
"vite.config.js",
|
|
@@ -164,7 +204,7 @@ function filesForFramework(root, framework, warnings, mode) {
|
|
|
164
204
|
const viteConfigPath = findExistingPath(root, ["vite.config.ts", "vite.config.js"]);
|
|
165
205
|
const files = [planTextFile(root, "resources/css/app.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Laravel Vite CSS entry.")];
|
|
166
206
|
if (viteConfigPath) files.unshift(planTextFile(root, viteConfigPath, addMasterCSSStaticVitePlugin, createStaticViteConfig(), "Register the Master CSS Vite plugin in static mode."));
|
|
167
|
-
else warnings.push("No vite.config.ts or vite.config.js was found. Add @master/css
|
|
207
|
+
else warnings.push("No vite.config.ts or vite.config.js was found. Add @master/css-vite to the Laravel Vite config manually after setup.");
|
|
168
208
|
return files;
|
|
169
209
|
}
|
|
170
210
|
case "lit": {
|
|
@@ -176,19 +216,20 @@ function filesForFramework(root, framework, warnings, mode) {
|
|
|
176
216
|
], "vite.config.ts"), (content) => addMasterCSSVitePlugin(content, mode), createViteConfig(mode), "Register the Master CSS Vite plugin."),
|
|
177
217
|
planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Lit project CSS entry."),
|
|
178
218
|
planTextFile(root, "src/vite-env.d.ts", addViteClientTypes, `/// <reference types="vite/client" />
|
|
179
|
-
/// <reference types="@master/css
|
|
219
|
+
/// <reference types="@master/css/client" />
|
|
180
220
|
`, "Add Vite and Master CSS integration client types.")
|
|
181
221
|
];
|
|
182
222
|
const elementPath = findExistingPath(root, ["src/my-element.ts", "src/my-element.js"]);
|
|
183
|
-
if (elementPath) files.push(planTextFile(root, elementPath, addLitShadowRuntime, "", "Initialize Master CSS Runtime for the Lit shadow root."));
|
|
184
|
-
else warnings.push("No standard src/my-element.ts or src/my-element.js file was found. Add
|
|
223
|
+
if (elementPath) files.push(planTextFile(root, elementPath, mode === "runtime" || mode === "progressive" ? addLitShadowRuntime : addLitShadowStylesheet, "", mode === "runtime" || mode === "progressive" ? "Initialize Master CSS Runtime for the Lit shadow root." : "Include generated CSS in the Lit shadow root."));
|
|
224
|
+
else warnings.push("No standard src/my-element.ts or src/my-element.js file was found. Add the selected mode’s CSS or runtime to each Lit shadow root using the Lit installation guide.");
|
|
185
225
|
return files;
|
|
186
226
|
}
|
|
187
227
|
case "angular": {
|
|
228
|
+
if (!mode || mode === "static") return [planTextFile(root, "master.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create the CLI source entry."), planTextFile(root, "src/styles.css", addGeneratedStylesheetImport, addGeneratedStylesheetImport(""), "Import the generated static CSS from Angular’s global stylesheet.")];
|
|
188
229
|
const files = [planTextFile(root, "src/styles.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the Angular global stylesheet entry.")];
|
|
189
230
|
const mainPath = findExistingPath(root, ["src/main.ts"]);
|
|
190
231
|
if (mainPath) files.unshift(planTextFile(root, mainPath, addAngularRuntimeSetup, "", "Initialize Master CSS Runtime in the Angular browser entry."));
|
|
191
|
-
else warnings.push("No src/main.ts file was found. Initialize
|
|
232
|
+
else warnings.push("No src/main.ts file was found. Initialize MasterCSSRuntime manually in the Angular browser entry after setup.");
|
|
192
233
|
return files;
|
|
193
234
|
}
|
|
194
235
|
case "rspack": return [planTextFile(root, firstExistingPath(root, [
|
|
@@ -211,7 +252,7 @@ function filesForFramework(root, framework, warnings, mode) {
|
|
|
211
252
|
"webpack.config.js",
|
|
212
253
|
"webpack.config.cjs"
|
|
213
254
|
], "webpack.config.mjs"), (content) => addMasterCSSWebpackPlugin(content, mode), createWebpackConfig(mode), "Register the Master CSS Webpack plugin."), planTextFile(root, "src/index.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create or update the project CSS entry for Webpack.")];
|
|
214
|
-
default: return [planTextFile(root, "
|
|
255
|
+
default: return [planTextFile(root, "master.css", addMasterCSSImportToStylesheet, createMasterCSSStylesheet(), "Create a standalone Master CSS source entry; link the generated src/master.generated.css in your application.")];
|
|
215
256
|
}
|
|
216
257
|
}
|
|
217
258
|
function assertFrameworkSupportsMode(framework, mode) {
|
|
@@ -220,9 +261,13 @@ function assertFrameworkSupportsMode(framework, mode) {
|
|
|
220
261
|
if (mode === "static") return;
|
|
221
262
|
throw new Error(`--mode ${mode} is not supported for laravel. The Laravel installer only supports --mode static.`);
|
|
222
263
|
}
|
|
223
|
-
if (framework === "angular" || framework === "
|
|
264
|
+
if (framework === "angular" || framework === "none") {
|
|
265
|
+
if (mode === "static" || mode === "runtime") return;
|
|
266
|
+
throw new Error(`--mode ${mode} is not supported for ${framework}. Use static or runtime.`);
|
|
267
|
+
}
|
|
268
|
+
if (framework === "svelte") throw new Error(`--mode is not supported for ${framework}. Supported frameworks: vite, react, react-router, tanstack-start, vue, nextjs, nuxt, astro, webpack, rspack, rsbuild, laravel, lit.`);
|
|
224
269
|
}
|
|
225
|
-
function dependenciesForFramework(framework, version) {
|
|
270
|
+
function dependenciesForFramework(framework, version, mode) {
|
|
226
271
|
const dependencies = [{
|
|
227
272
|
name: MASTER_CSS_PACKAGES.css,
|
|
228
273
|
version,
|
|
@@ -253,15 +298,15 @@ function dependenciesForFramework(framework, version) {
|
|
|
253
298
|
version,
|
|
254
299
|
dev: false
|
|
255
300
|
});
|
|
256
|
-
if (framework === "none" || framework === "lit" || framework === "angular") dependencies.push({
|
|
301
|
+
if ((framework === "none" || framework === "lit" || framework === "angular") && (mode === "runtime" || mode === "progressive")) dependencies.push({
|
|
257
302
|
name: MASTER_CSS_PACKAGES.runtime,
|
|
258
303
|
version,
|
|
259
304
|
dev: false
|
|
260
305
|
});
|
|
261
|
-
if (framework === "angular") dependencies.push({
|
|
262
|
-
name: MASTER_CSS_PACKAGES.
|
|
306
|
+
if ((framework === "none" || framework === "angular") && (!mode || mode === "static")) dependencies.push({
|
|
307
|
+
name: MASTER_CSS_PACKAGES.cli,
|
|
263
308
|
version,
|
|
264
|
-
dev:
|
|
309
|
+
dev: true
|
|
265
310
|
});
|
|
266
311
|
return dependencies;
|
|
267
312
|
}
|
|
@@ -271,7 +316,8 @@ function planTextFile(root, path, transform, createContent, reason) {
|
|
|
271
316
|
path,
|
|
272
317
|
action: "create",
|
|
273
318
|
content: createContent,
|
|
274
|
-
reason
|
|
319
|
+
reason,
|
|
320
|
+
precondition: createFilePrecondition(filePath)
|
|
275
321
|
};
|
|
276
322
|
const content = readFileSync(filePath, "utf8");
|
|
277
323
|
const nextContent = transform(content);
|
|
@@ -279,7 +325,8 @@ function planTextFile(root, path, transform, createContent, reason) {
|
|
|
279
325
|
path,
|
|
280
326
|
action: nextContent === content ? "skip" : "update",
|
|
281
327
|
...nextContent === content ? {} : { content: nextContent },
|
|
282
|
-
reason
|
|
328
|
+
reason,
|
|
329
|
+
precondition: createFilePrecondition(filePath)
|
|
283
330
|
};
|
|
284
331
|
}
|
|
285
332
|
function applyDependencyChanges(root, dependencies) {
|
|
@@ -321,7 +368,7 @@ function resolvePackageManager(root, packageJSON, explicit) {
|
|
|
321
368
|
if (isPackageManager(explicit)) return explicit;
|
|
322
369
|
const declared = packageJSON?.packageManager?.split("@")[0];
|
|
323
370
|
if (isPackageManager(declared)) return declared;
|
|
324
|
-
for (const [name, lockfile] of Object.entries(lockfiles)) if (existsSync(join(root,
|
|
371
|
+
for (const [name, lockfile] of Object.entries(lockfiles)) if (lockfile.some((file) => existsSync(join(root, file)))) return name;
|
|
325
372
|
return "npm";
|
|
326
373
|
}
|
|
327
374
|
function resolveFramework(root, packageJSON, framework) {
|
|
@@ -360,5 +407,25 @@ function appendAgentRules(content) {
|
|
|
360
407
|
if (content.includes("## Master CSS")) return content;
|
|
361
408
|
return `${content.trimEnd()}${content.trim() ? "\n\n" : ""}${AGENT_RULES_BLOCK}`;
|
|
362
409
|
}
|
|
363
|
-
|
|
364
|
-
|
|
410
|
+
function digest(content) {
|
|
411
|
+
return createHash("sha256").update(content).digest("hex");
|
|
412
|
+
}
|
|
413
|
+
function createFilePrecondition(filePath) {
|
|
414
|
+
if (!existsSync(filePath)) return {
|
|
415
|
+
exists: false,
|
|
416
|
+
digest: null
|
|
417
|
+
};
|
|
418
|
+
return {
|
|
419
|
+
exists: true,
|
|
420
|
+
digest: digest(readFileSync(filePath, "utf8"))
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
function assertFilePrecondition(root, path, precondition) {
|
|
424
|
+
const current = createFilePrecondition(join(root, path));
|
|
425
|
+
if (current.exists !== precondition.exists || current.digest !== precondition.digest) throw new Error(`Setup plan is stale because ${path} changed after planning.`);
|
|
426
|
+
}
|
|
427
|
+
function assertPlanPreconditions(plan) {
|
|
428
|
+
if (plan.dependencies.length) assertFilePrecondition(plan.root, "package.json", plan.packageJSONPrecondition);
|
|
429
|
+
for (const file of plan.files) if (file.action !== "skip") assertFilePrecondition(plan.root, file.path, file.precondition);
|
|
430
|
+
}
|
|
431
|
+
export { applyMasterCSSSetupPlan, planMasterCSSSetup };
|
package/dist/modes.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
type RenderingMode = typeof renderingModes[number];
|
|
4
|
-
declare function isRenderingMode(value: unknown): value is RenderingMode;
|
|
1
|
+
import { MasterCSSRenderingMode } from "@master/css-schema/integration";
|
|
2
|
+
declare function isRenderingMode(value: unknown): value is MasterCSSRenderingMode;
|
|
5
3
|
declare function formatRenderingModes(): string;
|
|
6
|
-
declare function resolveRenderingMode(value: unknown):
|
|
7
|
-
|
|
8
|
-
export { RenderingMode, formatRenderingModes, isRenderingMode, renderingModes, resolveRenderingMode };
|
|
4
|
+
declare function resolveRenderingMode(value: unknown): MasterCSSRenderingMode | undefined;
|
|
5
|
+
export { formatRenderingModes, isRenderingMode, resolveRenderingMode };
|
package/dist/modes.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"runtime",
|
|
4
|
-
"static",
|
|
5
|
-
"progressive",
|
|
6
|
-
"pre-render"
|
|
7
|
-
];
|
|
1
|
+
import { MASTER_CSS_RENDERING_MODES, isMasterCSSRenderingMode } from "@master/css-schema/integration";
|
|
2
|
+
// src/modes.ts
|
|
8
3
|
function isRenderingMode(value) {
|
|
9
|
-
return
|
|
4
|
+
return isMasterCSSRenderingMode(value);
|
|
10
5
|
}
|
|
11
6
|
function formatRenderingModes() {
|
|
12
|
-
return
|
|
7
|
+
return MASTER_CSS_RENDERING_MODES.join(", ");
|
|
13
8
|
}
|
|
14
9
|
function resolveRenderingMode(value) {
|
|
15
10
|
if (value === void 0) return void 0;
|
|
16
11
|
if (isRenderingMode(value)) return value;
|
|
17
12
|
throw new Error(`Invalid rendering mode "${String(value)}". Supported modes: ${formatRenderingModes()}.`);
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
export { formatRenderingModes, isRenderingMode, renderingModes, resolveRenderingMode };
|
|
14
|
+
export { formatRenderingModes, isRenderingMode, resolveRenderingMode };
|
package/dist/transforms.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/transforms.d.ts
|
|
1
|
+
import { MasterCSSRenderingMode } from "@master/css-schema/integration";
|
|
3
2
|
declare function addMasterCSSImportToStylesheet(content: string): string;
|
|
4
3
|
declare function createMasterCSSStylesheet(): string;
|
|
5
|
-
declare function addMasterCSSVitePlugin(content: string, mode?:
|
|
4
|
+
declare function addMasterCSSVitePlugin(content: string, mode?: MasterCSSRenderingMode): string;
|
|
6
5
|
declare function addReactRouterRootCSSImport(content: string): string;
|
|
7
6
|
declare function addTanStackStartRootCSSImport(content: string): string;
|
|
8
7
|
declare function addMasterCSSStaticVitePlugin(content: string): string;
|
|
9
|
-
declare function addMasterCSSTanStackStartVitePlugin(content: string, mode?:
|
|
10
|
-
declare function addMasterCSSRspackPlugin(content: string, mode?:
|
|
11
|
-
declare function addMasterCSSWebpackPlugin(content: string, mode?:
|
|
12
|
-
declare function addMasterCSSRsbuildPlugin(content: string, mode?:
|
|
13
|
-
declare function createViteConfig(mode?:
|
|
8
|
+
declare function addMasterCSSTanStackStartVitePlugin(content: string, mode?: MasterCSSRenderingMode): string;
|
|
9
|
+
declare function addMasterCSSRspackPlugin(content: string, mode?: MasterCSSRenderingMode): string;
|
|
10
|
+
declare function addMasterCSSWebpackPlugin(content: string, mode?: MasterCSSRenderingMode): string;
|
|
11
|
+
declare function addMasterCSSRsbuildPlugin(content: string, mode?: MasterCSSRenderingMode): string;
|
|
12
|
+
declare function createViteConfig(mode?: MasterCSSRenderingMode): string;
|
|
14
13
|
declare function createStaticViteConfig(): string;
|
|
15
|
-
declare function createRspackConfig(mode?:
|
|
16
|
-
declare function createWebpackConfig(mode?:
|
|
17
|
-
declare function createRsbuildConfig(mode?:
|
|
18
|
-
declare function createNextConfig(mode?:
|
|
19
|
-
declare function addMasterCSSNextConfig(content: string, mode?:
|
|
20
|
-
declare function addMasterCSSNuxtModule(content: string, mode?:
|
|
21
|
-
declare function createNuxtConfig(mode?:
|
|
22
|
-
declare function addMasterCSSAstroIntegration(content: string, mode?:
|
|
23
|
-
declare function createAstroConfig(mode?:
|
|
14
|
+
declare function createRspackConfig(mode?: MasterCSSRenderingMode): string;
|
|
15
|
+
declare function createWebpackConfig(mode?: MasterCSSRenderingMode): string;
|
|
16
|
+
declare function createRsbuildConfig(mode?: MasterCSSRenderingMode): string;
|
|
17
|
+
declare function createNextConfig(mode?: MasterCSSRenderingMode): string;
|
|
18
|
+
declare function addMasterCSSNextConfig(content: string, mode?: MasterCSSRenderingMode): string;
|
|
19
|
+
declare function addMasterCSSNuxtModule(content: string, mode?: MasterCSSRenderingMode): string;
|
|
20
|
+
declare function createNuxtConfig(mode?: MasterCSSRenderingMode): string;
|
|
21
|
+
declare function addMasterCSSAstroIntegration(content: string, mode?: MasterCSSRenderingMode): string;
|
|
22
|
+
declare function createAstroConfig(mode?: MasterCSSRenderingMode): string;
|
|
24
23
|
declare function addViteClientTypes(content: string): string;
|
|
24
|
+
/** Preserve the component's own styles while adding build-generated shadow CSS. */
|
|
25
|
+
declare function addLitShadowStylesheet(content: string): string;
|
|
26
|
+
declare function addGeneratedStylesheetImport(content: string): string;
|
|
25
27
|
declare function addLitShadowRuntime(content: string): string;
|
|
26
28
|
declare function addAngularRuntimeSetup(content: string): string;
|
|
27
29
|
declare function addMasterCSSEslintConfig(content: string): string;
|
|
28
|
-
|
|
29
|
-
export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
|
|
30
|
+
export { addAngularRuntimeSetup, addGeneratedStylesheetImport, addLitShadowRuntime, addLitShadowStylesheet, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
|
package/dist/transforms.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CANONICAL_ESLINT_CONFIG } from "./constants.js";
|
|
2
|
-
|
|
2
|
+
// src/transforms.ts
|
|
3
3
|
function formatMasterCSSCall(mode) {
|
|
4
4
|
return mode ? `masterCSS({ mode: '${mode}' })` : "masterCSS()";
|
|
5
5
|
}
|
|
@@ -7,17 +7,28 @@ function formatWebpackPluginCall(mode) {
|
|
|
7
7
|
return mode ? `new MasterCSSPlugin({ mode: '${mode}' })` : "new MasterCSSPlugin()";
|
|
8
8
|
}
|
|
9
9
|
function formatNuxtModule(mode) {
|
|
10
|
-
return mode ? `['@master/css
|
|
10
|
+
return mode ? `['@master/css-nuxt', { mode: '${mode}' }]` : "'@master/css-nuxt'";
|
|
11
11
|
}
|
|
12
12
|
function formatNextCall(target, mode) {
|
|
13
|
-
return mode ?
|
|
13
|
+
return mode ? `withMasterCSS(${target}, { mode: '${mode}' })` : `withMasterCSS(${target})`;
|
|
14
|
+
}
|
|
15
|
+
function formatNextExport(target, mode) {
|
|
16
|
+
return `${!mode || mode === "static" ? "async () => " : ""}${formatNextCall(target, mode)}`;
|
|
14
17
|
}
|
|
15
18
|
function addImport(content, statement) {
|
|
16
19
|
if (content.includes(statement)) return content;
|
|
20
|
+
const newline = content.includes("\r\n") ? "\r\n" : "\n";
|
|
17
21
|
const lines = content.split("\n");
|
|
22
|
+
if (content && !/^import\s/.test(lines[0])) return content + (content.endsWith("\n") ? "" : newline) + statement + newline;
|
|
18
23
|
let insertIndex = 0;
|
|
19
|
-
while (insertIndex < lines.length
|
|
20
|
-
|
|
24
|
+
while (insertIndex < lines.length) {
|
|
25
|
+
const complete = /^import\s+(?:[^'"]+\s+from\s+)?(['"])[^'"]+\1\s*(;?)\s*(?:\/\/.*)?$/.exec(lines[insertIndex]);
|
|
26
|
+
if (!complete) break;
|
|
27
|
+
const next = lines.slice(insertIndex + 1).find((line) => line.trim())?.trim();
|
|
28
|
+
if (!complete[2] && next && !/^(?:import|export|const|let|var|function|class)\b/.test(next)) break;
|
|
29
|
+
insertIndex++;
|
|
30
|
+
}
|
|
31
|
+
lines.splice(insertIndex, 0, statement + (newline === "\r\n" ? "\r" : ""));
|
|
21
32
|
return lines.join("\n").replace(/\n{3,}/, "\n\n");
|
|
22
33
|
}
|
|
23
34
|
function ensureCSSImport(content) {
|
|
@@ -49,8 +60,8 @@ function addMasterCSSStaticVitePlugin(content) {
|
|
|
49
60
|
}
|
|
50
61
|
function addMasterCSSTanStackStartVitePlugin(content, mode = "static") {
|
|
51
62
|
const pluginCall = formatMasterCSSCall(mode);
|
|
52
|
-
if (content.includes("@master/css
|
|
53
|
-
let next = addImport(content, "import masterCSS from '@master/css
|
|
63
|
+
if (content.includes("@master/css-vite")) return content;
|
|
64
|
+
let next = addImport(content, "import masterCSS from '@master/css-vite'");
|
|
54
65
|
const tanStackStartPluginPattern = /^(\s*)tanstackStart\([^)]*\),?/m;
|
|
55
66
|
if (tanStackStartPluginPattern.test(next)) return next.replace(tanStackStartPluginPattern, (match, indent) => {
|
|
56
67
|
return `${match.endsWith(",") ? match : `${match},`}\n${indent}${pluginCall},`;
|
|
@@ -60,24 +71,24 @@ function addMasterCSSTanStackStartVitePlugin(content, mode = "static") {
|
|
|
60
71
|
return next;
|
|
61
72
|
}
|
|
62
73
|
function addMasterCSSRspackPlugin(content, mode) {
|
|
63
|
-
if (content.includes("@master/css
|
|
74
|
+
if (content.includes("@master/css-webpack")) return content;
|
|
64
75
|
const pluginCall = formatWebpackPluginCall(mode);
|
|
65
|
-
let next = addImport(content, "import MasterCSSPlugin from '@master/css
|
|
76
|
+
let next = addImport(content, "import MasterCSSPlugin from '@master/css-webpack'");
|
|
66
77
|
if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, `plugins: [\n ${pluginCall},`);
|
|
67
78
|
if (/export\s+default\s+\{/.test(next)) return replaceFirst(next, /export\s+default\s+\{/, `export default {\n plugins: [${pluginCall}],`);
|
|
68
79
|
return next;
|
|
69
80
|
}
|
|
70
81
|
function addMasterCSSWebpackPlugin(content, mode) {
|
|
71
|
-
if (content.includes("@master/css
|
|
82
|
+
if (content.includes("@master/css-webpack")) return content;
|
|
72
83
|
const pluginCall = formatWebpackPluginCall(mode);
|
|
73
|
-
let next = addImport(content, "import MasterCSSPlugin from '@master/css
|
|
84
|
+
let next = addImport(content, "import MasterCSSPlugin from '@master/css-webpack'");
|
|
74
85
|
if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, `plugins: [\n ${pluginCall},`);
|
|
75
86
|
if (/export\s+default\s+\{/.test(next)) return replaceFirst(next, /export\s+default\s+\{/, `export default {\n plugins: [${pluginCall}],`);
|
|
76
87
|
return next;
|
|
77
88
|
}
|
|
78
89
|
function addMasterCSSRsbuildPlugin(content, mode) {
|
|
79
|
-
if (content.includes("@master/css
|
|
80
|
-
let next = addImport(content, "import MasterCSSPlugin from '@master/css
|
|
90
|
+
if (content.includes("@master/css-webpack")) return content;
|
|
91
|
+
let next = addImport(content, "import MasterCSSPlugin from '@master/css-webpack'");
|
|
81
92
|
const rspackSetupBody = ` config.plugins ||= []
|
|
82
93
|
config.plugins.push(${formatWebpackPluginCall(mode)})
|
|
83
94
|
return config`;
|
|
@@ -99,15 +110,15 @@ ${rspackSetupBody}`);
|
|
|
99
110
|
return next;
|
|
100
111
|
}
|
|
101
112
|
function addMasterCSSVitePluginCall(content, pluginCall) {
|
|
102
|
-
if (content.includes("@master/css
|
|
103
|
-
let next = addImport(content, "import masterCSS from '@master/css
|
|
113
|
+
if (content.includes("@master/css-vite")) return content;
|
|
114
|
+
let next = addImport(content, "import masterCSS from '@master/css-vite'");
|
|
104
115
|
if (/plugins\s*:\s*\[/.test(next)) return replaceFirst(next, /plugins\s*:\s*\[/, `plugins: [\n ${pluginCall},`);
|
|
105
116
|
if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, `defineConfig({\n plugins: [${pluginCall}],`);
|
|
106
117
|
return next;
|
|
107
118
|
}
|
|
108
119
|
function createViteConfig(mode) {
|
|
109
120
|
return `import { defineConfig } from 'vite'
|
|
110
|
-
import masterCSS from '@master/css
|
|
121
|
+
import masterCSS from '@master/css-vite'
|
|
111
122
|
|
|
112
123
|
export default defineConfig({
|
|
113
124
|
plugins: [
|
|
@@ -120,7 +131,7 @@ function createStaticViteConfig() {
|
|
|
120
131
|
return createViteConfig("static");
|
|
121
132
|
}
|
|
122
133
|
function createRspackConfig(mode) {
|
|
123
|
-
return `import MasterCSSPlugin from '@master/css
|
|
134
|
+
return `import MasterCSSPlugin from '@master/css-webpack'
|
|
124
135
|
|
|
125
136
|
export default {
|
|
126
137
|
module: {
|
|
@@ -138,7 +149,7 @@ export default {
|
|
|
138
149
|
`;
|
|
139
150
|
}
|
|
140
151
|
function createWebpackConfig(mode) {
|
|
141
|
-
return `import MasterCSSPlugin from '@master/css
|
|
152
|
+
return `import MasterCSSPlugin from '@master/css-webpack'
|
|
142
153
|
|
|
143
154
|
export default {
|
|
144
155
|
plugins: [
|
|
@@ -149,7 +160,7 @@ export default {
|
|
|
149
160
|
}
|
|
150
161
|
function createRsbuildConfig(mode) {
|
|
151
162
|
return `import { defineConfig } from '@rsbuild/core'
|
|
152
|
-
import MasterCSSPlugin from '@master/css
|
|
163
|
+
import MasterCSSPlugin from '@master/css-webpack'
|
|
153
164
|
|
|
154
165
|
export default defineConfig({
|
|
155
166
|
tools: {
|
|
@@ -163,27 +174,39 @@ export default defineConfig({
|
|
|
163
174
|
`;
|
|
164
175
|
}
|
|
165
176
|
function createNextConfig(mode) {
|
|
166
|
-
return `import
|
|
177
|
+
return `import withMasterCSS from '@master/css-next'
|
|
167
178
|
|
|
168
|
-
const nextConfig = ${
|
|
179
|
+
const nextConfig = ${formatNextExport("{}", mode)}
|
|
169
180
|
|
|
170
181
|
export default nextConfig
|
|
171
182
|
`;
|
|
172
183
|
}
|
|
173
184
|
function addMasterCSSNextConfig(content, mode) {
|
|
174
|
-
if (content.includes("@master/css
|
|
175
|
-
const next = addImport(content, "import
|
|
176
|
-
if (/export\s+default\s+/.test(next)) return next.replace(/export\s+default\s+([^;\n]+)(;?)(\n|$)/, `export default ${
|
|
185
|
+
if (content.includes("@master/css-next")) return updateMasterCSSNextConfig(content, mode);
|
|
186
|
+
const next = addImport(content, "import withMasterCSS from '@master/css-next'");
|
|
187
|
+
if (/export\s+default\s+/.test(next)) return next.replace(/export\s+default\s+([^;\r\n]+)(;?)(\r?\n|$)/, `export default ${formatNextExport("$1", mode)}$2$3`);
|
|
177
188
|
return `${next.trimEnd()}
|
|
178
189
|
|
|
179
|
-
export default ${
|
|
190
|
+
export default ${formatNextExport("{}", mode)}
|
|
180
191
|
`;
|
|
181
192
|
}
|
|
182
|
-
function
|
|
183
|
-
return content.replace(/(
|
|
193
|
+
function updateMasterCSSNextConfig(content, mode) {
|
|
194
|
+
return content.replace(/(await[ \t]+)?\b(withMasterCSS\(\s*(\{\s*\}|[A-Za-z_$][\w$]*)\s*(?:,\s*(\{[^)]*\}))?\s*\))/g, (match, awaited, call, target, options, offset) => {
|
|
195
|
+
let updated = call;
|
|
196
|
+
if (mode) {
|
|
197
|
+
if (!options || /^\{\s*(?:mode\s*:\s*['"][a-z-]+['"]\s*,?\s*)?\}$/.test(options)) updated = formatNextCall(target, mode);
|
|
198
|
+
else updated = `withMasterCSS(${target}, { ...${/^\{ \.\.\.(\{[^)]*\}), mode: '[a-z-]+' \}$/.exec(options)?.[1] ?? options}, mode: '${mode}' })`;
|
|
199
|
+
}
|
|
200
|
+
const before = content.slice(content.lastIndexOf("\n", offset - 1) + 1, offset);
|
|
201
|
+
const after = content.slice(offset + match.length);
|
|
202
|
+
const exportedCall = /^export[ \t]+default[ \t]+$/.test(before) && /^;?[ \t]*(?:\r?\n|$)/.test(after);
|
|
203
|
+
const exportedBinding = /^const[ \t]+nextConfig[ \t]*=[ \t]*$/.test(before) && /^;?[ \t]*(?:\r?\n[ \t]*)+export[ \t]+default[ \t]+nextConfig;?[ \t]*(?:\r?\n|$)/.test(after);
|
|
204
|
+
if ((exportedCall || exportedBinding) && (awaited || mode === "static")) return `${!mode || mode === "static" ? "async () => " : ""}${updated}`;
|
|
205
|
+
return (awaited ?? "") + updated;
|
|
206
|
+
});
|
|
184
207
|
}
|
|
185
208
|
function addMasterCSSNuxtModule(content, mode) {
|
|
186
|
-
if (content.includes("@master/css
|
|
209
|
+
if (content.includes("@master/css-nuxt")) return content;
|
|
187
210
|
const moduleEntry = formatNuxtModule(mode);
|
|
188
211
|
if (/modules\s*:\s*\[/.test(content)) return replaceFirst(content, /modules\s*:\s*\[/, `modules: [\n ${moduleEntry},`);
|
|
189
212
|
if (/defineNuxtConfig\(\s*\{/.test(content)) return replaceFirst(content, /defineNuxtConfig\(\s*\{/, `defineNuxtConfig({\n modules: [${moduleEntry}],`);
|
|
@@ -197,16 +220,16 @@ function createNuxtConfig(mode) {
|
|
|
197
220
|
`;
|
|
198
221
|
}
|
|
199
222
|
function addMasterCSSAstroIntegration(content, mode) {
|
|
200
|
-
if (content.includes("@master/css
|
|
223
|
+
if (content.includes("@master/css-astro")) return content;
|
|
201
224
|
const pluginCall = formatMasterCSSCall(mode);
|
|
202
|
-
let next = addImport(content, "import masterCSS from '@master/css
|
|
225
|
+
let next = addImport(content, "import masterCSS from '@master/css-astro'");
|
|
203
226
|
if (/integrations\s*:\s*\[/.test(next)) return replaceFirst(next, /integrations\s*:\s*\[/, `integrations: [\n ${pluginCall},`);
|
|
204
227
|
if (/defineConfig\(\s*\{/.test(next)) return replaceFirst(next, /defineConfig\(\s*\{/, `defineConfig({\n integrations: [${pluginCall}],`);
|
|
205
228
|
return next;
|
|
206
229
|
}
|
|
207
230
|
function createAstroConfig(mode) {
|
|
208
231
|
return `import { defineConfig } from 'astro/config'
|
|
209
|
-
import masterCSS from '@master/css
|
|
232
|
+
import masterCSS from '@master/css-astro'
|
|
210
233
|
|
|
211
234
|
export default defineConfig({
|
|
212
235
|
integrations: [
|
|
@@ -218,33 +241,46 @@ export default defineConfig({
|
|
|
218
241
|
function addViteClientTypes(content) {
|
|
219
242
|
let next = content;
|
|
220
243
|
if (!next.includes("/// <reference types=\"vite/client\" />")) next = `/// <reference types="vite/client" />\n${next}`;
|
|
221
|
-
if (!next.includes("/// <reference types=\"@master/css
|
|
244
|
+
if (!next.includes("/// <reference types=\"@master/css/client\" />")) {
|
|
222
245
|
const lines = next.split("\n");
|
|
223
246
|
const viteReferenceIndex = lines.findIndex((line) => line.includes("/// <reference types=\"vite/client\" />"));
|
|
224
|
-
lines.splice(viteReferenceIndex + 1, 0, "/// <reference types=\"@master/css
|
|
247
|
+
lines.splice(viteReferenceIndex + 1, 0, "/// <reference types=\"@master/css/client\" />");
|
|
225
248
|
next = lines.join("\n");
|
|
226
249
|
}
|
|
227
250
|
return next;
|
|
228
251
|
}
|
|
252
|
+
/** Preserve the component's own styles while adding build-generated shadow CSS. */
|
|
253
|
+
function addLitShadowStylesheet(content) {
|
|
254
|
+
if (content.includes("import masterCSSStyles from './index.css?inline'")) return content;
|
|
255
|
+
const ownStyles = /\bstatic\s+(?:get\s+)?styles\b/.test(content);
|
|
256
|
+
let next = content.replace(/(\bstatic\s+(?:get\s+)?)styles\b/, "$1masterCSSOriginalStyles");
|
|
257
|
+
next = addImport(next, "import { unsafeCSS } from 'lit'");
|
|
258
|
+
next = addImport(next, "import masterCSSStyles from './index.css?inline'");
|
|
259
|
+
return next.replace(/(export\s+class\s+\w+[^\{]*\{)/, `$1\n static get styles() { return [unsafeCSS(masterCSSStyles)${ownStyles ? ", this.masterCSSOriginalStyles" : ""}] }\n`);
|
|
260
|
+
}
|
|
261
|
+
function addGeneratedStylesheetImport(content) {
|
|
262
|
+
const statement = "@import './master.generated.css';";
|
|
263
|
+
return content.includes(statement) ? content : `${statement}\n${content}`;
|
|
264
|
+
}
|
|
229
265
|
function addLitShadowRuntime(content) {
|
|
230
|
-
if (content.includes("@master/css-runtime") && content.includes("virtual:master-css-
|
|
231
|
-
let next = addImport(content, "import {
|
|
232
|
-
next = addImport(next, "import type
|
|
233
|
-
next = addImport(next, "import
|
|
266
|
+
if (content.includes("@master/css-runtime") && content.includes("virtual:master-css-program") && content.includes("@withMasterCSSRuntime({ program, emittedGlobals })") && content.includes("masterCSSRuntime?: MasterCSSRuntime")) return content;
|
|
267
|
+
let next = addImport(content, "import { withMasterCSSRuntime } from '@master/css-runtime'");
|
|
268
|
+
next = addImport(next, "import type { MasterCSSRuntime } from '@master/css-runtime'");
|
|
269
|
+
next = addImport(next, "import program from 'virtual:master-css-program'");
|
|
234
270
|
next = addImport(next, "import emittedGlobals from 'virtual:master-css-emitted-globals'");
|
|
235
|
-
if (!next.includes("@
|
|
236
|
-
|
|
237
|
-
|
|
271
|
+
if (!next.includes("@withMasterCSSRuntime({ program, emittedGlobals })")) {
|
|
272
|
+
if (/@customElement\([^\n]+\)\nexport\s+class\s/.test(next)) next = next.replace(/(@customElement\([^\n]+\)\n)(export\s+class\s)/, "$1@withMasterCSSRuntime({ program, emittedGlobals })\n$2");
|
|
273
|
+
else next = next.replace(/export\s+class\s/, "@withMasterCSSRuntime({ program, emittedGlobals })\nexport class ");
|
|
274
|
+
}
|
|
275
|
+
if (!next.includes("masterCSSRuntime?: MasterCSSRuntime")) next = next.replace(/(export\s+class\s+\w+[^{]*\{)/, "$1\n\n masterCSSRuntime?: MasterCSSRuntime");
|
|
238
276
|
return next;
|
|
239
277
|
}
|
|
240
278
|
function addAngularRuntimeSetup(content) {
|
|
241
279
|
if (content.includes("@master/css-runtime")) return content;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
CSSRuntime.create({ manifest: defaultManifest }).observe()
|
|
280
|
+
const next = addImport(content, "import { MasterCSSRuntime } from '@master/css-runtime'");
|
|
281
|
+
const setup = `void MasterCSSRuntime.start({ program: () => import('@master/css-runtime/default-program').then((module) => module.defaultProgram) })
|
|
282
|
+
.then((cssRuntime) => cssRuntime.observe())
|
|
283
|
+
.catch((error) => console.error(error))
|
|
248
284
|
|
|
249
285
|
`;
|
|
250
286
|
if (/bootstrapApplication\s*\(/.test(next)) return next.replace(/bootstrapApplication\s*\(/, `${setup}bootstrapApplication(`);
|
|
@@ -257,10 +293,10 @@ function addMasterCSSEslintConfig(content) {
|
|
|
257
293
|
if (content.includes("@master/eslint-config-css")) return content;
|
|
258
294
|
if (!content.trim()) return CANONICAL_ESLINT_CONFIG;
|
|
259
295
|
let next = addImport(content, "import { defineConfig } from 'eslint/config'");
|
|
260
|
-
next = addImport(next, "import
|
|
261
|
-
if (/export\s+default\s+defineConfig\(\s*\[/.test(next)) return replaceFirst(next, /export\s+default\s+defineConfig\(\s*\[/, "export default defineConfig([\n ...
|
|
296
|
+
next = addImport(next, "import masterCSS from '@master/eslint-config-css'");
|
|
297
|
+
if (/export\s+default\s+defineConfig\(\s*\[/.test(next)) return replaceFirst(next, /export\s+default\s+defineConfig\(\s*\[/, "export default defineConfig([\n ...masterCSS,");
|
|
262
298
|
if (/export\s+default\s+\[/.test(next)) {
|
|
263
|
-
next = replaceFirst(next, /export\s+default\s+\[/, "export default defineConfig([\n ...
|
|
299
|
+
next = replaceFirst(next, /export\s+default\s+\[/, "export default defineConfig([\n ...masterCSS,");
|
|
264
300
|
const closeIndex = next.lastIndexOf("]");
|
|
265
301
|
return closeIndex === -1 ? next : `${next.slice(0, closeIndex + 1)})${next.slice(closeIndex + 1)}`;
|
|
266
302
|
}
|
|
@@ -268,9 +304,8 @@ function addMasterCSSEslintConfig(content) {
|
|
|
268
304
|
|
|
269
305
|
// Master CSS recommended config:
|
|
270
306
|
// export default defineConfig([
|
|
271
|
-
// ...
|
|
307
|
+
// ...masterCSS
|
|
272
308
|
// ])
|
|
273
309
|
`;
|
|
274
310
|
}
|
|
275
|
-
|
|
276
|
-
export { addAngularRuntimeSetup, addLitShadowRuntime, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
|
|
311
|
+
export { addAngularRuntimeSetup, addGeneratedStylesheetImport, addLitShadowRuntime, addLitShadowStylesheet, addMasterCSSAstroIntegration, addMasterCSSEslintConfig, addMasterCSSImportToStylesheet, addMasterCSSNextConfig, addMasterCSSNuxtModule, addMasterCSSRsbuildPlugin, addMasterCSSRspackPlugin, addMasterCSSStaticVitePlugin, addMasterCSSTanStackStartVitePlugin, addMasterCSSVitePlugin, addMasterCSSWebpackPlugin, addReactRouterRootCSSImport, addTanStackStartRootCSSImport, addViteClientTypes, createAstroConfig, createMasterCSSStylesheet, createNextConfig, createNuxtConfig, createRsbuildConfig, createRspackConfig, createStaticViteConfig, createViteConfig, createWebpackConfig };
|
package/package.json
CHANGED
|
@@ -1,51 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
2
|
+
"name": "@master/create-css",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": "^24"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "bun --bun tsdown --config ../../shared/tsdown-package.config.ts",
|
|
9
|
+
"dev": "bun --bun tsdown --config ../../shared/tsdown-package.config.ts --watch",
|
|
10
|
+
"lint": "bun --bun eslint",
|
|
11
|
+
"test": "node ../../node_modules/vitest/vitest.mjs run"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"description": "Add Master CSS to an existing project.",
|
|
15
|
+
"author": "Aoyue Design LLC.",
|
|
16
|
+
"homepage": "https://css.master.co",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/master-co/css/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/master-co/css.git",
|
|
23
|
+
"directory": "packages/create"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"cli",
|
|
27
|
+
"create",
|
|
28
|
+
"init",
|
|
29
|
+
"css",
|
|
30
|
+
"mastercss"
|
|
31
|
+
],
|
|
32
|
+
"bin": {
|
|
33
|
+
"create-css": "./dist/bin/index.js"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"dist"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@master/css-schema": "3.0.0",
|
|
52
|
+
"commander": "^15.0.0"
|
|
53
|
+
},
|
|
54
|
+
"version": "3.0.0",
|
|
55
|
+
"gitHead": "a5da5f2d73901082314a082d5213fd18e11ad48b"
|
|
56
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Aoyue Design LLC.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|