@salty-css/core 0.0.1-alpha.303 → 0.0.1-alpha.305

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/bin/main.cjs CHANGED
@@ -7,6 +7,7 @@ const path = require("path");
7
7
  const ejs = require("ejs");
8
8
  const compiler_index = require("../compiler/index.cjs");
9
9
  const pascalCase = require("../pascal-case-By_l58S-.cjs");
10
+ const saltyReset = require("../salty-reset-wJhVT2ys.cjs");
10
11
  const child_process = require("child_process");
11
12
  const ora = require("ora");
12
13
  const shouldRestart = require("../should-restart-DoaGoD5T.cjs");
@@ -34,9 +35,9 @@ async function formatWithPrettier(filePath) {
34
35
  const hasPrettier = hasPrettierInstalled();
35
36
  if (!hasPrettier) return;
36
37
  await execAsync(`./node_modules/.bin/prettier --write "${filePath}"`);
37
- compiler_index.logger.info(`Formatted ${filePath} with Prettier`);
38
+ saltyReset.logger.info(`Formatted ${filePath} with Prettier`);
38
39
  } catch (error) {
39
- compiler_index.logger.error(`Error formatting ${filePath} with Prettier:`, error);
40
+ saltyReset.logger.error(`Error formatting ${filePath} with Prettier:`, error);
40
41
  }
41
42
  }
42
43
  async function main() {
@@ -95,10 +96,10 @@ async function main() {
95
96
  };
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 = ".") {
97
98
  const packageJson = await readPackageJson().catch(() => void 0);
98
- if (!packageJson) return compiler_index.logError("Salty CSS project must be initialized in a directory with a package.json file.");
99
- compiler_index.logger.info("Initializing a new Salty-CSS project!");
99
+ if (!packageJson) return saltyReset.logError("Salty CSS project must be initialized in a directory with a package.json file.");
100
+ saltyReset.logger.info("Initializing a new Salty-CSS project!");
100
101
  const { dir = _dir, cssFile, skipInstall } = this.opts();
101
- if (!dir) return compiler_index.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
102
+ if (!dir) return saltyReset.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
102
103
  if (!skipInstall) await npmInstall(packages.core, packages.react);
103
104
  const rootDir = process.cwd();
104
105
  const projectDir = resolveProjectDir(dir);
@@ -108,12 +109,12 @@ async function main() {
108
109
  const filePath = path.join(projectDir, fileName);
109
110
  const existingContent = await promises.readFile(filePath, "utf-8").catch(() => void 0);
110
111
  if (existingContent !== void 0) {
111
- compiler_index.logger.debug("File already exists: " + filePath);
112
+ saltyReset.logger.debug("File already exists: " + filePath);
112
113
  return;
113
114
  }
114
115
  const additionalFolders = fileName.split("/").slice(0, -1).join("/");
115
116
  if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
116
- compiler_index.logger.info("Creating file: " + filePath);
117
+ saltyReset.logger.info("Creating file: " + filePath);
117
118
  await promises.writeFile(filePath, content);
118
119
  await formatWithPrettier(filePath);
119
120
  });
