@razorwind/vsce 0.0.2
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/LICENSE +201 -0
- package/README.md +331 -0
- package/dist/index.cjs +152 -0
- package/dist/index.d.cts +261 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +261 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +153 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +80 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin"),t=require("@razorwind/core/utils"),n=require("node:path");const r=/^(?:light|dark|dim|dimmed|high-contrast|hc|protanopia|deuteranopia|tritanopia|achromatopsia|achromatomaly|monochrome|monochromatic|grayscale|greyscale|bw|black-and-white|black-white|blackWhite|default|base|theme)(?:[A-Z]\w*|[._-].+)?$/i;function i(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function a(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function o(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function s(e){if(`$value`in e)return e.$value;if(`value`in e)return e.value;if(typeof e.$ref==`string`)return e.$ref;if(typeof e.ref==`string`)return e.ref}function c(e,n,r,l,u){if(!(0,t.isObject)(e))return;let d=o(e,r);if(i(e)){let r=s(e);u.push({path:n.join(`.`),type:d,value:r,cssValue:(0,t.formatTokenValue)(r,d),description:a(e),theme:l});return}for(let[t,r]of Object.entries(e))t.startsWith(`$`)||c(r,[...n,t],d,l,u)}function l(e){if(!(0,t.isObject)(e))return[];let n=Object.keys(e).filter(e=>!e.startsWith(`$`));if(n.length>0&&n.every(e=>r.test(e))){let t=e;return n.map(e=>({id:e,tokens:t[e]}))}return[{id:`default`,tokens:e}]}function u(e,t={}){let n=t.includeTypes?new Set(t.includeTypes):void 0,r=[];for(let t of l(e)){let e=t.id==="default"?void 0:t.id;c(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}function d(e){return`import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
interface PackageJson {
|
|
6
|
+
name?: unknown;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
export const packageRoot = join(scriptDir, "..");
|
|
12
|
+
const packageJsonPath = join(packageRoot, "package.json");
|
|
13
|
+
const readmePath = join(packageRoot, "README.md");
|
|
14
|
+
const vsceReadmePath = join(scriptDir, "README.package.md");
|
|
15
|
+
const readmeBackupPath = join(packageRoot, "README.md.bak");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Temporarily rewrite package.json / README for VSIX tooling.
|
|
19
|
+
*
|
|
20
|
+
* VSIX packaging reads package.json and README.md from the extension root,
|
|
21
|
+
* while an npm-scoped package may keep a different name and README.
|
|
22
|
+
*/
|
|
23
|
+
export function withVsixPackageShim(action: () => void): void {
|
|
24
|
+
const originalPackageJson = readFileSync(packageJsonPath, "utf8");
|
|
25
|
+
const packageJson = JSON.parse(originalPackageJson) as PackageJson;
|
|
26
|
+
|
|
27
|
+
if (typeof packageJson.name !== "string") {
|
|
28
|
+
throw new TypeError("package.json must define a string name");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const originalName = packageJson.name;
|
|
32
|
+
const extensionName = ${JSON.stringify(e)};
|
|
33
|
+
packageJson.name = extensionName;
|
|
34
|
+
delete packageJson.files;
|
|
35
|
+
|
|
36
|
+
console.log(
|
|
37
|
+
\`Temporarily renaming package: \${originalName} -> \${extensionName}\\n\`
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const hadReadme = existsSync(readmePath);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
writeFileSync(packageJsonPath, \`\${JSON.stringify(packageJson, null, 2)}\\n\`);
|
|
44
|
+
|
|
45
|
+
if (hadReadme) {
|
|
46
|
+
renameSync(readmePath, readmeBackupPath);
|
|
47
|
+
}
|
|
48
|
+
if (existsSync(vsceReadmePath)) {
|
|
49
|
+
renameSync(vsceReadmePath, readmePath);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
action();
|
|
53
|
+
} finally {
|
|
54
|
+
if (existsSync(readmePath) && existsSync(vsceReadmePath) === false) {
|
|
55
|
+
renameSync(readmePath, vsceReadmePath);
|
|
56
|
+
}
|
|
57
|
+
if (hadReadme && existsSync(readmeBackupPath)) {
|
|
58
|
+
renameSync(readmeBackupPath, readmePath);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
writeFileSync(packageJsonPath, originalPackageJson);
|
|
62
|
+
console.log(\`\\nRestored package name: \${originalName}\`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`}function f(){return`import { execFileSync } from "node:child_process";
|
|
66
|
+
import { mkdirSync } from "node:fs";
|
|
67
|
+
import { join } from "node:path";
|
|
68
|
+
import { packageRoot, withVsixPackageShim } from "./vsixPackageShim.ts";
|
|
69
|
+
|
|
70
|
+
mkdirSync(join(packageRoot, "artifacts", "vsix"), { recursive: true });
|
|
71
|
+
|
|
72
|
+
withVsixPackageShim(() => {
|
|
73
|
+
execFileSync(
|
|
74
|
+
"pnpm",
|
|
75
|
+
[
|
|
76
|
+
"exec",
|
|
77
|
+
"vsce",
|
|
78
|
+
"package",
|
|
79
|
+
"--no-dependencies",
|
|
80
|
+
"--out",
|
|
81
|
+
"artifacts/vsix"
|
|
82
|
+
],
|
|
83
|
+
{
|
|
84
|
+
cwd: packageRoot,
|
|
85
|
+
stdio: "inherit"
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
`}function p(){return`import { execFileSync } from "node:child_process";
|
|
90
|
+
import { packageRoot, withVsixPackageShim } from "./vsixPackageShim.ts";
|
|
91
|
+
|
|
92
|
+
// Manual VS Marketplace publish. Requires VSCE_PAT in the environment.
|
|
93
|
+
const vscePat = process.env.VSCE_PAT;
|
|
94
|
+
|
|
95
|
+
if (vscePat === undefined || vscePat.length === 0) {
|
|
96
|
+
throw new Error("VSCE_PAT must be set to publish the VS Code extension");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
withVsixPackageShim(() => {
|
|
100
|
+
execFileSync("pnpm", ["exec", "vsce", "publish", "--no-dependencies"], {
|
|
101
|
+
cwd: packageRoot,
|
|
102
|
+
env: { ...process.env, VSCE_PAT: vscePat },
|
|
103
|
+
stdio: "inherit"
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
`}function m(){return`import { execFileSync } from "node:child_process";
|
|
107
|
+
import { packageRoot, withVsixPackageShim } from "./vsixPackageShim.ts";
|
|
108
|
+
|
|
109
|
+
// Manual Open VSX publish. Requires OVSX_PAT in the environment.
|
|
110
|
+
const ovsxPat = process.env.OVSX_PAT;
|
|
111
|
+
|
|
112
|
+
if (ovsxPat === undefined || ovsxPat.length === 0) {
|
|
113
|
+
throw new Error("OVSX_PAT must be set to publish the Open VSX extension");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
withVsixPackageShim(() => {
|
|
117
|
+
execFileSync("pnpm", ["exec", "ovsx", "publish", "--no-dependencies"], {
|
|
118
|
+
cwd: packageRoot,
|
|
119
|
+
env: { ...process.env, OVSX_PAT: ovsxPat },
|
|
120
|
+
stdio: "inherit"
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
`}function h(e){let t=e.themes.map(e=>`- ${e.label}`).join(`
|
|
124
|
+
`),n=e.repositoryUrl?`\n## Links\n\n- [GitHub](${e.repositoryUrl})\n`:``;return`# ${e.displayName}
|
|
125
|
+
|
|
126
|
+
${e.description}
|
|
127
|
+
|
|
128
|
+
## Installation
|
|
129
|
+
|
|
130
|
+
1. Open the Extensions view (\`Cmd+Shift+X\` / \`Ctrl+Shift+X\`)
|
|
131
|
+
2. Search for **${e.displayName}**
|
|
132
|
+
3. Click **Install**
|
|
133
|
+
4. Open the Command Palette (\`Cmd+Shift+P\` / \`Ctrl+Shift+P\`) → **Color Theme** → select a theme
|
|
134
|
+
|
|
135
|
+
## Themes
|
|
136
|
+
|
|
137
|
+
${t||`- (generated themes)`}
|
|
138
|
+
${n}`}function g(){return`node_modules/**
|
|
139
|
+
src/**
|
|
140
|
+
scripts/**
|
|
141
|
+
test/**
|
|
142
|
+
tests/**
|
|
143
|
+
.github/**
|
|
144
|
+
.vscode/**
|
|
145
|
+
|
|
146
|
+
.gitignore
|
|
147
|
+
*.tsbuildinfo
|
|
148
|
+
*.vsix
|
|
149
|
+
artifacts/**
|
|
150
|
+
README.md.bak
|
|
151
|
+
.DS_Store
|
|
152
|
+
`}const _={name:`razorwind-vsce`},v={vscode:`^1.85.0`};function y(e,n,r){return(0,t.createDocument)(e,n,_,r)}function b(e){return e.split(/[-_.\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function x(e){return e.trim().toLowerCase().replaceAll(/[^a-z0-9]+/g,`-`).replaceAll(/^-+|-+$/g,``)}function S(e){switch(e){case`light`:return`vs`;case`hc`:return`hc-black`;case`hcLight`:return`hc-light`;case`dark`:return`vs-dark`;default:return`vs-dark`}}function C(e){return(0,t.isObject)(e)&&typeof e.name==`string`&&(e.type===`light`||e.type===`dark`||e.type===`hc`||e.type===`hcLight`)}function w(e){if(Array.isArray(e))return e.map((e,t)=>{if(!C(e))throw TypeError(`@razorwind/vsce mapTheme()[${t}] must be a VsCodeTheme with name + type`);return e});if(C(e))return[e];if(!(0,t.isObject)(e))throw TypeError(`@razorwind/vsce mapTheme() must return a theme, theme array, or theme record`);return Object.entries(e).map(([e,t])=>{if(!C(t))throw TypeError(`@razorwind/vsce mapTheme()["${e}"] must be a VsCodeTheme with name + type`);return{...t,name:t.name||e}})}function T(e){if(typeof e==`string`)return e;if(e&&typeof e.url==`string`)return e.url}function E(e){if(!e.mapTheme)throw Error(`@razorwind/vsce requires options.mapTheme`);if(!e.name||e.name.includes(`/`))throw Error(`@razorwind/vsce requires options.name (unscoped Marketplace id)`);if(!e.publisher)throw Error(`@razorwind/vsce requires options.publisher`)}function D(e){return e===`light`||e===`hcLight`?`light`:`dark`}function O(e){let t={name:e.name,type:D(e.type),colors:e.colors??{}};return e.displayName&&(t.displayName=e.displayName),e.tokenColors&&(t.tokenColors=e.tokenColors),e.semanticHighlighting!==void 0&&(t.semanticHighlighting=e.semanticHighlighting),e.semanticTokenColors&&(t.semanticTokenColors=e.semanticTokenColors),`${JSON.stringify(t,null,2)}\n`}function k(e,n){let r=e.includeScripts!==!1,i=e.displayName??b(e.name),a=e.description??`${i} — VS Code themes generated by Razorwind`,o={themes:n.map(e=>({label:e.displayName??e.name,uiTheme:S(e.type),path:`./themes/${x(e.name)}.json`}))},s=r?{"package-vsix":`node --import tsx scripts/buildVsCodePackage.ts`,"publish-vsce":`node --import tsx scripts/publishVsce.ts`,"publish-ovsx":`node --import tsx scripts/publishOvsx.ts`}:void 0,c={name:e.name,displayName:i,description:a,version:e.version??`0.0.1`,publisher:e.publisher,license:e.license??`Apache-2.0`,categories:e.categories??[`Themes`],engines:e.engines??{...v},contributes:o,...e.keywords?{keywords:e.keywords}:{},...e.repository?{repository:e.repository}:{},...e.homepage?{homepage:e.homepage}:{},...e.bugs?{bugs:e.bugs}:{},...e.author?{author:e.author}:{},...e.icon?{icon:e.icon}:{},...e.galleryBanner?{galleryBanner:e.galleryBanner}:{},...s?{scripts:s}:{},...e.packageJson??{}};return c.name=e.name,c.publisher=e.publisher,c.contributes=o,s&&(c.scripts=(0,t.isObject)(c.scripts)&&!Array.isArray(c.scripts)?{...c.scripts,...s}:s),`${JSON.stringify(c,null,2)}\n`}function A(e,t){E(t);let r=t.outputPath??`vscode-extension`,i=t.includeScripts!==!1,a=t.extensionName??t.name,o=t.displayName??b(t.name),s=t.description??`${o} — VS Code themes generated by Razorwind`,c=w(t.mapTheme(e.tokens));if(c.length===0)throw Error(`@razorwind/vsce mapTheme() returned no themes`);let l={};for(let e of c){let t=`${x(e.name)}.json`,i=(0,n.join)(r,`themes`,t);l[i]=y(i,O(e),`json`)}let u=(0,n.join)(r,`package.json`);l[u]=y(u,k(t,c),`json`);let _=(0,n.join)(r,`.vscodeignore`);l[_]=y(_,g(),`ignore`);let v=c.map(e=>({label:e.displayName??e.name})),S=t.readme??h({displayName:o,description:s,themes:v,repositoryUrl:T(t.repository)}),C=(0,n.join)(r,`README.md`);if(l[C]=y(C,S,`markdown`),i){let e=(0,n.join)(r,`scripts`,`vsixPackageShim.ts`);l[e]=y(e,d(a),`typescript`);let i=(0,n.join)(r,`scripts`,`buildVsCodePackage.ts`);l[i]=y(i,f(),`typescript`);let c=(0,n.join)(r,`scripts`,`publishVsce.ts`);l[c]=y(c,p(),`typescript`);let u=(0,n.join)(r,`scripts`,`publishOvsx.ts`);l[u]=y(u,m(),`typescript`);let g=(0,n.join)(r,`scripts`,`README.package.md`);l[g]=y(g,h({displayName:o,description:s,themes:v,repositoryUrl:T(t.repository)}),`markdown`)}return l}var j=(0,e.definePlugin)(e=>({name:`vsce`,generate:async t=>{if(!e)throw Error(`@razorwind/vsce requires options: { name, publisher, mapTheme }`);return A(t,e)}}));exports.default=j,exports.flattenTokens=u,Object.defineProperty(exports,"formatTokenValue",{enumerable:!0,get:function(){return t.formatTokenValue}}),exports.generateVsceExtension=A,exports.normalizeThemes=w,exports.renderPackageJson=k,exports.renderThemeJson=O,exports.resolveTokenSets=l,Object.defineProperty(exports,"toCssVar",{enumerable:!0,get:function(){return t.toCssVar}});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Schema, Tokens } from "@razorwind/core/schema";
|
|
2
|
+
import { TokenType } from "@power-plant/dtcg-schema";
|
|
3
|
+
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
4
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A flattened design token ready for VS Code theme mapping.
|
|
8
|
+
*/
|
|
9
|
+
interface FlatToken {
|
|
10
|
+
/** Dot-separated token path (e.g. `color.primary`). */
|
|
11
|
+
path: string;
|
|
12
|
+
/** DTCG `$type`, when known. */
|
|
13
|
+
type?: TokenType | string;
|
|
14
|
+
/** Raw `$value` from the token document. */
|
|
15
|
+
value: unknown;
|
|
16
|
+
/** CSS-friendly string form of {@link value}. */
|
|
17
|
+
cssValue: string;
|
|
18
|
+
/** Optional DTCG `$description`. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Theme / set id when tokens are a `Record<string, Tokens>`. */
|
|
21
|
+
theme?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TextMate token color rule for a VS Code theme.
|
|
25
|
+
*
|
|
26
|
+
* @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
|
|
27
|
+
*/
|
|
28
|
+
interface VsCodeTokenColor {
|
|
29
|
+
name?: string;
|
|
30
|
+
scope?: string | string[];
|
|
31
|
+
settings: {
|
|
32
|
+
foreground?: string;
|
|
33
|
+
background?: string;
|
|
34
|
+
fontStyle?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* VS Code / TextMate color theme document.
|
|
39
|
+
*
|
|
40
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
41
|
+
*/
|
|
42
|
+
interface VsCodeTheme {
|
|
43
|
+
/** Stable theme id used for the theme file name. */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Marketplace / Color Theme picker label. Defaults to {@link name}. */
|
|
46
|
+
displayName?: string;
|
|
47
|
+
/** Theme kind — maps to `contributes.themes[].uiTheme`. */
|
|
48
|
+
type: "light" | "dark" | "hc" | "hcLight";
|
|
49
|
+
colors?: Record<string, string>;
|
|
50
|
+
tokenColors?: VsCodeTokenColor[];
|
|
51
|
+
semanticHighlighting?: boolean;
|
|
52
|
+
semanticTokenColors?: Record<string, string | {
|
|
53
|
+
foreground?: string;
|
|
54
|
+
fontStyle?: string;
|
|
55
|
+
bold?: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Map extracted design tokens to one or more VS Code theme documents.
|
|
60
|
+
*
|
|
61
|
+
* Return a single theme, an array, or a record keyed by theme id.
|
|
62
|
+
*/
|
|
63
|
+
type GenerateVsCodeTheme = (tokens: Tokens | Record<string, Tokens>) => VsCodeTheme | VsCodeTheme[] | Record<string, VsCodeTheme>;
|
|
64
|
+
/**
|
|
65
|
+
* package.json `author` field shape.
|
|
66
|
+
*/
|
|
67
|
+
type VscePackageAuthor = string | {
|
|
68
|
+
name: string;
|
|
69
|
+
email?: string;
|
|
70
|
+
url?: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Options for the Razorwind VS Code extension (theme) generator.
|
|
74
|
+
*
|
|
75
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
76
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
77
|
+
*/
|
|
78
|
+
interface VscePluginOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Directory (relative to the execution cwd) for the generated extension
|
|
81
|
+
* package.
|
|
82
|
+
*
|
|
83
|
+
* @defaultValue `"vscode-extension"`
|
|
84
|
+
*/
|
|
85
|
+
outputPath?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Map extracted tokens to VS Code theme JSON document(s).
|
|
88
|
+
*
|
|
89
|
+
* Required — without a mapping there is nothing to emit.
|
|
90
|
+
*/
|
|
91
|
+
mapTheme: GenerateVsCodeTheme;
|
|
92
|
+
/**
|
|
93
|
+
* Unscoped Marketplace extension id (`contributes` / VSIX name).
|
|
94
|
+
* Must not include an npm scope.
|
|
95
|
+
*/
|
|
96
|
+
name: string;
|
|
97
|
+
/** Marketplace display name. Defaults to a title-cased {@link name}. */
|
|
98
|
+
displayName?: string;
|
|
99
|
+
/** Marketplace short description. */
|
|
100
|
+
description?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Extension version (semver without prerelease tags — vsce rejects them).
|
|
103
|
+
*
|
|
104
|
+
* @defaultValue `"0.0.1"`
|
|
105
|
+
*/
|
|
106
|
+
version?: string;
|
|
107
|
+
/** Marketplace publisher id. */
|
|
108
|
+
publisher: string;
|
|
109
|
+
/**
|
|
110
|
+
* Unscoped name written into the VSIX shim when packaging.
|
|
111
|
+
* Defaults to {@link name}.
|
|
112
|
+
*/
|
|
113
|
+
extensionName?: string;
|
|
114
|
+
/**
|
|
115
|
+
* @defaultValue `"Apache-2.0"`
|
|
116
|
+
*/
|
|
117
|
+
license?: string;
|
|
118
|
+
repository?: string | {
|
|
119
|
+
type?: string;
|
|
120
|
+
url?: string;
|
|
121
|
+
directory?: string;
|
|
122
|
+
};
|
|
123
|
+
homepage?: string;
|
|
124
|
+
bugs?: string | {
|
|
125
|
+
url?: string;
|
|
126
|
+
email?: string;
|
|
127
|
+
};
|
|
128
|
+
author?: VscePackageAuthor;
|
|
129
|
+
/**
|
|
130
|
+
* Icon path relative to the extension root (e.g. `icon.png`).
|
|
131
|
+
* The file itself is not generated — place it beside the package.
|
|
132
|
+
*/
|
|
133
|
+
icon?: string;
|
|
134
|
+
galleryBanner?: {
|
|
135
|
+
color?: string;
|
|
136
|
+
theme?: "dark" | "light";
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* @defaultValue `["Themes"]`
|
|
140
|
+
*/
|
|
141
|
+
categories?: string[];
|
|
142
|
+
keywords?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* @defaultValue `{ vscode: "^1.85.0" }`
|
|
145
|
+
*/
|
|
146
|
+
engines?: {
|
|
147
|
+
vscode: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Emit pierre-style `scripts/` helpers and `package.json` script entries
|
|
151
|
+
* for packaging / publishing.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue `true`
|
|
154
|
+
*
|
|
155
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
156
|
+
*/
|
|
157
|
+
includeScripts?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Marketplace README body. When omitted, a minimal install guide is
|
|
160
|
+
* generated from the contributed themes.
|
|
161
|
+
*/
|
|
162
|
+
readme?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Restrict flattened helper tokens to these DTCG `$type` values.
|
|
165
|
+
* Does not filter what {@link mapTheme} receives.
|
|
166
|
+
*/
|
|
167
|
+
includeTypes?: TokenType[];
|
|
168
|
+
/**
|
|
169
|
+
* Extra fields merged into the generated extension `package.json`
|
|
170
|
+
* (shallow merge; `contributes.themes` / `scripts` from the plugin win).
|
|
171
|
+
*/
|
|
172
|
+
packageJson?: Record<string, unknown>;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/flatten.d.ts
|
|
176
|
+
interface TokenSet {
|
|
177
|
+
id: string;
|
|
178
|
+
tokens: Tokens;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Split `Schema.tokens` into one or more named token sets.
|
|
182
|
+
*/
|
|
183
|
+
declare function resolveTokenSets(tokens: Tokens | Record<string, Tokens>): TokenSet[];
|
|
184
|
+
/**
|
|
185
|
+
* Flatten DTCG token trees into rows helpful for {@link VscePluginOptions.mapTheme}.
|
|
186
|
+
*/
|
|
187
|
+
declare function flattenTokens(tokens: Tokens | Record<string, Tokens>, options?: Pick<VscePluginOptions, "includeTypes">): FlatToken[];
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/generate.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* Normalize {@link VscePluginOptions.mapTheme} results into a theme list.
|
|
192
|
+
*/
|
|
193
|
+
declare function normalizeThemes(result: VsCodeTheme | VsCodeTheme[] | Record<string, VsCodeTheme>): VsCodeTheme[];
|
|
194
|
+
declare function renderThemeJson(theme: VsCodeTheme): string;
|
|
195
|
+
/**
|
|
196
|
+
* Build the extension `package.json` manifest (themes + optional scripts).
|
|
197
|
+
*/
|
|
198
|
+
declare function renderPackageJson(options: VscePluginOptions, themes: VsCodeTheme[]): string;
|
|
199
|
+
/**
|
|
200
|
+
* Generate a publishable VS Code theme extension package from a Razorwind schema.
|
|
201
|
+
*/
|
|
202
|
+
declare function generateVsceExtension(spec: Schema, options: VscePluginOptions): GeneratorFunctionResult<Schema, VscePluginOptions>;
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/index.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* Razorwind plugin that turns design tokens into a publishable VS Code
|
|
207
|
+
* theme extension package (theme JSON, package.json, scripts, README).
|
|
208
|
+
*
|
|
209
|
+
* Provide {@link VscePluginOptions.mapTheme} to map extracted tokens to one
|
|
210
|
+
* or more VS Code theme documents. Packaging / publish helpers follow the
|
|
211
|
+
* pierre theme script layout.
|
|
212
|
+
*
|
|
213
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
214
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { defineConfig } from "@razorwind/core";
|
|
219
|
+
* import vsce, { flattenTokens } from "@razorwind/vsce";
|
|
220
|
+
*
|
|
221
|
+
* export default defineConfig({
|
|
222
|
+
* plugins: [
|
|
223
|
+
* vsce({
|
|
224
|
+
* name: "my-theme",
|
|
225
|
+
* publisher: "acme",
|
|
226
|
+
* displayName: "My Theme",
|
|
227
|
+
* mapTheme: tokens => {
|
|
228
|
+
* const flat = flattenTokens(tokens);
|
|
229
|
+
* const color = (path: string) =>
|
|
230
|
+
* flat.find(t => t.path === path)?.cssValue ?? "#000000";
|
|
231
|
+
*
|
|
232
|
+
* return [
|
|
233
|
+
* {
|
|
234
|
+
* name: "my-theme-dark",
|
|
235
|
+
* displayName: "My Theme Dark",
|
|
236
|
+
* type: "dark",
|
|
237
|
+
* colors: {
|
|
238
|
+
* "editor.background": color("color.bg"),
|
|
239
|
+
* "editor.foreground": color("color.fg")
|
|
240
|
+
* }
|
|
241
|
+
* },
|
|
242
|
+
* {
|
|
243
|
+
* name: "my-theme-light",
|
|
244
|
+
* displayName: "My Theme Light",
|
|
245
|
+
* type: "light",
|
|
246
|
+
* colors: {
|
|
247
|
+
* "editor.background": color("color.bg"),
|
|
248
|
+
* "editor.foreground": color("color.fg")
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ];
|
|
252
|
+
* }
|
|
253
|
+
* })
|
|
254
|
+
* ]
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare const _default: (options?: VscePluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
259
|
+
//#endregion
|
|
260
|
+
export { type FlatToken, type GenerateVsCodeTheme, type VsCodeTheme, type VsCodeTokenColor, type VscePluginOptions, _default as default, flattenTokens, formatTokenValue, generateVsceExtension, normalizeThemes, renderPackageJson, renderThemeJson, resolveTokenSets, toCssVar };
|
|
261
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/generate.ts","../src/index.ts"],"mappings":";;;;;;;;UAwBiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;EACf;EACA;EACA;IACE;IACA;IACA;;;;;;;;UASa;;EAEf;;EAEA;;EAEA;EACA,SAAS;EACT,cAAc;EACd;EACA,sBAAsB;IAET;IAAqB;IAAoB;;;;;;;;KAS5C,uBACV,QAAQ,SAAS,eAAe,YAC7B,cAAc,gBAAgB,eAAe;;;;KAKtC;EAGN;EACA;EACA;;;;;;;;UASW;;;;;;;EAOf;;;;;;EAOA,UAAU;;;;;EAMV;;EAGA;;EAGA;;;;;;EAOA;;EAGA;;;;;EAMA;;;;EAKA;EAEA;IAGM;IACA;IACA;;EAGN;EAEA;IAGM;IACA;;EAGN,SAAS;;;;;EAMT;EAEA;IACE;IACA;;;;;EAMF;EAEA;;;;EAKA;IACE;;;;;;;;;;EAWF;;;;;EAMA;;;;;EAMA,eAAe;;;;;EAMf,cAAc;;;;UChHC;EACf;EACA,QAAQ;;;;;iBAMM,iBACd,QAAQ,SAAS,eAAe,UAC/B;;;;iBAwBa,cACd,QAAQ,SAAS,eAAe,SAChC,UAAS,KAAK,qCACb;;;;;;iBCjDa,gBACd,QAAQ,cAAc,gBAAgB,eAAe,eACpD;iBA0Ea,gBAAgB,OAAO;;;;iBA0BvB,kBACd,SAAS,mBACT,QAAQ;;;;iBA+DM,sBACd,MAAM,QACN,SAAS,oBACR,wBAAwB,QAAQ"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
2
|
+
import { Schema, Tokens } from "@razorwind/core/schema";
|
|
3
|
+
import { TokenType } from "@power-plant/dtcg-schema";
|
|
4
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A flattened design token ready for VS Code theme mapping.
|
|
8
|
+
*/
|
|
9
|
+
interface FlatToken {
|
|
10
|
+
/** Dot-separated token path (e.g. `color.primary`). */
|
|
11
|
+
path: string;
|
|
12
|
+
/** DTCG `$type`, when known. */
|
|
13
|
+
type?: TokenType | string;
|
|
14
|
+
/** Raw `$value` from the token document. */
|
|
15
|
+
value: unknown;
|
|
16
|
+
/** CSS-friendly string form of {@link value}. */
|
|
17
|
+
cssValue: string;
|
|
18
|
+
/** Optional DTCG `$description`. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Theme / set id when tokens are a `Record<string, Tokens>`. */
|
|
21
|
+
theme?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TextMate token color rule for a VS Code theme.
|
|
25
|
+
*
|
|
26
|
+
* @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
|
|
27
|
+
*/
|
|
28
|
+
interface VsCodeTokenColor {
|
|
29
|
+
name?: string;
|
|
30
|
+
scope?: string | string[];
|
|
31
|
+
settings: {
|
|
32
|
+
foreground?: string;
|
|
33
|
+
background?: string;
|
|
34
|
+
fontStyle?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* VS Code / TextMate color theme document.
|
|
39
|
+
*
|
|
40
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
41
|
+
*/
|
|
42
|
+
interface VsCodeTheme {
|
|
43
|
+
/** Stable theme id used for the theme file name. */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Marketplace / Color Theme picker label. Defaults to {@link name}. */
|
|
46
|
+
displayName?: string;
|
|
47
|
+
/** Theme kind — maps to `contributes.themes[].uiTheme`. */
|
|
48
|
+
type: "light" | "dark" | "hc" | "hcLight";
|
|
49
|
+
colors?: Record<string, string>;
|
|
50
|
+
tokenColors?: VsCodeTokenColor[];
|
|
51
|
+
semanticHighlighting?: boolean;
|
|
52
|
+
semanticTokenColors?: Record<string, string | {
|
|
53
|
+
foreground?: string;
|
|
54
|
+
fontStyle?: string;
|
|
55
|
+
bold?: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Map extracted design tokens to one or more VS Code theme documents.
|
|
60
|
+
*
|
|
61
|
+
* Return a single theme, an array, or a record keyed by theme id.
|
|
62
|
+
*/
|
|
63
|
+
type GenerateVsCodeTheme = (tokens: Tokens | Record<string, Tokens>) => VsCodeTheme | VsCodeTheme[] | Record<string, VsCodeTheme>;
|
|
64
|
+
/**
|
|
65
|
+
* package.json `author` field shape.
|
|
66
|
+
*/
|
|
67
|
+
type VscePackageAuthor = string | {
|
|
68
|
+
name: string;
|
|
69
|
+
email?: string;
|
|
70
|
+
url?: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Options for the Razorwind VS Code extension (theme) generator.
|
|
74
|
+
*
|
|
75
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
76
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
77
|
+
*/
|
|
78
|
+
interface VscePluginOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Directory (relative to the execution cwd) for the generated extension
|
|
81
|
+
* package.
|
|
82
|
+
*
|
|
83
|
+
* @defaultValue `"vscode-extension"`
|
|
84
|
+
*/
|
|
85
|
+
outputPath?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Map extracted tokens to VS Code theme JSON document(s).
|
|
88
|
+
*
|
|
89
|
+
* Required — without a mapping there is nothing to emit.
|
|
90
|
+
*/
|
|
91
|
+
mapTheme: GenerateVsCodeTheme;
|
|
92
|
+
/**
|
|
93
|
+
* Unscoped Marketplace extension id (`contributes` / VSIX name).
|
|
94
|
+
* Must not include an npm scope.
|
|
95
|
+
*/
|
|
96
|
+
name: string;
|
|
97
|
+
/** Marketplace display name. Defaults to a title-cased {@link name}. */
|
|
98
|
+
displayName?: string;
|
|
99
|
+
/** Marketplace short description. */
|
|
100
|
+
description?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Extension version (semver without prerelease tags — vsce rejects them).
|
|
103
|
+
*
|
|
104
|
+
* @defaultValue `"0.0.1"`
|
|
105
|
+
*/
|
|
106
|
+
version?: string;
|
|
107
|
+
/** Marketplace publisher id. */
|
|
108
|
+
publisher: string;
|
|
109
|
+
/**
|
|
110
|
+
* Unscoped name written into the VSIX shim when packaging.
|
|
111
|
+
* Defaults to {@link name}.
|
|
112
|
+
*/
|
|
113
|
+
extensionName?: string;
|
|
114
|
+
/**
|
|
115
|
+
* @defaultValue `"Apache-2.0"`
|
|
116
|
+
*/
|
|
117
|
+
license?: string;
|
|
118
|
+
repository?: string | {
|
|
119
|
+
type?: string;
|
|
120
|
+
url?: string;
|
|
121
|
+
directory?: string;
|
|
122
|
+
};
|
|
123
|
+
homepage?: string;
|
|
124
|
+
bugs?: string | {
|
|
125
|
+
url?: string;
|
|
126
|
+
email?: string;
|
|
127
|
+
};
|
|
128
|
+
author?: VscePackageAuthor;
|
|
129
|
+
/**
|
|
130
|
+
* Icon path relative to the extension root (e.g. `icon.png`).
|
|
131
|
+
* The file itself is not generated — place it beside the package.
|
|
132
|
+
*/
|
|
133
|
+
icon?: string;
|
|
134
|
+
galleryBanner?: {
|
|
135
|
+
color?: string;
|
|
136
|
+
theme?: "dark" | "light";
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* @defaultValue `["Themes"]`
|
|
140
|
+
*/
|
|
141
|
+
categories?: string[];
|
|
142
|
+
keywords?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* @defaultValue `{ vscode: "^1.85.0" }`
|
|
145
|
+
*/
|
|
146
|
+
engines?: {
|
|
147
|
+
vscode: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Emit pierre-style `scripts/` helpers and `package.json` script entries
|
|
151
|
+
* for packaging / publishing.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue `true`
|
|
154
|
+
*
|
|
155
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
156
|
+
*/
|
|
157
|
+
includeScripts?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Marketplace README body. When omitted, a minimal install guide is
|
|
160
|
+
* generated from the contributed themes.
|
|
161
|
+
*/
|
|
162
|
+
readme?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Restrict flattened helper tokens to these DTCG `$type` values.
|
|
165
|
+
* Does not filter what {@link mapTheme} receives.
|
|
166
|
+
*/
|
|
167
|
+
includeTypes?: TokenType[];
|
|
168
|
+
/**
|
|
169
|
+
* Extra fields merged into the generated extension `package.json`
|
|
170
|
+
* (shallow merge; `contributes.themes` / `scripts` from the plugin win).
|
|
171
|
+
*/
|
|
172
|
+
packageJson?: Record<string, unknown>;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/flatten.d.ts
|
|
176
|
+
interface TokenSet {
|
|
177
|
+
id: string;
|
|
178
|
+
tokens: Tokens;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Split `Schema.tokens` into one or more named token sets.
|
|
182
|
+
*/
|
|
183
|
+
declare function resolveTokenSets(tokens: Tokens | Record<string, Tokens>): TokenSet[];
|
|
184
|
+
/**
|
|
185
|
+
* Flatten DTCG token trees into rows helpful for {@link VscePluginOptions.mapTheme}.
|
|
186
|
+
*/
|
|
187
|
+
declare function flattenTokens(tokens: Tokens | Record<string, Tokens>, options?: Pick<VscePluginOptions, "includeTypes">): FlatToken[];
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/generate.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* Normalize {@link VscePluginOptions.mapTheme} results into a theme list.
|
|
192
|
+
*/
|
|
193
|
+
declare function normalizeThemes(result: VsCodeTheme | VsCodeTheme[] | Record<string, VsCodeTheme>): VsCodeTheme[];
|
|
194
|
+
declare function renderThemeJson(theme: VsCodeTheme): string;
|
|
195
|
+
/**
|
|
196
|
+
* Build the extension `package.json` manifest (themes + optional scripts).
|
|
197
|
+
*/
|
|
198
|
+
declare function renderPackageJson(options: VscePluginOptions, themes: VsCodeTheme[]): string;
|
|
199
|
+
/**
|
|
200
|
+
* Generate a publishable VS Code theme extension package from a Razorwind schema.
|
|
201
|
+
*/
|
|
202
|
+
declare function generateVsceExtension(spec: Schema, options: VscePluginOptions): GeneratorFunctionResult<Schema, VscePluginOptions>;
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/index.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* Razorwind plugin that turns design tokens into a publishable VS Code
|
|
207
|
+
* theme extension package (theme JSON, package.json, scripts, README).
|
|
208
|
+
*
|
|
209
|
+
* Provide {@link VscePluginOptions.mapTheme} to map extracted tokens to one
|
|
210
|
+
* or more VS Code theme documents. Packaging / publish helpers follow the
|
|
211
|
+
* pierre theme script layout.
|
|
212
|
+
*
|
|
213
|
+
* @see https://code.visualstudio.com/api/extension-guides/color-theme
|
|
214
|
+
* @see https://github.com/pierrecomputer/pierre/tree/main/packages/theme/scripts
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { defineConfig } from "@razorwind/core";
|
|
219
|
+
* import vsce, { flattenTokens } from "@razorwind/vsce";
|
|
220
|
+
*
|
|
221
|
+
* export default defineConfig({
|
|
222
|
+
* plugins: [
|
|
223
|
+
* vsce({
|
|
224
|
+
* name: "my-theme",
|
|
225
|
+
* publisher: "acme",
|
|
226
|
+
* displayName: "My Theme",
|
|
227
|
+
* mapTheme: tokens => {
|
|
228
|
+
* const flat = flattenTokens(tokens);
|
|
229
|
+
* const color = (path: string) =>
|
|
230
|
+
* flat.find(t => t.path === path)?.cssValue ?? "#000000";
|
|
231
|
+
*
|
|
232
|
+
* return [
|
|
233
|
+
* {
|
|
234
|
+
* name: "my-theme-dark",
|
|
235
|
+
* displayName: "My Theme Dark",
|
|
236
|
+
* type: "dark",
|
|
237
|
+
* colors: {
|
|
238
|
+
* "editor.background": color("color.bg"),
|
|
239
|
+
* "editor.foreground": color("color.fg")
|
|
240
|
+
* }
|
|
241
|
+
* },
|
|
242
|
+
* {
|
|
243
|
+
* name: "my-theme-light",
|
|
244
|
+
* displayName: "My Theme Light",
|
|
245
|
+
* type: "light",
|
|
246
|
+
* colors: {
|
|
247
|
+
* "editor.background": color("color.bg"),
|
|
248
|
+
* "editor.foreground": color("color.fg")
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ];
|
|
252
|
+
* }
|
|
253
|
+
* })
|
|
254
|
+
* ]
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare const _default: (options?: VscePluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
259
|
+
//#endregion
|
|
260
|
+
export { type FlatToken, type GenerateVsCodeTheme, type VsCodeTheme, type VsCodeTokenColor, type VscePluginOptions, _default as default, flattenTokens, formatTokenValue, generateVsceExtension, normalizeThemes, renderPackageJson, renderThemeJson, resolveTokenSets, toCssVar };
|
|
261
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/generate.ts","../src/index.ts"],"mappings":""}
|