@salty-css/core 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +83 -0
- package/astro-component-5hrNTCJ5.js +4 -0
- package/astro-component-Dj3enX6K.cjs +4 -0
- package/bin/commands/build.d.ts +2 -0
- package/bin/commands/generate.d.ts +2 -0
- package/bin/commands/init.d.ts +2 -0
- package/bin/commands/update.d.ts +2 -0
- package/bin/commands/version.d.ts +2 -0
- package/bin/confirm-install.d.ts +34 -0
- package/bin/context.d.ts +22 -0
- package/bin/detection/css-file.d.ts +5 -0
- package/bin/frameworks/astro.d.ts +4 -0
- package/bin/frameworks/index.d.ts +13 -0
- package/bin/frameworks/react.d.ts +2 -0
- package/bin/frameworks/types.d.ts +27 -0
- package/bin/integrations/astro.d.ts +11 -0
- package/bin/integrations/eslint.d.ts +6 -0
- package/bin/integrations/index.d.ts +21 -0
- package/bin/integrations/next.d.ts +9 -0
- package/bin/integrations/types.d.ts +29 -0
- package/bin/integrations/vite.d.ts +8 -0
- package/bin/main.cjs +653 -336
- package/bin/main.d.ts +8 -0
- package/bin/main.js +653 -336
- package/bin/package-json.d.ts +21 -0
- package/bin/saltyrc.d.ts +31 -0
- package/bin/templates.d.ts +14 -0
- package/{class-name-generator-B2Pb2obX.cjs → class-name-generator-DVuPkyrS.cjs} +1 -1
- package/{class-name-generator-YeSQe_Ik.js → class-name-generator-DkByUzHU.js} +1 -1
- package/compiler/salty-compiler.cjs +29 -8
- package/compiler/salty-compiler.d.ts +7 -1
- package/compiler/salty-compiler.js +29 -8
- package/config/index.cjs +2 -0
- package/config/index.js +3 -1
- package/css/dynamic-styles.cjs +15 -0
- package/css/dynamic-styles.d.ts +10 -0
- package/css/dynamic-styles.js +15 -0
- package/css/index.cjs +3 -0
- package/css/index.d.ts +1 -0
- package/css/index.js +3 -0
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/factories/define-font.d.ts +28 -0
- package/factories/index.cjs +128 -0
- package/factories/index.d.ts +1 -0
- package/factories/index.js +128 -0
- package/generators/index.cjs +1 -1
- package/generators/index.js +2 -2
- package/instances/classname-instance.cjs +1 -1
- package/instances/classname-instance.js +1 -1
- package/package.json +5 -1
- package/{parse-styles-CA3TP5n1.cjs → parse-styles-CX1WjafO.cjs} +106 -7
- package/{parse-styles-BTIoYnBr.js → parse-styles-DIqJjXF3.js} +107 -8
- package/parsers/index.cjs +2 -1
- package/parsers/index.d.ts +1 -0
- package/parsers/index.js +4 -3
- package/parsers/parser-regexes.d.ts +3 -0
- package/parsers/strict.d.ts +2 -0
- package/runtime/index.cjs +1 -1
- package/runtime/index.js +1 -1
- package/{salty.config-cqavVm2t.cjs → salty.config-DogY_sSQ.cjs} +1 -1
- package/salty.config-GV37Q-D2.js +4 -0
- package/styled-file-BzmB9_Ez.cjs +12 -0
- package/{react-styled-file-U02jek-B.cjs → styled-file-CPd_rTW2.cjs} +2 -2
- package/{react-styled-file-B99mwk0w.js → styled-file-Cda3EeR6.js} +2 -2
- package/styled-file-DLcgYmGN.js +12 -0
- package/types/config-types.d.ts +10 -1
- package/types/font-types.d.ts +53 -0
- package/{react-vanilla-file-D9px70iK.js → vanilla-file-1kOqbCIM.js} +2 -2
- package/{react-vanilla-file-Bj6XC8GS.cjs → vanilla-file-r0fp2q_m.cjs} +2 -2
- package/salty.config-DjosWdPw.js +0 -4
package/bin/main.cjs
CHANGED
|
@@ -2,16 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const commander = require("commander");
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const promises = require("fs/promises");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const ejs = require("ejs");
|
|
8
|
-
const pascalCase = require("../pascal-case-By_l58S-.cjs");
|
|
9
5
|
const compiler_saltyCompiler = require("../compiler/salty-compiler.cjs");
|
|
6
|
+
const compiler_helpers = require("../compiler/helpers.cjs");
|
|
7
|
+
const shouldRestart = require("../should-restart-CQsyHls3.cjs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const promises = require("fs/promises");
|
|
10
10
|
const child_process = require("child_process");
|
|
11
11
|
const ora = require("ora");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const pascalCase = require("../pascal-case-By_l58S-.cjs");
|
|
13
|
+
const ejs = require("ejs");
|
|
14
|
+
const promises$1 = require("readline/promises");
|
|
14
15
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
16
|
+
const defaultPackageJsonPath = path.join(process.cwd(), "package.json");
|
|
17
|
+
const readPackageJson = async (filePath = defaultPackageJsonPath) => {
|
|
18
|
+
const content = await promises.readFile(filePath, "utf-8").then(JSON.parse).catch(() => void 0);
|
|
19
|
+
if (!content) throw "Could not read package.json file!";
|
|
20
|
+
return content;
|
|
21
|
+
};
|
|
22
|
+
const updatePackageJson = async (content, filePath = defaultPackageJsonPath) => {
|
|
23
|
+
if (typeof content === "object") content = JSON.stringify(content, null, 2);
|
|
24
|
+
await promises.writeFile(filePath, content);
|
|
25
|
+
};
|
|
26
|
+
const readThisPackageJson = async () => {
|
|
27
|
+
const packageJsonPath = new URL("../package.json", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("bin/main.cjs", document.baseURI).href);
|
|
28
|
+
return readPackageJson(packageJsonPath);
|
|
29
|
+
};
|
|
30
|
+
const corePackages = {
|
|
31
|
+
core: (version) => `@salty-css/core@${version}`,
|
|
32
|
+
eslintConfigCore: (version) => `@salty-css/eslint-config-core@${version}`
|
|
33
|
+
};
|
|
34
|
+
const addPrepareScript = (pkg) => {
|
|
35
|
+
if (!pkg.scripts) pkg.scripts = {};
|
|
36
|
+
const current = pkg.scripts["prepare"];
|
|
37
|
+
if (current) {
|
|
38
|
+
if (current.includes("salty-css")) return { changed: false, pkg };
|
|
39
|
+
pkg.scripts["prepare"] = current + " && npx salty-css build";
|
|
40
|
+
} else {
|
|
41
|
+
pkg.scripts["prepare"] = "npx salty-css build";
|
|
42
|
+
}
|
|
43
|
+
return { changed: true, pkg };
|
|
44
|
+
};
|
|
15
45
|
const execAsync = (command) => {
|
|
16
46
|
return new Promise((resolve, reject) => {
|
|
17
47
|
child_process.exec(command, (error) => {
|
|
@@ -40,367 +70,633 @@ async function formatWithPrettier(filePath) {
|
|
|
40
70
|
compiler_saltyCompiler.logger.error(`Error formatting ${filePath} with Prettier:`, error);
|
|
41
71
|
}
|
|
42
72
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const packageJsonContent = await promises.readFile(filePath, "utf-8").then(JSON.parse).catch(() => void 0);
|
|
67
|
-
if (!packageJsonContent) throw "Could not read package.json file!";
|
|
68
|
-
return packageJsonContent;
|
|
69
|
-
};
|
|
70
|
-
const updatePackageJson = async (content, filePath = defaultPackageJsonPath) => {
|
|
71
|
-
if (typeof content === "object") content = JSON.stringify(content, null, 2);
|
|
72
|
-
await promises.writeFile(filePath, content);
|
|
73
|
-
};
|
|
74
|
-
const readThisPackageJson = async () => {
|
|
75
|
-
const packageJsonPath = new URL("../package.json", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("bin/main.cjs", document.baseURI).href);
|
|
76
|
-
return readPackageJson(packageJsonPath);
|
|
77
|
-
};
|
|
78
|
-
const getDefaultProject = async () => {
|
|
79
|
-
const rcContent = await readRCFile();
|
|
80
|
-
return rcContent.defaultProject;
|
|
81
|
-
};
|
|
82
|
-
const defaultProject = await getDefaultProject();
|
|
83
|
-
const currentPackageJson = await readThisPackageJson();
|
|
84
|
-
const packages = {
|
|
85
|
-
core: `@salty-css/core@${currentPackageJson.version}`,
|
|
86
|
-
react: `@salty-css/react@${currentPackageJson.version}`,
|
|
87
|
-
eslintConfigCore: `@salty-css/eslint-config-core@${currentPackageJson.version}`,
|
|
88
|
-
vite: `@salty-css/vite@${currentPackageJson.version}`,
|
|
89
|
-
next: `@salty-css/next@${currentPackageJson.version}`
|
|
90
|
-
};
|
|
91
|
-
const resolveProjectDir = (dir) => {
|
|
92
|
-
const dirName = dir === "." ? "" : dir;
|
|
93
|
-
const rootDir = process.cwd();
|
|
94
|
-
const projectDir = path.join(rootDir, dirName);
|
|
95
|
-
return projectDir;
|
|
96
|
-
};
|
|
97
|
-
program.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(_dir = ".") {
|
|
98
|
-
const packageJson = await readPackageJson().catch(() => void 0);
|
|
99
|
-
if (!packageJson) return compiler_saltyCompiler.logError("Salty CSS project must be initialized in a directory with a package.json file.");
|
|
100
|
-
compiler_saltyCompiler.logger.info("Initializing a new Salty-CSS project!");
|
|
101
|
-
const { dir = _dir, cssFile, skipInstall } = this.opts();
|
|
102
|
-
if (!dir) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
|
|
103
|
-
if (!skipInstall) await npmInstall(packages.core, packages.react);
|
|
104
|
-
const rootDir = process.cwd();
|
|
105
|
-
const projectDir = resolveProjectDir(dir);
|
|
106
|
-
const projectFiles = await Promise.all([readTemplate("salty.config.ts"), readTemplate("saltygen/index.css")]);
|
|
107
|
-
const saltyCompiler = new compiler_saltyCompiler.SaltyCompiler(projectDir);
|
|
108
|
-
await promises.mkdir(projectDir, { recursive: true });
|
|
109
|
-
const writeFiles = projectFiles.map(async ({ fileName, content }) => {
|
|
110
|
-
const filePath = path.join(projectDir, fileName);
|
|
111
|
-
const existingContent = await promises.readFile(filePath, "utf-8").catch(() => void 0);
|
|
112
|
-
if (existingContent !== void 0) {
|
|
113
|
-
compiler_saltyCompiler.logger.debug("File already exists: " + filePath);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const additionalFolders = fileName.split("/").slice(0, -1).join("/");
|
|
117
|
-
if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
|
|
118
|
-
compiler_saltyCompiler.logger.info("Creating file: " + filePath);
|
|
119
|
-
await promises.writeFile(filePath, content);
|
|
120
|
-
await formatWithPrettier(filePath);
|
|
121
|
-
});
|
|
122
|
-
await Promise.all(writeFiles);
|
|
123
|
-
const relativeProjectPath = path.relative(rootDir, projectDir) || ".";
|
|
124
|
-
const saltyrcPath = path.join(rootDir, ".saltyrc.json");
|
|
125
|
-
const existingSaltyrc = await promises.readFile(saltyrcPath, "utf-8").catch(() => void 0);
|
|
126
|
-
if (existingSaltyrc === void 0) {
|
|
127
|
-
compiler_saltyCompiler.logger.info("Creating file: " + saltyrcPath);
|
|
128
|
-
const rcContent = {
|
|
129
|
-
$schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
|
|
130
|
-
info: "This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",
|
|
131
|
-
defaultProject: relativeProjectPath,
|
|
132
|
-
projects: [
|
|
133
|
-
{
|
|
134
|
-
dir: relativeProjectPath,
|
|
135
|
-
framework: "react"
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
};
|
|
139
|
-
const content = JSON.stringify(rcContent, null, 2);
|
|
140
|
-
await promises.writeFile(saltyrcPath, content);
|
|
141
|
-
await formatWithPrettier(saltyrcPath);
|
|
142
|
-
} else {
|
|
143
|
-
const rcContent = JSON.parse(existingSaltyrc);
|
|
144
|
-
const projects = (rcContent == null ? void 0 : rcContent.projects) || [];
|
|
145
|
-
const projectIndex = projects.findIndex((p) => p.dir === relativeProjectPath);
|
|
146
|
-
if (projectIndex === -1) {
|
|
147
|
-
projects.push({ dir: relativeProjectPath, framework: "react" });
|
|
148
|
-
rcContent.projects = [...projects];
|
|
149
|
-
const content = JSON.stringify(rcContent, null, 2);
|
|
150
|
-
if (content !== existingSaltyrc) {
|
|
151
|
-
compiler_saltyCompiler.logger.info("Edit file: " + saltyrcPath);
|
|
152
|
-
await promises.writeFile(saltyrcPath, content);
|
|
153
|
-
await formatWithPrettier(saltyrcPath);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const gitIgnorePath = path.join(rootDir, ".gitignore");
|
|
158
|
-
const gitIgnoreContent = await promises.readFile(gitIgnorePath, "utf-8").catch(() => void 0);
|
|
159
|
-
if (gitIgnoreContent !== void 0) {
|
|
160
|
-
const alreadyIgnoresSaltygen = gitIgnoreContent.includes("saltygen");
|
|
161
|
-
if (!alreadyIgnoresSaltygen) {
|
|
162
|
-
compiler_saltyCompiler.logger.info("Edit file: " + gitIgnorePath);
|
|
163
|
-
await promises.writeFile(gitIgnorePath, gitIgnoreContent + "\n\n# Salty-CSS\nsaltygen\n");
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const cssFileFoldersToLookFor = ["src", "public", "assets", "styles", "css", "app"];
|
|
167
|
-
const secondLevelFolders = ["styles", "css", "app", "pages"];
|
|
168
|
-
const cssFilesToLookFor = ["index", "styles", "main", "app", "global", "globals"];
|
|
169
|
-
const cssFileExtensions = [".css", ".scss", ".sass"];
|
|
170
|
-
const getTargetCssFile = async () => {
|
|
171
|
-
if (cssFile) return cssFile;
|
|
172
|
-
for (const folder of cssFileFoldersToLookFor) {
|
|
173
|
-
for (const file of cssFilesToLookFor) {
|
|
174
|
-
for (const ext of cssFileExtensions) {
|
|
175
|
-
const filePath = path.join(projectDir, folder, file + ext);
|
|
176
|
-
const fileContent = await promises.readFile(filePath, "utf-8").catch(() => void 0);
|
|
177
|
-
if (fileContent !== void 0) return path.relative(projectDir, filePath);
|
|
178
|
-
for (const secondLevelFolder of secondLevelFolders) {
|
|
179
|
-
const filePath2 = path.join(projectDir, folder, secondLevelFolder, file + ext);
|
|
180
|
-
const fileContent2 = await promises.readFile(filePath2, "utf-8").catch(() => void 0);
|
|
181
|
-
if (fileContent2 !== void 0) return path.relative(projectDir, filePath2);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return void 0;
|
|
187
|
-
};
|
|
188
|
-
const targetCSSFile = await getTargetCssFile();
|
|
189
|
-
if (targetCSSFile) {
|
|
190
|
-
const cssFilePath = path.join(projectDir, targetCSSFile);
|
|
191
|
-
const cssFileContent = await promises.readFile(cssFilePath, "utf-8").catch(() => void 0);
|
|
192
|
-
if (cssFileContent !== void 0) {
|
|
193
|
-
const alreadyImportsSaltygen = cssFileContent.includes("saltygen");
|
|
194
|
-
if (!alreadyImportsSaltygen) {
|
|
195
|
-
const cssFileFolder = path.join(cssFilePath, "..");
|
|
196
|
-
const relativePath = path.relative(cssFileFolder, path.join(projectDir, "saltygen/index.css"));
|
|
197
|
-
const importStatement = `@import '${relativePath}';`;
|
|
198
|
-
compiler_saltyCompiler.logger.info("Adding global import statement to CSS file: " + cssFilePath);
|
|
199
|
-
await promises.writeFile(cssFilePath, importStatement + "\n" + cssFileContent);
|
|
200
|
-
await formatWithPrettier(cssFilePath);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
compiler_saltyCompiler.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
|
|
205
|
-
}
|
|
206
|
-
const eslintConfigs = {
|
|
207
|
-
projectJs: path.join(projectDir, "eslint.config.js"),
|
|
208
|
-
rootJs: path.join(rootDir, "eslint.config.js"),
|
|
209
|
-
projectMjs: path.join(projectDir, "eslint.config.mjs"),
|
|
210
|
-
rootMjs: path.join(rootDir, "eslint.config.mjs"),
|
|
211
|
-
projectJson: path.join(projectDir, ".eslintrc.json"),
|
|
212
|
-
rootJson: path.join(rootDir, ".eslintrc.json")
|
|
73
|
+
const SALTYRC_FILENAME = ".saltyrc.json";
|
|
74
|
+
const SALTYRC_SCHEMA = "./node_modules/@salty-css/core/.saltyrc.schema.json";
|
|
75
|
+
const SALTYRC_INFO = "This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.";
|
|
76
|
+
const saltyrcPath = (rootDir = process.cwd()) => path.join(rootDir, SALTYRC_FILENAME);
|
|
77
|
+
const readRc = async (rootDir = process.cwd()) => {
|
|
78
|
+
const content = await promises.readFile(saltyrcPath(rootDir), "utf-8").then(JSON.parse).catch(() => ({}));
|
|
79
|
+
return content;
|
|
80
|
+
};
|
|
81
|
+
const readRawRc = async (rootDir = process.cwd()) => {
|
|
82
|
+
return promises.readFile(saltyrcPath(rootDir), "utf-8").catch(() => void 0);
|
|
83
|
+
};
|
|
84
|
+
const getDefaultProject = async (rootDir = process.cwd()) => {
|
|
85
|
+
const rc = await readRc(rootDir);
|
|
86
|
+
return rc.defaultProject;
|
|
87
|
+
};
|
|
88
|
+
const upsertProjectInRc = (existingRaw, relativeProjectPath, framework) => {
|
|
89
|
+
const projectPath = path.join(relativeProjectPath, framework.srcDirectory);
|
|
90
|
+
if (existingRaw === void 0) {
|
|
91
|
+
const fresh = {
|
|
92
|
+
$schema: SALTYRC_SCHEMA,
|
|
93
|
+
info: SALTYRC_INFO,
|
|
94
|
+
defaultProject: projectPath,
|
|
95
|
+
projects: [{ dir: projectPath, framework: framework.name }]
|
|
213
96
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const alreadyHasPlugin = nextConfigContent.includes("withSaltyCss");
|
|
269
|
-
if (!alreadyHasPlugin) {
|
|
270
|
-
let saltyCssAppended = false;
|
|
271
|
-
const hasPluginsArray = /\splugins([^=]*)=[^[]\[/.test(nextConfigContent);
|
|
272
|
-
if (hasPluginsArray && !saltyCssAppended) {
|
|
273
|
-
nextConfigContent = nextConfigContent.replace(/\splugins([^=]*)=[^[]\[/, (_, config) => {
|
|
274
|
-
return ` plugins${config}= [withSaltyCss,`;
|
|
275
|
-
});
|
|
276
|
-
saltyCssAppended = true;
|
|
277
|
-
}
|
|
278
|
-
const useRequire = nextConfigContent.includes("module.exports");
|
|
279
|
-
const pluginImport = useRequire ? "const { withSaltyCss } = require('@salty-css/next');\n" : "import { withSaltyCss } from '@salty-css/next';\n";
|
|
280
|
-
if (useRequire && !saltyCssAppended) {
|
|
281
|
-
nextConfigContent = nextConfigContent.replace(/module.exports = ([^;]+)/, (_, config) => {
|
|
282
|
-
return `module.exports = withSaltyCss(${config})`;
|
|
283
|
-
});
|
|
284
|
-
saltyCssAppended = true;
|
|
285
|
-
} else if (!saltyCssAppended) {
|
|
286
|
-
nextConfigContent = nextConfigContent.replace(/export default ([^;]+)/, (_, config) => {
|
|
287
|
-
return `export default withSaltyCss(${config})`;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
if (!skipInstall) await npmInstall(`-D ${packages.next}`);
|
|
291
|
-
compiler_saltyCompiler.logger.info("Adding Salty-CSS plugin to Next.js config...");
|
|
292
|
-
await promises.writeFile(nextConfigPath, pluginImport + nextConfigContent);
|
|
293
|
-
await formatWithPrettier(nextConfigPath);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const packageJsonContent = await readPackageJson().catch(() => compiler_saltyCompiler.logError("Could not read package.json file.")).then((content) => {
|
|
298
|
-
if (!content.scripts) content.scripts = {};
|
|
299
|
-
if (content.scripts.prepare) {
|
|
300
|
-
const alreadyHasSaltyCss = content.scripts.prepare.includes("salty-css");
|
|
301
|
-
if (!alreadyHasSaltyCss) {
|
|
302
|
-
compiler_saltyCompiler.logger.info("Edit file: " + defaultPackageJsonPath);
|
|
303
|
-
content.scripts.prepare = content.scripts.prepare + " && npx salty-css build";
|
|
304
|
-
}
|
|
305
|
-
} else {
|
|
306
|
-
compiler_saltyCompiler.logger.info("Edit file: " + defaultPackageJsonPath);
|
|
307
|
-
content.scripts.prepare = "npx salty-css build";
|
|
308
|
-
}
|
|
309
|
-
return content;
|
|
310
|
-
});
|
|
311
|
-
await updatePackageJson(packageJsonContent);
|
|
312
|
-
compiler_saltyCompiler.logger.info("Running the build to generate initial CSS...");
|
|
313
|
-
await saltyCompiler.generateCss();
|
|
314
|
-
compiler_saltyCompiler.logger.info("🎉 Salty CSS project initialized successfully!");
|
|
315
|
-
compiler_saltyCompiler.logger.info("Next steps:");
|
|
316
|
-
compiler_saltyCompiler.logger.info("1. Configure variables and templates in `salty.config.ts`");
|
|
317
|
-
compiler_saltyCompiler.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
|
|
318
|
-
compiler_saltyCompiler.logger.info("3. Run `npx salty-css build` to generate the CSS");
|
|
319
|
-
compiler_saltyCompiler.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
|
|
320
|
-
compiler_saltyCompiler.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
|
|
321
|
-
});
|
|
322
|
-
program.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").option("--watch", "Watch for changes and rebuild the project.").action(async function(_dir = defaultProject) {
|
|
97
|
+
return { content: JSON.stringify(fresh, null, 2), changed: true, created: true };
|
|
98
|
+
}
|
|
99
|
+
const rc = JSON.parse(existingRaw);
|
|
100
|
+
const projects = rc.projects || [];
|
|
101
|
+
const exists = projects.some((p) => p.dir === projectPath);
|
|
102
|
+
if (exists) return { content: existingRaw, changed: false, created: false };
|
|
103
|
+
projects.push({ dir: projectPath, framework: framework.name });
|
|
104
|
+
rc.projects = [...projects];
|
|
105
|
+
const next = JSON.stringify(rc, null, 2);
|
|
106
|
+
return { content: next, changed: next !== existingRaw, created: false };
|
|
107
|
+
};
|
|
108
|
+
const writeProjectToRc = async (cwd, relativeProjectPath, framework) => {
|
|
109
|
+
const path2 = saltyrcPath(cwd);
|
|
110
|
+
const existing = await readRawRc(cwd);
|
|
111
|
+
const { content, changed, created } = upsertProjectInRc(existing, relativeProjectPath, framework);
|
|
112
|
+
if (!changed) return false;
|
|
113
|
+
if (created) compiler_saltyCompiler.logger.info("Creating file: " + path2);
|
|
114
|
+
else compiler_saltyCompiler.logger.info("Edit file: " + path2);
|
|
115
|
+
await promises.writeFile(path2, content);
|
|
116
|
+
await formatWithPrettier(path2);
|
|
117
|
+
return true;
|
|
118
|
+
};
|
|
119
|
+
const getProjectFramework = (rc, relativeProjectPath) => {
|
|
120
|
+
const projects = rc.projects || [];
|
|
121
|
+
const entry = projects.find((p) => p.dir === relativeProjectPath);
|
|
122
|
+
return entry == null ? void 0 : entry.framework;
|
|
123
|
+
};
|
|
124
|
+
const resolveProjectDir = (dir, rootDir = process.cwd()) => {
|
|
125
|
+
const dirName = dir === "." ? "" : dir;
|
|
126
|
+
return path.join(rootDir, dirName);
|
|
127
|
+
};
|
|
128
|
+
const buildContext = async (opts) => {
|
|
129
|
+
const cwd = process.cwd();
|
|
130
|
+
const projectDir = resolveProjectDir(opts.dir, cwd);
|
|
131
|
+
const relativeProjectPath = path.relative(cwd, projectDir) || ".";
|
|
132
|
+
const packageJson = await readPackageJson().catch(() => void 0);
|
|
133
|
+
if (opts.requirePackageJson !== false && !packageJson) {
|
|
134
|
+
throw new Error("Salty CSS project must be initialized in a directory with a package.json file.");
|
|
135
|
+
}
|
|
136
|
+
const rcFile = await readRc(cwd);
|
|
137
|
+
const cliPackageJson = await readThisPackageJson();
|
|
138
|
+
return {
|
|
139
|
+
cwd,
|
|
140
|
+
projectDir,
|
|
141
|
+
relativeProjectPath,
|
|
142
|
+
packageJson,
|
|
143
|
+
rcFile,
|
|
144
|
+
cliVersion: cliPackageJson.version || "0.0.0",
|
|
145
|
+
skipInstall: !!opts.skipInstall,
|
|
146
|
+
yes: !!opts.yes
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const registerBuildCommand = (program, defaultProject) => {
|
|
150
|
+
program.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").option("--watch", "Watch for changes and rebuild the project.").option("--mode <mode>", 'Build mode: "production" or "development". Defaults to NODE_ENV-based detection.').action(async function(_dir = defaultProject) {
|
|
323
151
|
compiler_saltyCompiler.logger.info("Building the Salty-CSS project...");
|
|
324
|
-
const { dir = _dir, watch } = this.opts();
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
await
|
|
152
|
+
const { dir = _dir, watch, mode } = this.opts();
|
|
153
|
+
if (mode !== void 0 && mode !== "production" && mode !== "development") {
|
|
154
|
+
return compiler_saltyCompiler.logError(`Invalid --mode "${mode}". Expected "production" or "development".`);
|
|
155
|
+
}
|
|
156
|
+
const resolved = dir ?? await getDefaultProject();
|
|
157
|
+
if (!resolved) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
|
|
158
|
+
const projectDir = resolveProjectDir(resolved);
|
|
159
|
+
const compiler = new compiler_saltyCompiler.SaltyCompiler(projectDir, { mode });
|
|
160
|
+
await compiler.generateCss();
|
|
329
161
|
if (watch) {
|
|
330
162
|
compiler_saltyCompiler.logger.info("Watching for changes in the project directory...");
|
|
331
|
-
fs.watch(projectDir, { recursive: true }, async (
|
|
163
|
+
fs.watch(projectDir, { recursive: true }, async (_event, filePath) => {
|
|
332
164
|
const shouldRestart$1 = await shouldRestart.checkShouldRestart(filePath);
|
|
333
165
|
if (shouldRestart$1) {
|
|
334
|
-
await
|
|
335
|
-
} else {
|
|
336
|
-
|
|
337
|
-
if (saltyFile) await saltyCompiler.generateFile(filePath);
|
|
166
|
+
await compiler.generateCss(false);
|
|
167
|
+
} else if (compiler_helpers.isSaltyFile(filePath)) {
|
|
168
|
+
await compiler.generateFile(filePath);
|
|
338
169
|
}
|
|
339
170
|
});
|
|
340
171
|
}
|
|
341
172
|
});
|
|
342
|
-
|
|
173
|
+
};
|
|
174
|
+
const astroConfigFiles = ["astro.config.mjs", "astro.config.ts", "astro.config.js", "astro.config.cjs"];
|
|
175
|
+
const findAstroConfig = (projectDir) => {
|
|
176
|
+
for (const name of astroConfigFiles) {
|
|
177
|
+
const path$1 = path.join(projectDir, name);
|
|
178
|
+
if (fs.existsSync(path$1)) return path$1;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
const hasAstroDependency = (ctx) => {
|
|
183
|
+
const pkg = ctx.packageJson;
|
|
184
|
+
if (!pkg) return false;
|
|
185
|
+
const all = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
186
|
+
return Object.prototype.hasOwnProperty.call(all, "astro");
|
|
187
|
+
};
|
|
188
|
+
const astroFramework = {
|
|
189
|
+
name: "astro",
|
|
190
|
+
srcDirectory: "src",
|
|
191
|
+
detect: (ctx) => Boolean(findAstroConfig(ctx.projectDir)) || hasAstroDependency(ctx),
|
|
192
|
+
runtimePackage: (version) => `@salty-css/astro@${version}`,
|
|
193
|
+
templates: {
|
|
194
|
+
styled: "astro/styled-file.ts",
|
|
195
|
+
component: {
|
|
196
|
+
styled: "astro/styled-file.ts",
|
|
197
|
+
wrapper: "astro/component.astro",
|
|
198
|
+
wrapperExt: ".astro"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const reactFramework = {
|
|
203
|
+
name: "react",
|
|
204
|
+
srcDirectory: "",
|
|
205
|
+
detect: () => true,
|
|
206
|
+
// default fallback — evaluated last in the registry
|
|
207
|
+
runtimePackage: (version) => `@salty-css/react@${version}`,
|
|
208
|
+
templates: {
|
|
209
|
+
styled: "react/styled-file.ts",
|
|
210
|
+
component: {
|
|
211
|
+
styled: "react/styled-file.ts",
|
|
212
|
+
wrapper: "react/vanilla-file.ts",
|
|
213
|
+
wrapperExt: ".tsx"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const frameworkRegistry = [astroFramework, reactFramework];
|
|
218
|
+
const frameworksByName = {
|
|
219
|
+
astro: astroFramework,
|
|
220
|
+
react: reactFramework
|
|
221
|
+
};
|
|
222
|
+
const detectFramework = async (ctx) => {
|
|
223
|
+
for (const adapter of frameworkRegistry) {
|
|
224
|
+
if (await adapter.detect(ctx)) return adapter;
|
|
225
|
+
}
|
|
226
|
+
return reactFramework;
|
|
227
|
+
};
|
|
228
|
+
const getFramework = (name) => {
|
|
229
|
+
if (!name) return void 0;
|
|
230
|
+
return frameworksByName[name];
|
|
231
|
+
};
|
|
232
|
+
const templateLoaders = {
|
|
233
|
+
"salty.config.ts": () => Promise.resolve().then(() => require("../salty.config-DogY_sSQ.cjs")),
|
|
234
|
+
"saltygen/index.css": () => Promise.resolve().then(() => require("../index-ByR0nfaf.cjs")),
|
|
235
|
+
"react/styled-file.ts": () => Promise.resolve().then(() => require("../styled-file-CPd_rTW2.cjs")),
|
|
236
|
+
"react/vanilla-file.ts": () => Promise.resolve().then(() => require("../vanilla-file-r0fp2q_m.cjs")),
|
|
237
|
+
"astro/styled-file.ts": () => Promise.resolve().then(() => require("../styled-file-BzmB9_Ez.cjs")),
|
|
238
|
+
"astro/component.astro": () => Promise.resolve().then(() => require("../astro-component-Dj3enX6K.cjs"))
|
|
239
|
+
};
|
|
240
|
+
const readTemplate = async (key, options) => {
|
|
241
|
+
const { default: file } = await templateLoaders[key]();
|
|
242
|
+
const content = ejs.render(file, options);
|
|
243
|
+
return { fileName: key, content };
|
|
244
|
+
};
|
|
245
|
+
const registerGenerateCommand = (program, defaultProject) => {
|
|
246
|
+
program.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").option("-r, --reactComponent", "Generate a wrapper component file alongside the styled definition.").action(async function(_file, _dir = defaultProject) {
|
|
343
247
|
const { file = _file, dir = _dir, tag, name, className, reactComponent = false } = this.opts();
|
|
344
248
|
if (!file) return compiler_saltyCompiler.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
|
|
345
249
|
if (!dir) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
|
|
346
|
-
|
|
250
|
+
let ctx;
|
|
251
|
+
try {
|
|
252
|
+
ctx = await buildContext({ dir, requirePackageJson: false });
|
|
253
|
+
} catch (err) {
|
|
254
|
+
return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
|
|
255
|
+
}
|
|
256
|
+
const rcFramework = getFramework(getProjectFramework(ctx.rcFile, ctx.relativeProjectPath));
|
|
257
|
+
const framework = rcFramework ?? await detectFramework(ctx);
|
|
347
258
|
const additionalFolders = file.split("/").slice(0, -1).join("/");
|
|
348
|
-
if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
|
|
349
|
-
const filePath = path.join(projectDir, file);
|
|
259
|
+
if (additionalFolders) await promises.mkdir(path.join(ctx.projectDir, additionalFolders), { recursive: true });
|
|
260
|
+
const filePath = path.join(ctx.projectDir, file);
|
|
350
261
|
const parsedFilePath = path.parse(filePath);
|
|
351
|
-
if (!parsedFilePath.ext)
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
if (!parsedFilePath.name.endsWith(".css")) {
|
|
355
|
-
parsedFilePath.name = parsedFilePath.name + ".css";
|
|
356
|
-
}
|
|
262
|
+
if (!parsedFilePath.ext) parsedFilePath.ext = ".ts";
|
|
263
|
+
if (!parsedFilePath.name.endsWith(".css")) parsedFilePath.name = parsedFilePath.name + ".css";
|
|
357
264
|
parsedFilePath.base = parsedFilePath.name + parsedFilePath.ext;
|
|
358
265
|
const formattedStyledFilePath = path.format(parsedFilePath);
|
|
359
266
|
const alreadyExists = await promises.readFile(formattedStyledFilePath, "utf-8").catch(() => void 0);
|
|
360
267
|
if (alreadyExists !== void 0) {
|
|
361
|
-
compiler_saltyCompiler.logger.error("File already exists:"
|
|
268
|
+
compiler_saltyCompiler.logger.error("File already exists: " + formattedStyledFilePath);
|
|
362
269
|
return;
|
|
363
270
|
}
|
|
364
271
|
let styledComponentName = pascalCase.pascalCase(name || parsedFilePath.base.replace(/\.css\.\w+$/, ""));
|
|
365
272
|
if (reactComponent) {
|
|
273
|
+
if (!framework.templates.component) {
|
|
274
|
+
return compiler_saltyCompiler.logError(`--reactComponent is not supported for the ${framework.name} framework.`);
|
|
275
|
+
}
|
|
366
276
|
const componentName = styledComponentName + "Component";
|
|
367
277
|
styledComponentName = styledComponentName + "Wrapper";
|
|
368
278
|
const fileName = parsedFilePath.base.replace(/\.css\.\w+$/, "");
|
|
369
|
-
const { content:
|
|
279
|
+
const { content: wrapperContent } = await readTemplate(framework.templates.component.wrapper, {
|
|
280
|
+
tag,
|
|
281
|
+
componentName,
|
|
282
|
+
styledComponentName,
|
|
283
|
+
className,
|
|
284
|
+
fileName
|
|
285
|
+
});
|
|
370
286
|
parsedFilePath.name = fileName.replace(/\.css$/, "");
|
|
371
|
-
parsedFilePath.ext =
|
|
287
|
+
parsedFilePath.ext = framework.templates.component.wrapperExt;
|
|
372
288
|
parsedFilePath.base = parsedFilePath.name + parsedFilePath.ext;
|
|
373
|
-
const
|
|
374
|
-
compiler_saltyCompiler.logger.info("Generating a new file: " +
|
|
375
|
-
await promises.writeFile(
|
|
376
|
-
await formatWithPrettier(
|
|
289
|
+
const formattedWrapperPath = path.format(parsedFilePath);
|
|
290
|
+
compiler_saltyCompiler.logger.info("Generating a new file: " + formattedWrapperPath);
|
|
291
|
+
await promises.writeFile(formattedWrapperPath, wrapperContent);
|
|
292
|
+
await formatWithPrettier(formattedWrapperPath);
|
|
377
293
|
}
|
|
378
|
-
const
|
|
294
|
+
const styledKey = reactComponent && framework.templates.component ? framework.templates.component.styled : framework.templates.styled;
|
|
295
|
+
const { content } = await readTemplate(styledKey, { tag, name: styledComponentName, className });
|
|
379
296
|
compiler_saltyCompiler.logger.info("Generating a new file: " + formattedStyledFilePath);
|
|
380
297
|
await promises.writeFile(formattedStyledFilePath, content);
|
|
381
298
|
await formatWithPrettier(formattedStyledFilePath);
|
|
382
299
|
});
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
300
|
+
};
|
|
301
|
+
const formatPackageForDisplay = (spec) => {
|
|
302
|
+
const trimmed = spec.trim();
|
|
303
|
+
if (trimmed.startsWith("-D ")) return `${trimmed.slice(3).trim()} (dev)`;
|
|
304
|
+
return trimmed;
|
|
305
|
+
};
|
|
306
|
+
const renderPackageList = (packages) => {
|
|
307
|
+
return packages.map((p) => ` + ${formatPackageForDisplay(p)}`).join("\n");
|
|
308
|
+
};
|
|
309
|
+
const confirmInstall = async (packages, yes, options = {}) => {
|
|
310
|
+
if (yes) return;
|
|
311
|
+
if (packages.length === 0) return;
|
|
312
|
+
const input = options.input ?? process.stdin;
|
|
313
|
+
const output = options.output ?? process.stdout;
|
|
314
|
+
const isTTY = options.isTTY ?? process.stdin.isTTY ?? false;
|
|
315
|
+
if (!isTTY) {
|
|
316
|
+
throw new Error("Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.");
|
|
317
|
+
}
|
|
318
|
+
output.write(`The following packages will be installed:
|
|
319
|
+
${renderPackageList(packages)}
|
|
320
|
+
`);
|
|
321
|
+
const rl = promises$1.createInterface({ input, output, terminal: false });
|
|
322
|
+
try {
|
|
323
|
+
const answer = (await rl.question("Proceed? (y/N) ")).trim().toLowerCase();
|
|
324
|
+
if (answer !== "y" && answer !== "yes") {
|
|
325
|
+
throw new Error("Install cancelled by user.");
|
|
393
326
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
327
|
+
} finally {
|
|
328
|
+
rl.close();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
const confirmYesNo = async (question, options = {}) => {
|
|
332
|
+
if (options.yes) return true;
|
|
333
|
+
const input = options.input ?? process.stdin;
|
|
334
|
+
const output = options.output ?? process.stdout;
|
|
335
|
+
const isTTY = options.isTTY ?? process.stdin.isTTY ?? false;
|
|
336
|
+
if (!isTTY) return false;
|
|
337
|
+
const suffix = options.defaultYes ? "(Y/n)" : "(y/N)";
|
|
338
|
+
const rl = promises$1.createInterface({ input, output, terminal: false });
|
|
339
|
+
try {
|
|
340
|
+
const answer = (await rl.question(`${question} ${suffix} `)).trim().toLowerCase();
|
|
341
|
+
if (answer === "") return !!options.defaultYes;
|
|
342
|
+
return answer === "y" || answer === "yes";
|
|
343
|
+
} finally {
|
|
344
|
+
rl.close();
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const CSS_FILE_FOLDERS = ["src", "public", "assets", "styles", "css", "app"];
|
|
348
|
+
const CSS_SECOND_LEVEL_FOLDERS = ["styles", "css", "app", "pages"];
|
|
349
|
+
const CSS_FILE_NAMES = ["index", "styles", "main", "app", "global", "globals"];
|
|
350
|
+
const CSS_FILE_EXTENSIONS = [".css", ".scss", ".sass"];
|
|
351
|
+
const findGlobalCssFile = async (projectDir) => {
|
|
352
|
+
for (const folder of CSS_FILE_FOLDERS) {
|
|
353
|
+
for (const file of CSS_FILE_NAMES) {
|
|
354
|
+
for (const ext of CSS_FILE_EXTENSIONS) {
|
|
355
|
+
const filePath = path.join(projectDir, folder, file + ext);
|
|
356
|
+
const fileContent = await promises.readFile(filePath, "utf-8").catch(() => void 0);
|
|
357
|
+
if (fileContent !== void 0) return path.relative(projectDir, filePath);
|
|
358
|
+
for (const second of CSS_SECOND_LEVEL_FOLDERS) {
|
|
359
|
+
const nestedPath = path.join(projectDir, folder, second, file + ext);
|
|
360
|
+
const nestedContent = await promises.readFile(nestedPath, "utf-8").catch(() => void 0);
|
|
361
|
+
if (nestedContent !== void 0) return path.relative(projectDir, nestedPath);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return void 0;
|
|
367
|
+
};
|
|
368
|
+
const astroPackage = (version) => `@salty-css/astro@${version}`;
|
|
369
|
+
const SALTY_ASTRO_IMPORT = "import saltyIntegration from '@salty-css/astro/integration';\n";
|
|
370
|
+
const editAstroConfig = (existing) => {
|
|
371
|
+
if (existing.includes("@salty-css/astro")) return { content: null };
|
|
372
|
+
let next = existing;
|
|
373
|
+
let inserted = false;
|
|
374
|
+
if (/integrations\s*:\s*\[/.test(next)) {
|
|
375
|
+
next = next.replace(/integrations\s*:\s*\[/, (m) => `${m}saltyIntegration(),`);
|
|
376
|
+
inserted = true;
|
|
377
|
+
} else if (/defineConfig\s*\(\s*\{/.test(next)) {
|
|
378
|
+
next = next.replace(/defineConfig\s*\(\s*\{/, (m) => `${m}
|
|
379
|
+
integrations: [saltyIntegration()],`);
|
|
380
|
+
inserted = true;
|
|
381
|
+
}
|
|
382
|
+
if (!inserted) {
|
|
383
|
+
return {
|
|
384
|
+
content: null,
|
|
385
|
+
warning: "Could not find a place to add saltyIntegration() in the Astro config. Please add it manually."
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return { content: SALTY_ASTRO_IMPORT + next };
|
|
389
|
+
};
|
|
390
|
+
const astroIntegration = {
|
|
391
|
+
name: "astro",
|
|
392
|
+
detect: (ctx) => findAstroConfig(ctx.projectDir),
|
|
393
|
+
plan: async (ctx, configPath) => {
|
|
394
|
+
const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
|
|
395
|
+
if (existing === void 0) return null;
|
|
396
|
+
const result = editAstroConfig(existing);
|
|
397
|
+
if (result.warning) compiler_saltyCompiler.logger.warn(result.warning);
|
|
398
|
+
if (result.content === null) return null;
|
|
399
|
+
const newContent = result.content;
|
|
400
|
+
return {
|
|
401
|
+
packages: [`-D ${astroPackage(ctx.cliVersion)}`],
|
|
402
|
+
execute: async () => {
|
|
403
|
+
compiler_saltyCompiler.logger.info("Adding Salty-CSS integration to Astro config: " + configPath);
|
|
404
|
+
await promises.writeFile(configPath, newContent);
|
|
405
|
+
await formatWithPrettier(configPath);
|
|
406
|
+
return { changed: true };
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const ESLINT_CONFIG_CANDIDATES = [
|
|
412
|
+
// Project-local candidates first, then root-level.
|
|
413
|
+
["projectJs", "eslint.config.js"],
|
|
414
|
+
["rootJs", "eslint.config.js"],
|
|
415
|
+
["projectMjs", "eslint.config.mjs"],
|
|
416
|
+
["rootMjs", "eslint.config.mjs"],
|
|
417
|
+
["projectJson", ".eslintrc.json"],
|
|
418
|
+
["rootJson", ".eslintrc.json"]
|
|
419
|
+
];
|
|
420
|
+
const eslintConfigCandidates = (projectDir, rootDir) => {
|
|
421
|
+
return ESLINT_CONFIG_CANDIDATES.map(([scope, name]) => {
|
|
422
|
+
const base = scope.startsWith("root") ? rootDir : projectDir;
|
|
423
|
+
return path.join(base, name);
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
const editEslintConfig = (existing, isJsFlat) => {
|
|
427
|
+
if (existing.includes("salty-css")) return { content: null };
|
|
428
|
+
if (isJsFlat) {
|
|
429
|
+
const importStatement = 'import saltyCss from "@salty-css/eslint-config-core/flat";';
|
|
430
|
+
let newContent = `${importStatement}
|
|
431
|
+
${existing}`;
|
|
432
|
+
const isTsEslint = existing.includes("typescript-eslint");
|
|
433
|
+
if (isTsEslint) {
|
|
434
|
+
if (newContent.includes(".config(")) {
|
|
435
|
+
newContent = newContent.replace(".config(", ".config(saltyCss,");
|
|
436
|
+
} else {
|
|
437
|
+
return {
|
|
438
|
+
content: null,
|
|
439
|
+
warning: "Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
if (newContent.includes("export default [")) {
|
|
444
|
+
newContent = newContent.replace("export default [", "export default [ saltyCss,");
|
|
445
|
+
} else if (newContent.includes("eslintConfig = [")) {
|
|
446
|
+
newContent = newContent.replace("eslintConfig = [", "eslintConfig = [ saltyCss,");
|
|
447
|
+
} else {
|
|
448
|
+
return {
|
|
449
|
+
content: null,
|
|
450
|
+
warning: "Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return { content: newContent };
|
|
455
|
+
}
|
|
456
|
+
const json = JSON.parse(existing);
|
|
457
|
+
if (!json.extends) json.extends = [];
|
|
458
|
+
if (!json.extends.includes("@salty-css/core")) json.extends.push("@salty-css/core");
|
|
459
|
+
return { content: JSON.stringify(json, null, 2) };
|
|
460
|
+
};
|
|
461
|
+
const eslintIntegration = {
|
|
462
|
+
name: "eslint",
|
|
463
|
+
detect: (ctx) => {
|
|
464
|
+
const candidates = eslintConfigCandidates(ctx.projectDir, ctx.cwd);
|
|
465
|
+
return candidates.find((p) => fs.existsSync(p)) ?? null;
|
|
466
|
+
},
|
|
467
|
+
plan: async (ctx, configPath) => {
|
|
468
|
+
const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
|
|
469
|
+
if (existing === void 0) {
|
|
470
|
+
compiler_saltyCompiler.logger.error("Could not read ESLint config file.");
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
const result = editEslintConfig(existing, configPath.endsWith("js"));
|
|
474
|
+
if (result.warning) compiler_saltyCompiler.logger.warn(result.warning);
|
|
475
|
+
if (result.content === null) return null;
|
|
476
|
+
const newContent = result.content;
|
|
477
|
+
return {
|
|
478
|
+
packages: [corePackages.eslintConfigCore(ctx.cliVersion)],
|
|
479
|
+
execute: async () => {
|
|
480
|
+
compiler_saltyCompiler.logger.info("Edit file: " + configPath);
|
|
481
|
+
await promises.writeFile(configPath, newContent);
|
|
482
|
+
await formatWithPrettier(configPath);
|
|
483
|
+
return { changed: true };
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const nextConfigFiles = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"];
|
|
489
|
+
const nextPackage = (version) => `@salty-css/next@${version}`;
|
|
490
|
+
const editNextConfig = (existing) => {
|
|
491
|
+
if (existing.includes("withSaltyCss")) return { content: null };
|
|
492
|
+
let next = existing;
|
|
493
|
+
let saltyCssAppended = false;
|
|
494
|
+
const hasPluginsArray = /\splugins([^=]*)=[^[]\[/.test(next);
|
|
495
|
+
if (hasPluginsArray) {
|
|
496
|
+
next = next.replace(/\splugins([^=]*)=[^[]\[/, (_, config) => ` plugins${config}= [withSaltyCss,`);
|
|
497
|
+
saltyCssAppended = true;
|
|
498
|
+
}
|
|
499
|
+
const useRequire = next.includes("module.exports");
|
|
500
|
+
const pluginImport = useRequire ? "const { withSaltyCss } = require('@salty-css/next');\n" : "import { withSaltyCss } from '@salty-css/next';\n";
|
|
501
|
+
if (useRequire && !saltyCssAppended) {
|
|
502
|
+
next = next.replace(/module.exports = ([^;]+)/, (_, config) => `module.exports = withSaltyCss(${config})`);
|
|
503
|
+
saltyCssAppended = true;
|
|
504
|
+
} else if (!saltyCssAppended) {
|
|
505
|
+
next = next.replace(/export default ([^;]+)/, (_, config) => `export default withSaltyCss(${config})`);
|
|
506
|
+
}
|
|
507
|
+
return { content: pluginImport + next };
|
|
508
|
+
};
|
|
509
|
+
const nextIntegration = {
|
|
510
|
+
name: "next",
|
|
511
|
+
detect: (ctx) => {
|
|
512
|
+
const found = nextConfigFiles.map((file) => path.join(ctx.projectDir, file)).find((p) => fs.existsSync(p));
|
|
513
|
+
return found ?? null;
|
|
514
|
+
},
|
|
515
|
+
plan: async (ctx, configPath) => {
|
|
516
|
+
const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
|
|
517
|
+
if (existing === void 0) return null;
|
|
518
|
+
const { content } = editNextConfig(existing);
|
|
519
|
+
if (content === null) return null;
|
|
520
|
+
return {
|
|
521
|
+
packages: [`-D ${nextPackage(ctx.cliVersion)}`],
|
|
522
|
+
execute: async () => {
|
|
523
|
+
compiler_saltyCompiler.logger.info("Adding Salty-CSS plugin to Next.js config...");
|
|
524
|
+
await promises.writeFile(configPath, content);
|
|
525
|
+
await formatWithPrettier(configPath);
|
|
526
|
+
return { changed: true };
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const vitePackage = (version) => `@salty-css/vite@${version}`;
|
|
532
|
+
const editViteConfig = (existing) => {
|
|
533
|
+
if (existing.includes("saltyPlugin")) return { content: null };
|
|
534
|
+
const pluginImport = "import { saltyPlugin } from '@salty-css/vite';\n";
|
|
535
|
+
const pluginConfig = "saltyPlugin(__dirname),";
|
|
536
|
+
const withPlugin = existing.replace(/(plugins: \[)/, `$1
|
|
537
|
+
${pluginConfig}`);
|
|
538
|
+
return { content: pluginImport + withPlugin };
|
|
539
|
+
};
|
|
540
|
+
const viteIntegration = {
|
|
541
|
+
name: "vite",
|
|
542
|
+
detect: (ctx) => {
|
|
543
|
+
const path$1 = path.join(ctx.projectDir, "vite.config.ts");
|
|
544
|
+
return fs.existsSync(path$1) ? path$1 : null;
|
|
545
|
+
},
|
|
546
|
+
plan: async (ctx, configPath) => {
|
|
547
|
+
const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
|
|
548
|
+
if (existing === void 0) return null;
|
|
549
|
+
const { content } = editViteConfig(existing);
|
|
550
|
+
if (content === null) return null;
|
|
551
|
+
return {
|
|
552
|
+
packages: [`-D ${vitePackage(ctx.cliVersion)}`],
|
|
553
|
+
execute: async () => {
|
|
554
|
+
compiler_saltyCompiler.logger.info("Edit file: " + configPath);
|
|
555
|
+
compiler_saltyCompiler.logger.info("Adding Salty-CSS plugin to Vite config...");
|
|
556
|
+
await promises.writeFile(configPath, content);
|
|
557
|
+
await formatWithPrettier(configPath);
|
|
558
|
+
return { changed: true };
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
const buildIntegrationRegistry = [eslintIntegration, viteIntegration, nextIntegration, astroIntegration];
|
|
564
|
+
const planIntegrations = async (ctx) => {
|
|
565
|
+
const planned = [];
|
|
566
|
+
for (const integration of buildIntegrationRegistry) {
|
|
567
|
+
const configPath = await integration.detect(ctx);
|
|
568
|
+
if (!configPath) continue;
|
|
569
|
+
const plan = await integration.plan(ctx, configPath);
|
|
570
|
+
if (!plan) continue;
|
|
571
|
+
planned.push({ name: integration.name, configPath, plan });
|
|
572
|
+
}
|
|
573
|
+
return planned;
|
|
574
|
+
};
|
|
575
|
+
const applyIntegrationPlans = async (planned) => {
|
|
576
|
+
const results = [];
|
|
577
|
+
for (const { name, configPath, plan } of planned) {
|
|
578
|
+
const result = await plan.execute();
|
|
579
|
+
results.push({ name, configPath, changed: result.changed });
|
|
580
|
+
}
|
|
581
|
+
return results;
|
|
582
|
+
};
|
|
583
|
+
const writeProjectFile = async (projectDir, fileName, content) => {
|
|
584
|
+
const filePath = path.join(projectDir, fileName);
|
|
585
|
+
if (fs.existsSync(filePath)) {
|
|
586
|
+
compiler_saltyCompiler.logger.debug("File already exists: " + filePath);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const additionalFolders = fileName.split("/").slice(0, -1).join("/");
|
|
590
|
+
if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
|
|
591
|
+
compiler_saltyCompiler.logger.info("Creating file: " + filePath);
|
|
592
|
+
await promises.writeFile(filePath, content);
|
|
593
|
+
await formatWithPrettier(filePath);
|
|
594
|
+
};
|
|
595
|
+
const ensureGitignoreSaltygen = async (rootDir) => {
|
|
596
|
+
const path$1 = path.join(rootDir, ".gitignore");
|
|
597
|
+
const existing = await promises.readFile(path$1, "utf-8").catch(() => void 0);
|
|
598
|
+
if (existing === void 0) return;
|
|
599
|
+
if (existing.includes("saltygen")) return;
|
|
600
|
+
compiler_saltyCompiler.logger.info("Edit file: " + path$1);
|
|
601
|
+
await promises.writeFile(path$1, existing + "\n\n# Salty-CSS\nsaltygen\n");
|
|
602
|
+
};
|
|
603
|
+
const importSaltygenIntoCss = async (projectDir, explicitCssFile) => {
|
|
604
|
+
const target = explicitCssFile ?? await findGlobalCssFile(projectDir);
|
|
605
|
+
if (!target) {
|
|
606
|
+
compiler_saltyCompiler.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const cssFilePath = path.join(projectDir, target);
|
|
610
|
+
const cssFileContent = await promises.readFile(cssFilePath, "utf-8").catch(() => void 0);
|
|
611
|
+
if (cssFileContent === void 0) return;
|
|
612
|
+
if (cssFileContent.includes("saltygen")) return;
|
|
613
|
+
const cssFileFolder = path.join(cssFilePath, "..");
|
|
614
|
+
const relPath = path.relative(cssFileFolder, path.join(projectDir, "saltygen/index.css"));
|
|
615
|
+
compiler_saltyCompiler.logger.info("Adding global import statement to CSS file: " + cssFilePath);
|
|
616
|
+
await promises.writeFile(cssFilePath, `@import '${relPath}';
|
|
617
|
+
` + cssFileContent);
|
|
618
|
+
await formatWithPrettier(cssFilePath);
|
|
619
|
+
};
|
|
620
|
+
const wirePrepareScript = async () => {
|
|
621
|
+
const pkg = await readPackageJson().catch(() => {
|
|
622
|
+
compiler_saltyCompiler.logError("Could not read package.json file.");
|
|
623
|
+
return void 0;
|
|
624
|
+
});
|
|
625
|
+
if (!pkg) return;
|
|
626
|
+
const { pkg: next } = addPrepareScript(pkg);
|
|
627
|
+
await updatePackageJson(next);
|
|
628
|
+
};
|
|
629
|
+
const registerInitCommand = (program) => {
|
|
630
|
+
program.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").option("-y, --yes", "Skip the install confirmation prompt.").action(async function(_dir = ".") {
|
|
631
|
+
try {
|
|
632
|
+
const opts = this.opts();
|
|
633
|
+
const dir = opts.dir ?? _dir;
|
|
634
|
+
if (!dir) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
|
|
635
|
+
const ctx = await buildContext({ dir, skipInstall: opts.skipInstall, yes: opts.yes });
|
|
636
|
+
compiler_saltyCompiler.logger.info("Initializing a new Salty-CSS project!");
|
|
637
|
+
const framework = await detectFramework(ctx);
|
|
638
|
+
compiler_saltyCompiler.logger.info(`Detected framework: ${framework.name}`);
|
|
639
|
+
const plannedIntegrations = await planIntegrations(ctx);
|
|
640
|
+
if (!ctx.skipInstall) {
|
|
641
|
+
const packages = [
|
|
642
|
+
corePackages.core(ctx.cliVersion),
|
|
643
|
+
framework.runtimePackage(ctx.cliVersion),
|
|
644
|
+
...plannedIntegrations.flatMap((p) => p.plan.packages)
|
|
645
|
+
];
|
|
646
|
+
await confirmInstall(packages, ctx.yes);
|
|
647
|
+
await npmInstall(...packages);
|
|
648
|
+
}
|
|
649
|
+
const projectFiles = await Promise.all([readTemplate("salty.config.ts"), readTemplate("saltygen/index.css")]);
|
|
650
|
+
await promises.mkdir(ctx.projectDir, { recursive: true });
|
|
651
|
+
await Promise.all(projectFiles.map(({ fileName, content }) => writeProjectFile(ctx.projectDir, fileName, content)));
|
|
652
|
+
await writeProjectToRc(ctx.cwd, ctx.relativeProjectPath, framework);
|
|
653
|
+
await ensureGitignoreSaltygen(ctx.cwd);
|
|
654
|
+
await importSaltygenIntoCss(ctx.projectDir, opts.cssFile);
|
|
655
|
+
await applyIntegrationPlans(plannedIntegrations);
|
|
656
|
+
await wirePrepareScript();
|
|
657
|
+
compiler_saltyCompiler.logger.info("Running the build to generate initial CSS...");
|
|
658
|
+
const compiler = new compiler_saltyCompiler.SaltyCompiler(ctx.projectDir);
|
|
659
|
+
await compiler.generateCss();
|
|
660
|
+
compiler_saltyCompiler.logger.info("🎉 Salty CSS project initialized successfully!");
|
|
661
|
+
compiler_saltyCompiler.logger.info("Next steps:");
|
|
662
|
+
compiler_saltyCompiler.logger.info("1. Configure variables and templates in `salty.config.ts`");
|
|
663
|
+
compiler_saltyCompiler.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
|
|
664
|
+
compiler_saltyCompiler.logger.info("3. Run `npx salty-css build` to generate the CSS");
|
|
665
|
+
compiler_saltyCompiler.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
|
|
666
|
+
compiler_saltyCompiler.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
|
|
667
|
+
} catch (err) {
|
|
668
|
+
return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
};
|
|
672
|
+
const getSaltyCssPackages = async () => {
|
|
673
|
+
const packageJSONPath = path.join(process.cwd(), "package.json");
|
|
674
|
+
const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_saltyCompiler.logError(err));
|
|
675
|
+
if (!packageJson) return compiler_saltyCompiler.logError("Could not read package.json file.");
|
|
676
|
+
const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
677
|
+
const saltyCssPackages = Object.entries(allDependencies).filter(([name]) => name === "salty-css" || name.startsWith("@salty-css/"));
|
|
678
|
+
if (!saltyCssPackages.length) {
|
|
679
|
+
return compiler_saltyCompiler.logError(
|
|
680
|
+
"No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
return saltyCssPackages;
|
|
684
|
+
};
|
|
685
|
+
const registerUpdateCommand = (program) => {
|
|
686
|
+
program.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>", "Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", false).option("-y, --yes", "Skip confirmation prompts (install and rebuild).").option("-d, --dir <dir>", "Project directory to rebuild after updating.").action(async function(_version = "latest") {
|
|
687
|
+
const { legacyPeerDeps, version = _version, yes = false, dir } = this.opts();
|
|
398
688
|
const saltyCssPackages = await getSaltyCssPackages();
|
|
399
689
|
if (!saltyCssPackages) return compiler_saltyCompiler.logError("Could not update Salty-CSS packages as any were found in package.json.");
|
|
690
|
+
const cli = await readThisPackageJson();
|
|
400
691
|
const packagesToUpdate = saltyCssPackages.map(([name]) => {
|
|
401
|
-
if (version === "@") return `${name}@${
|
|
692
|
+
if (version === "@") return `${name}@${cli.version}`;
|
|
402
693
|
return `${name}@${version.replace(/^@/, "")}`;
|
|
403
694
|
});
|
|
695
|
+
try {
|
|
696
|
+
await confirmInstall(packagesToUpdate, yes);
|
|
697
|
+
} catch (err) {
|
|
698
|
+
return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
|
|
699
|
+
}
|
|
404
700
|
if (legacyPeerDeps) {
|
|
405
701
|
compiler_saltyCompiler.logger.warn("Using legacy peer dependencies to update packages.");
|
|
406
702
|
await npmInstall(...packagesToUpdate, "--legacy-peer-deps");
|
|
@@ -416,19 +712,30 @@ ${eslintConfigContent}`;
|
|
|
416
712
|
}, {});
|
|
417
713
|
const versionsCount = Object.keys(mappedByVersions).length;
|
|
418
714
|
if (versionsCount === 1) {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
compiler_saltyCompiler.logger.info(`Updated to all Salty CSS packages successfully to ${versionString}`);
|
|
715
|
+
const v = Object.keys(mappedByVersions)[0];
|
|
716
|
+
compiler_saltyCompiler.logger.info(`Updated to all Salty CSS packages successfully to ${v.replace(/^\^/, "")}`);
|
|
422
717
|
} else {
|
|
423
|
-
for (const [
|
|
424
|
-
|
|
425
|
-
compiler_saltyCompiler.logger.info(`Updated to ${versionString}: ${names.join(", ")}`);
|
|
718
|
+
for (const [v, names] of Object.entries(mappedByVersions)) {
|
|
719
|
+
compiler_saltyCompiler.logger.info(`Updated to ${v.replace(/^\^/, "")}: ${names.join(", ")}`);
|
|
426
720
|
}
|
|
427
721
|
}
|
|
722
|
+
const project = dir ?? await getDefaultProject();
|
|
723
|
+
if (!project) {
|
|
724
|
+
compiler_saltyCompiler.logger.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const shouldRebuild = await confirmYesNo("Rebuild Salty CSS now?", { yes });
|
|
728
|
+
if (!shouldRebuild) return;
|
|
729
|
+
const projectDir = resolveProjectDir(project);
|
|
730
|
+
compiler_saltyCompiler.logger.info("Rebuilding Salty-CSS project...");
|
|
731
|
+
await new compiler_saltyCompiler.SaltyCompiler(projectDir).generateCss();
|
|
732
|
+
compiler_saltyCompiler.logger.info("Rebuild complete.");
|
|
428
733
|
});
|
|
734
|
+
};
|
|
735
|
+
const registerVersionOption = (program) => {
|
|
429
736
|
program.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
|
|
430
|
-
const
|
|
431
|
-
compiler_saltyCompiler.logger.info("CLI is running: " +
|
|
737
|
+
const cli = await readThisPackageJson();
|
|
738
|
+
compiler_saltyCompiler.logger.info("CLI is running: " + cli.version);
|
|
432
739
|
const packageJSONPath = path.join(process.cwd(), "package.json");
|
|
433
740
|
const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_saltyCompiler.logError(err));
|
|
434
741
|
if (!packageJson) return;
|
|
@@ -443,6 +750,16 @@ ${eslintConfigContent}`;
|
|
|
443
750
|
compiler_saltyCompiler.logger.info(`${dep}: ${allDependencies[dep]}`);
|
|
444
751
|
}
|
|
445
752
|
});
|
|
753
|
+
};
|
|
754
|
+
async function main() {
|
|
755
|
+
const program = new commander.Command();
|
|
756
|
+
program.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
|
|
757
|
+
const defaultProject = await getDefaultProject();
|
|
758
|
+
registerInitCommand(program);
|
|
759
|
+
registerBuildCommand(program, defaultProject);
|
|
760
|
+
registerGenerateCommand(program, defaultProject);
|
|
761
|
+
registerUpdateCommand(program);
|
|
762
|
+
registerVersionOption(program);
|
|
446
763
|
program.parseAsync(process.argv);
|
|
447
764
|
}
|
|
448
765
|
exports.main = main;
|