@@ -122,7 +123,7 @@ async function main() {
122
123
  const saltyrcPath = path.join(rootDir, ".saltyrc.json");
123
124
  const existingSaltyrc = await promises.readFile(saltyrcPath, "utf-8").catch(() => void 0);
124
125
  if (existingSaltyrc === void 0) {
125
- compiler_index.logger.info("Creating file: " + saltyrcPath);
126
+ saltyReset.logger.info("Creating file: " + saltyrcPath);
126
127
  const rcContent = {
127
128
  $schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
128
129
  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.",
@@ -146,7 +147,7 @@ async function main() {
146
147
  rcContent.projects = [...projects];
147
148
  const content = JSON.stringify(rcContent, null, 2);
148
149
  if (content !== existingSaltyrc) {
149
- compiler_index.logger.info("Edit file: " + saltyrcPath);
150
+ saltyReset.logger.info("Edit file: " + saltyrcPath);
150
151
  await promises.writeFile(saltyrcPath, content);
151
152
  await formatWithPrettier(saltyrcPath);
152
153
  }
@@ -157,7 +158,7 @@ async function main() {
157
158
  if (gitIgnoreContent !== void 0) {
158
159
  const alreadyIgnoresSaltygen = gitIgnoreContent.includes("saltygen");
159
160
  if (!alreadyIgnoresSaltygen) {
160
- compiler_index.logger.info("Edit file: " + gitIgnorePath);
161
+ saltyReset.logger.info("Edit file: " + gitIgnorePath);
161
162
  await promises.writeFile(gitIgnorePath, gitIgnoreContent + "\n\n# Salty-CSS\nsaltygen\n");
162
163
  }
163
164
  }
@@ -193,13 +194,13 @@ async function main() {
193
194
  const cssFileFolder = path.join(cssFilePath, "..");
194
195
  const relativePath = path.relative(cssFileFolder, path.join(projectDir, "saltygen/index.css"));
195
196
  const importStatement = `@import '${relativePath}';`;
196
- compiler_index.logger.info("Adding global import statement to CSS file: " + cssFilePath);
197
+ saltyReset.logger.info("Adding global import statement to CSS file: " + cssFilePath);
197
198
  await promises.writeFile(cssFilePath, importStatement + "\n" + cssFileContent);
198
199
  await formatWithPrettier(cssFilePath);
199
200
  }
200
201
  }
201
202
  } else {
202
- compiler_index.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
203
+ saltyReset.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
203
204
  }
204
205
  const eslintConfigs = {
205
206
  projectJs: path.join(projectDir, "eslint.config.js"),
@@ -213,10 +214,10 @@ async function main() {
213
214
  if (eslintConfigToUse) {
214
215
  if (!skipInstall) await npmInstall(packages.eslintConfigCore);
215
216
  const eslintConfigContent = await promises.readFile(eslintConfigToUse, "utf-8").catch(() => void 0);
216
- if (!eslintConfigContent) return compiler_index.logError("Could not read ESLint config file.");
217
+ if (!eslintConfigContent) return saltyReset.logError("Could not read ESLint config file.");
217
218
  const alreadyHasSaltyConfig = eslintConfigContent.includes("salty-css");
218
219
  if (!alreadyHasSaltyConfig) {
219
- compiler_index.logger.info("Edit file: " + eslintConfigToUse);
220
+ saltyReset.logger.info("Edit file: " + eslintConfigToUse);
220
221
  if (eslintConfigToUse.endsWith("js")) {
221
222
  const importStatement = 'import saltyCss from "@salty-css/eslint-config-core/flat";';
222
223
  let newContent = `${importStatement}
@@ -224,11 +225,11 @@ ${eslintConfigContent}`;
224
225
  const isTsEslint = eslintConfigContent.includes("typescript-eslint");
225
226
  if (isTsEslint) {
226
227
  if (newContent.includes(".config(")) newContent = newContent.replace(".config(", ".config(saltyCss,");
227
- else compiler_index.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
228
+ else saltyReset.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
228
229
  } else {
229
230
  if (newContent.includes("export default [")) newContent = newContent.replace("export default [", "export default [ saltyCss,");
230
231
  else if (newContent.includes("eslintConfig = [")) newContent = newContent.replace("eslintConfig = [", "eslintConfig = [ saltyCss,");
231
- else compiler_index.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
232
+ else saltyReset.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
232
233
  }
233
234
  await promises.writeFile(eslintConfigToUse, newContent);
234
235
  await formatWithPrettier(eslintConfigToUse);
@@ -247,13 +248,13 @@ ${eslintConfigContent}`;
247
248
  if (viteConfigContent !== void 0) {
248
249
  const alreadyHasPlugin = viteConfigContent.includes("saltyPlugin");
249
250
  if (!alreadyHasPlugin) {
250
- compiler_index.logger.info("Edit file: " + viteConfigPath);
251
+ saltyReset.logger.info("Edit file: " + viteConfigPath);
251
252
  const pluginImport = "import { saltyPlugin } from '@salty-css/vite';\n";
252
253
  const pluginConfig = "saltyPlugin(__dirname),";
253
254
  const newContent = viteConfigContent.replace(/(plugins: \[)/, `$1
254
255
  ${pluginConfig}`);
255
256
  if (!skipInstall) await npmInstall(`-D ${packages.vite}`);
256
- compiler_index.logger.info("Adding Salty-CSS plugin to Vite config...");
257
+ saltyReset.logger.info("Adding Salty-CSS plugin to Vite config...");
257
258
  await promises.writeFile(viteConfigPath, pluginImport + newContent);
258
259
  await formatWithPrettier(viteConfigPath);
259
260
  }
@@ -286,45 +287,45 @@ ${eslintConfigContent}`;
286
287
  });
287
288
  }
288
289
  if (!skipInstall) await npmInstall(`-D ${packages.next}`);
289
- compiler_index.logger.info("Adding Salty-CSS plugin to Next.js config...");
290
+ saltyReset.logger.info("Adding Salty-CSS plugin to Next.js config...");
290
291
  await promises.writeFile(nextConfigPath, pluginImport + nextConfigContent);
291
292
  await formatWithPrettier(nextConfigPath);
292
293
  }
293
294
  }
294
295
  }
295
- const packageJsonContent = await readPackageJson().catch(() => compiler_index.logError("Could not read package.json file.")).then((content) => {
296
+ const packageJsonContent = await readPackageJson().catch(() => saltyReset.logError("Could not read package.json file.")).then((content) => {
296
297
  if (!content.scripts) content.scripts = {};
297
298
  if (content.scripts.prepare) {
298
299
  const alreadyHasSaltyCss = content.scripts.prepare.includes("salty-css");
299
300
  if (!alreadyHasSaltyCss) {
300
- compiler_index.logger.info("Edit file: " + defaultPackageJsonPath);
301
+ saltyReset.logger.info("Edit file: " + defaultPackageJsonPath);
301
302
  content.scripts.prepare = content.scripts.prepare + " && npx salty-css build";
302
303
  }
303
304
  } else {
304
- compiler_index.logger.info("Edit file: " + defaultPackageJsonPath);
305
+ saltyReset.logger.info("Edit file: " + defaultPackageJsonPath);
305
306
  content.scripts.prepare = "npx salty-css build";
306
307
  }
307
308
  return content;
308
309
  });
309
310
  await updatePackageJson(packageJsonContent);
310
- compiler_index.logger.info("Running the build to generate initial CSS...");
311
+ saltyReset.logger.info("Running the build to generate initial CSS...");
311
312
  await compiler_index.generateCss(projectDir);
312
- compiler_index.logger.info("🎉 Salty CSS project initialized successfully!");
313
- compiler_index.logger.info("Next steps:");
314
- compiler_index.logger.info("1. Configure variables and templates in `salty.config.ts`");
315
- compiler_index.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
316
- compiler_index.logger.info("3. Run `npx salty-css build` to generate the CSS");
317
- compiler_index.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
318
- compiler_index.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
313
+ saltyReset.logger.info("🎉 Salty CSS project initialized successfully!");
314
+ saltyReset.logger.info("Next steps:");
315
+ saltyReset.logger.info("1. Configure variables and templates in `salty.config.ts`");
316
+ saltyReset.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
317
+ saltyReset.logger.info("3. Run `npx salty-css build` to generate the CSS");
318
+ saltyReset.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
319
+ saltyReset.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
319
320
  });
320
321
  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) {
321
- compiler_index.logger.info("Building the Salty-CSS project...");
322
+ saltyReset.logger.info("Building the Salty-CSS project...");
322
323
  const { dir = _dir, watch } = this.opts();
323
- if (!dir) return compiler_index.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
324
+ if (!dir) return saltyReset.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
324
325
  const projectDir = resolveProjectDir(dir);
325
326
  await compiler_index.generateCss(projectDir);
326
327
  if (watch) {
327
- compiler_index.logger.info("Watching for changes in the project directory...");
328
+ saltyReset.logger.info("Watching for changes in the project directory...");
328
329
  fs.watch(projectDir, { recursive: true }, async (event, filePath) => {
329
330
  const shouldRestart$1 = await shouldRestart.checkShouldRestart(filePath);
330
331
  if (shouldRestart$1) {
@@ -338,8 +339,8 @@ ${eslintConfigContent}`;
338
339
  });
339
340
  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 React component as well.").action(async function(_file, _dir = defaultProject) {
340
341
  const { file = _file, dir = _dir, tag, name, className, reactComponent = false } = this.opts();
341
- if (!file) return compiler_index.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
342
- if (!dir) return compiler_index.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
342
+ if (!file) return saltyReset.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
343
+ if (!dir) return saltyReset.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
343
344
  const projectDir = resolveProjectDir(dir);
344
345
  const additionalFolders = file.split("/").slice(0, -1).join("/");
345
346
  if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
@@ -355,7 +356,7 @@ ${eslintConfigContent}`;
355
356
  const formattedStyledFilePath = path.format(parsedFilePath);
356
357
  const alreadyExists = await promises.readFile(formattedStyledFilePath, "utf-8").catch(() => void 0);
357
358
  if (alreadyExists !== void 0) {
358
- compiler_index.logger.error("File already exists:", formattedStyledFilePath);
359
+ saltyReset.logger.error("File already exists:", formattedStyledFilePath);
359
360
  return;
360
361
  }
361
362
  let styledComponentName = pascalCase.pascalCase(name || parsedFilePath.base.replace(/\.css\.\w+$/, ""));
@@ -368,23 +369,23 @@ ${eslintConfigContent}`;
368
369
  parsedFilePath.ext = ".tsx";
369
370
  parsedFilePath.base = parsedFilePath.name + parsedFilePath.ext;
370
371
  const formattedReactFilePath = path.format(parsedFilePath);
371
- compiler_index.logger.info("Generating a new file: " + formattedReactFilePath);
372
+ saltyReset.logger.info("Generating a new file: " + formattedReactFilePath);
372
373
  await promises.writeFile(formattedReactFilePath, reactContent);
373
374
  await formatWithPrettier(formattedReactFilePath);
374
375
  }
375
376
  const { content } = await readTemplate("react/react-styled-file.ts", { tag, name: styledComponentName, className });
376
- compiler_index.logger.info("Generating a new file: " + formattedStyledFilePath);
377
+ saltyReset.logger.info("Generating a new file: " + formattedStyledFilePath);
377
378
  await promises.writeFile(formattedStyledFilePath, content);
378
379
  await formatWithPrettier(formattedStyledFilePath);
379
380
  });
380
381
  const getSaltyCssPackages = async () => {
381
382
  const packageJSONPath = path.join(process.cwd(), "package.json");
382
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_index.logError(err));
383
- if (!packageJson) return compiler_index.logError("Could not read package.json file.");
383
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => saltyReset.logError(err));
384
+ if (!packageJson) return saltyReset.logError("Could not read package.json file.");
384
385
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
385
386
  const saltyCssPackages = Object.entries(allDependencies).filter(([name]) => name === "salty-css" || name.startsWith("@salty-css/"));
386
387
  if (!saltyCssPackages.length) {
387
- return compiler_index.logError(
388
+ return saltyReset.logError(
388
389
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
389
390
  );
390
391
  }
@@ -393,19 +394,19 @@ ${eslintConfigContent}`;
393
394
  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).action(async function(_version = "latest") {
394
395
  const { legacyPeerDeps, version = _version } = this.opts();
395
396
  const saltyCssPackages = await getSaltyCssPackages();
396
- if (!saltyCssPackages) return compiler_index.logError("Could not update Salty-CSS packages as any were found in package.json.");
397
+ if (!saltyCssPackages) return saltyReset.logError("Could not update Salty-CSS packages as any were found in package.json.");
397
398
  const packagesToUpdate = saltyCssPackages.map(([name]) => {
398
399
  if (version === "@") return `${name}@${currentPackageJson.version}`;
399
400
  return `${name}@${version.replace(/^@/, "")}`;
400
401
  });
401
402
  if (legacyPeerDeps) {
402
- compiler_index.logger.warn("Using legacy peer dependencies to update packages.");
403
+ saltyReset.logger.warn("Using legacy peer dependencies to update packages.");
403
404
  await npmInstall(...packagesToUpdate, "--legacy-peer-deps");
404
405
  } else {
405
406
  await npmInstall(...packagesToUpdate);
406
407
  }
407
408
  const updatedPackages = await getSaltyCssPackages();
408
- if (!updatedPackages) return compiler_index.logError("Something went wrong while reading the updated packages.");
409
+ if (!updatedPackages) return saltyReset.logError("Something went wrong while reading the updated packages.");
409
410
  const mappedByVersions = updatedPackages.reduce((acc, [name, version2]) => {
410
411
  if (!acc[version2]) acc[version2] = [];
411
412
  acc[version2].push(name);
@@ -415,29 +416,29 @@ ${eslintConfigContent}`;
415
416
  if (versionsCount === 1) {
416
417
  const version2 = Object.keys(mappedByVersions)[0];
417
418
  const versionString = version2.replace(/^\^/, "");
418
- compiler_index.logger.info(`Updated to all Salty CSS packages successfully to ${versionString}`);
419
+ saltyReset.logger.info(`Updated to all Salty CSS packages successfully to ${versionString}`);
419
420
  } else {
420
421
  for (const [version2, names] of Object.entries(mappedByVersions)) {
421
422
  const versionString = version2.replace(/^\^/, "");
422
- compiler_index.logger.info(`Updated to ${versionString}: ${names.join(", ")}`);
423
+ saltyReset.logger.info(`Updated to ${versionString}: ${names.join(", ")}`);
423
424
  }
424
425
  }
425
426
  });
426
427
  program.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
427
428
  const currentPackageJson2 = await readThisPackageJson();
428
- compiler_index.logger.info("CLI is running: " + currentPackageJson2.version);
429
+ saltyReset.logger.info("CLI is running: " + currentPackageJson2.version);
429
430
  const packageJSONPath = path.join(process.cwd(), "package.json");
430
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_index.logError(err));
431
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => saltyReset.logError(err));
431
432
  if (!packageJson) return;
432
433
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
433
434
  const saltyCssPackages = Object.keys(allDependencies).filter((dep) => dep === "salty-css" || dep.startsWith("@salty-css/"));
434
435
  if (!saltyCssPackages.length) {
435
- return compiler_index.logError(
436
+ return saltyReset.logError(
436
437
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
437
438
  );
438
439
  }
439
440
  for (const dep of saltyCssPackages) {
440
- compiler_index.logger.info(`${dep}: ${allDependencies[dep]}`);
441
+ saltyReset.logger.info(`${dep}: ${allDependencies[dep]}`);
441
442
  }
442
443
  });
443
444
  program.parseAsync(process.argv);
package/bin/main.js CHANGED
@@ -3,8 +3,9 @@ import { existsSync, watch } from "fs";
3
3
  import { mkdir, readFile, writeFile } from "fs/promises";
4
4
  import { join, relative, parse, format } from "path";
5
5
  import { render } from "ejs";
6
- import { l as logger, a as logError, generateCss, isSaltyFile, generateFile } from "../compiler/index.js";
6
+ import { generateCss, isSaltyFile, generateFile } from "../compiler/index.js";
7
7
  import { p as pascalCase } from "../pascal-case-F3Usi5Wf.js";
8
+ import { l as logger, b as logError } from "../salty-reset-StBt2yzJ.js";
8
9
  import { exec } from "child_process";
9
10
  import ora from "ora";
10
11
  import { c as checkShouldRestart } from "../should-restart-5jI-bzz0.js";