@nooeh/cli 0.2.1 → 0.2.3
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/dist/doctor.js +6 -1
- package/dist/init.js +50 -17
- package/package.json +2 -2
package/dist/doctor.js
CHANGED
|
@@ -81,7 +81,12 @@ export async function doctor(projectDirectory) {
|
|
|
81
81
|
name: "UI path",
|
|
82
82
|
status: "pass",
|
|
83
83
|
});
|
|
84
|
-
const tokenFiles = [
|
|
84
|
+
const tokenFiles = [
|
|
85
|
+
"color-palette.stylex.ts",
|
|
86
|
+
"semantic.stylex.ts",
|
|
87
|
+
"themes.stylex.ts",
|
|
88
|
+
"theme-provider.tsx",
|
|
89
|
+
];
|
|
85
90
|
const hasTokenFiles = await Promise.all(tokenFiles.map(async (fileName) => {
|
|
86
91
|
try {
|
|
87
92
|
await access(resolve(tokenDirectory, fileName));
|
package/dist/init.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { join, relative } from "node:path";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
3
|
import { createInterface } from "node:readline/promises";
|
|
4
4
|
import { configFileName, defaultConfig, hasConfig, resolveConfigAlias, writeConfig, } from "./config.js";
|
|
5
5
|
import { installDependencies } from "./dependencies.js";
|
|
@@ -33,21 +33,48 @@ async function readViteConfig(projectDirectory) {
|
|
|
33
33
|
}
|
|
34
34
|
throw new Error("Could not find a Vite config file.");
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function getStylexPlugin(stylesAlias, tokenDirectory, projectDirectory) {
|
|
37
|
+
const tokenPath = relative(projectDirectory, tokenDirectory).split(sep).join("/");
|
|
38
|
+
const aliasPattern = `${stylesAlias}/*`;
|
|
39
|
+
const aliasTarget = `/ROOT/${tokenPath}/*`;
|
|
40
|
+
return `stylex.vite({
|
|
41
|
+
useCSSLayers: true,
|
|
42
|
+
aliases: { ${JSON.stringify(aliasPattern)}: [${JSON.stringify(aliasTarget)}] },
|
|
43
|
+
unstable_moduleResolution: {
|
|
44
|
+
type: "commonJS",
|
|
45
|
+
rootDir: new URL(".", import.meta.url).pathname,
|
|
46
|
+
},
|
|
47
|
+
})`;
|
|
48
|
+
}
|
|
49
|
+
function configureVite(source, stylesAlias, tokenDirectory, projectDirectory) {
|
|
37
50
|
const importLine = 'import stylex from "@stylexjs/unplugin";';
|
|
38
51
|
const pluginPattern = /plugins:\s*\[([^\]]*)\]/s;
|
|
39
52
|
const configPattern = /defineConfig\(\{\s*/;
|
|
53
|
+
const stylexPlugin = getStylexPlugin(stylesAlias, tokenDirectory, projectDirectory);
|
|
54
|
+
const legacyStylexPluginPattern = /stylex\.vite\(\{\s*useCSSLayers:\s*true\s*\}\)/;
|
|
55
|
+
const emptyStylexPluginPattern = /stylex\.vite\(\)/;
|
|
40
56
|
if (!source.includes("stylex.vite(") && !pluginPattern.test(source)) {
|
|
41
57
|
throw new Error("Could not safely update the Vite plugins array. Add stylex.vite({ useCSSLayers: true }) manually.");
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
let withStylex = source;
|
|
60
|
+
if (source.includes("unstable_moduleResolution")) {
|
|
61
|
+
withStylex = source;
|
|
62
|
+
}
|
|
63
|
+
else if (legacyStylexPluginPattern.test(source)) {
|
|
64
|
+
withStylex = source.replace(legacyStylexPluginPattern, stylexPlugin);
|
|
65
|
+
}
|
|
66
|
+
else if (emptyStylexPluginPattern.test(source)) {
|
|
67
|
+
withStylex = source.replace(emptyStylexPluginPattern, stylexPlugin);
|
|
68
|
+
}
|
|
69
|
+
else if (source.includes("stylex.vite(")) {
|
|
70
|
+
throw new Error("Could not safely update the existing StyleX plugin. Add Nooeh's aliases and unstable_moduleResolution manually.");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
withStylex = (source.includes(importLine) ? source : `${importLine}\n${source}`).replace(pluginPattern, (_, plugins) => {
|
|
74
|
+
const prefix = plugins.trim() ? `${stylexPlugin}, ${plugins}` : stylexPlugin;
|
|
49
75
|
return `plugins: [${prefix}]`;
|
|
50
76
|
});
|
|
77
|
+
}
|
|
51
78
|
if (withStylex.includes("alias:"))
|
|
52
79
|
return withStylex;
|
|
53
80
|
if (!configPattern.test(withStylex)) {
|
|
@@ -55,22 +82,28 @@ function configureVite(source) {
|
|
|
55
82
|
}
|
|
56
83
|
return withStylex.replace(configPattern, 'defineConfig({\n resolve: { alias: { "@": new URL("./src", import.meta.url).pathname } },\n ');
|
|
57
84
|
}
|
|
58
|
-
async function writeViteFiles(projectDirectory, tokenDirectory) {
|
|
85
|
+
async function writeViteFiles(projectDirectory, tokenDirectory, stylesAlias, refreshLegacyTokens) {
|
|
59
86
|
const { path: configPath, source: configSource } = await readViteConfig(projectDirectory);
|
|
60
|
-
const configuredVite = configureVite(configSource);
|
|
61
|
-
await writeNooehFiles(projectDirectory, tokenDirectory);
|
|
87
|
+
const configuredVite = configureVite(configSource, stylesAlias, tokenDirectory, projectDirectory);
|
|
88
|
+
await writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTokens);
|
|
62
89
|
await writeFile(configPath, configuredVite, "utf8");
|
|
63
90
|
console.log(`Configured Vite and created ${relative(projectDirectory, tokenDirectory)}.`);
|
|
64
91
|
}
|
|
65
|
-
async function writeNooehFiles(projectDirectory, tokenDirectory) {
|
|
92
|
+
async function writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTokens = false) {
|
|
66
93
|
await mkdir(tokenDirectory, { recursive: true });
|
|
67
94
|
for (const file of await getTokenFiles()) {
|
|
68
|
-
await
|
|
95
|
+
await writeTokenFile(join(tokenDirectory, file.name), file.content, refreshLegacyTokens && file.name === "semantic.stylex.ts");
|
|
69
96
|
}
|
|
70
97
|
}
|
|
71
|
-
|
|
98
|
+
function isLegacySemanticSource(source) {
|
|
99
|
+
return source.includes('bgCanvas: "initial"') && source.includes('overlay: "initial"');
|
|
100
|
+
}
|
|
101
|
+
async function writeTokenFile(path, source, shouldRefreshLegacyToken) {
|
|
72
102
|
try {
|
|
73
|
-
await
|
|
103
|
+
const currentSource = await readFile(path, "utf8");
|
|
104
|
+
if (shouldRefreshLegacyToken && isLegacySemanticSource(currentSource)) {
|
|
105
|
+
await writeFile(path, source, "utf8");
|
|
106
|
+
}
|
|
74
107
|
}
|
|
75
108
|
catch {
|
|
76
109
|
await writeFile(path, source, "utf8");
|
|
@@ -106,10 +139,10 @@ export async function init(projectDirectory, options) {
|
|
|
106
139
|
}
|
|
107
140
|
}
|
|
108
141
|
if (options.framework === "vite") {
|
|
109
|
-
await writeViteFiles(projectDirectory, tokenDirectory);
|
|
142
|
+
await writeViteFiles(projectDirectory, tokenDirectory, stylesAlias, Boolean(options.force));
|
|
110
143
|
}
|
|
111
144
|
else {
|
|
112
|
-
await writeNooehFiles(projectDirectory, tokenDirectory);
|
|
145
|
+
await writeNooehFiles(projectDirectory, tokenDirectory, Boolean(options.force));
|
|
113
146
|
console.log(`Created ${relative(projectDirectory, tokenDirectory)}.`);
|
|
114
147
|
console.log("Configure the StyleX compiler for your bundler before importing added components.");
|
|
115
148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nooeh/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"bin": {
|
|
6
6
|
"nooeh": "./dist/cli.js"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nooeh/registry": "0.1.
|
|
22
|
+
"@nooeh/registry": "0.1.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22.20.1",
|