@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.mjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t,formatTokenValue as n,formatTokenValue as r,isObject as i,toCssVar as a}from"@razorwind/core/utils";import{join as o}from"node:path";const s=/^(?: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 c(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function l(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function u(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function d(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 f(e,t,n,a,o){if(!i(e))return;let s=u(e,n);if(c(e)){let n=d(e);o.push({path:t.join(`.`),type:s,value:n,cssValue:r(n,s),description:l(e),theme:a});return}for(let[n,r]of Object.entries(e))n.startsWith(`$`)||f(r,[...t,n],s,a,o)}function p(e){if(!i(e))return[];let t=Object.keys(e).filter(e=>!e.startsWith(`$`));if(t.length>0&&t.every(e=>s.test(e))){let n=e;return t.map(e=>({id:e,tokens:n[e]}))}return[{id:`default`,tokens:e}]}function m(e,t={}){let n=t.includeTypes?new Set(t.includeTypes):void 0,r=[];for(let t of p(e)){let e=t.id==="default"?void 0:t.id;f(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}function h(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 g(){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 _(){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 v(){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 y(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 b(){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 x={name:`razorwind-vsce`},S={vscode:`^1.85.0`};function C(e,n,r){return t(e,n,x,r)}function w(e){return e.split(/[-_.\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function T(e){return e.trim().toLowerCase().replaceAll(/[^a-z0-9]+/g,`-`).replaceAll(/^-+|-+$/g,``)}function E(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 D(e){return i(e)&&typeof e.name==`string`&&(e.type===`light`||e.type===`dark`||e.type===`hc`||e.type===`hcLight`)}function O(e){if(Array.isArray(e))return e.map((e,t)=>{if(!D(e))throw TypeError(`@razorwind/vsce mapTheme()[${t}] must be a VsCodeTheme with name + type`);return e});if(D(e))return[e];if(!i(e))throw TypeError(`@razorwind/vsce mapTheme() must return a theme, theme array, or theme record`);return Object.entries(e).map(([e,t])=>{if(!D(t))throw TypeError(`@razorwind/vsce mapTheme()["${e}"] must be a VsCodeTheme with name + type`);return{...t,name:t.name||e}})}function k(e){if(typeof e==`string`)return e;if(e&&typeof e.url==`string`)return e.url}function A(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 j(e){return e===`light`||e===`hcLight`?`light`:`dark`}function M(e){let t={name:e.name,type:j(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 N(e,t){let n=e.includeScripts!==!1,r=e.displayName??w(e.name),a=e.description??`${r} — VS Code themes generated by Razorwind`,o={themes:t.map(e=>({label:e.displayName??e.name,uiTheme:E(e.type),path:`./themes/${T(e.name)}.json`}))},s=n?{"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:r,description:a,version:e.version??`0.0.1`,publisher:e.publisher,license:e.license??`Apache-2.0`,categories:e.categories??[`Themes`],engines:e.engines??{...S},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=i(c.scripts)&&!Array.isArray(c.scripts)?{...c.scripts,...s}:s),`${JSON.stringify(c,null,2)}\n`}function P(e,t){A(t);let n=t.outputPath??`vscode-extension`,r=t.includeScripts!==!1,i=t.extensionName??t.name,a=t.displayName??w(t.name),s=t.description??`${a} — VS Code themes generated by Razorwind`,c=O(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=`${T(e.name)}.json`,r=o(n,`themes`,t);l[r]=C(r,M(e),`json`)}let u=o(n,`package.json`);l[u]=C(u,N(t,c),`json`);let d=o(n,`.vscodeignore`);l[d]=C(d,b(),`ignore`);let f=c.map(e=>({label:e.displayName??e.name})),p=t.readme??y({displayName:a,description:s,themes:f,repositoryUrl:k(t.repository)}),m=o(n,`README.md`);if(l[m]=C(m,p,`markdown`),r){let e=o(n,`scripts`,`vsixPackageShim.ts`);l[e]=C(e,h(i),`typescript`);let r=o(n,`scripts`,`buildVsCodePackage.ts`);l[r]=C(r,g(),`typescript`);let c=o(n,`scripts`,`publishVsce.ts`);l[c]=C(c,_(),`typescript`);let u=o(n,`scripts`,`publishOvsx.ts`);l[u]=C(u,v(),`typescript`);let d=o(n,`scripts`,`README.package.md`);l[d]=C(d,y({displayName:a,description:s,themes:f,repositoryUrl:k(t.repository)}),`markdown`)}return l}var F=e(e=>({name:`vsce`,generate:async t=>{if(!e)throw Error(`@razorwind/vsce requires options: { name, publisher, mapTheme }`);return P(t,e)}}));export{F as default,m as flattenTokens,n as formatTokenValue,P as generateVsceExtension,O as normalizeThemes,N as renderPackageJson,M as renderThemeJson,p as resolveTokenSets,a as toCssVar};
|
|
153
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@razorwind/vsce",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Razorwind Visual Studio Code Extension plugin that creates theming extensions from design tokens.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "github",
|
|
8
|
+
"url": "https://github.com/storm-software/razorwind.git",
|
|
9
|
+
"directory": "packages/vsce"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://stormsoftware.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://stormsoftware.com/support",
|
|
14
|
+
"email": "support@stormsoftware.com"
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Storm Software",
|
|
18
|
+
"email": "contact@stormsoftware.com",
|
|
19
|
+
"url": "https://stormsoftware.com"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"private": false,
|
|
23
|
+
"files": ["dist"],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"vscode",
|
|
26
|
+
"vsce",
|
|
27
|
+
"theme",
|
|
28
|
+
"razorwind",
|
|
29
|
+
"design-tokens",
|
|
30
|
+
"dtcg",
|
|
31
|
+
"storm-software"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"default": "./dist/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.mts",
|
|
41
|
+
"default": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"default": {
|
|
44
|
+
"types": "./dist/index.d.mts",
|
|
45
|
+
"default": "./dist/index.mjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./generate": {
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/index.d.cts",
|
|
51
|
+
"default": "./dist/index.cjs"
|
|
52
|
+
},
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/index.d.mts",
|
|
55
|
+
"default": "./dist/index.mjs"
|
|
56
|
+
},
|
|
57
|
+
"default": {
|
|
58
|
+
"types": "./dist/index.d.mts",
|
|
59
|
+
"default": "./dist/index.mjs"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"./package.json": "./package.json"
|
|
63
|
+
},
|
|
64
|
+
"main": "./dist/index.cjs",
|
|
65
|
+
"module": "./dist/index.mjs",
|
|
66
|
+
"types": "./dist/index.d.cts",
|
|
67
|
+
"typings": "dist/index.d.mts",
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@power-plant/core": "^0.0.67",
|
|
70
|
+
"@power-plant/dtcg-schema": "^0.0.1",
|
|
71
|
+
"@razorwind/core": "^0.0.25"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@powerlines/plugin-tsdown": "^0.1.586",
|
|
75
|
+
"@types/node": "^25.9.5",
|
|
76
|
+
"typescript": "^6.0.3"
|
|
77
|
+
},
|
|
78
|
+
"publishConfig": { "access": "public" },
|
|
79
|
+
"gitHead": "4cac94d47388e7e4d0739cde32600845340eaba2"
|
|
80
|
+
}
|