@salty-css/core 0.0.1-alpha.310 → 0.0.1-alpha.311

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
@@ -6,11 +6,10 @@ const promises = require("fs/promises");
6
6
  const path = require("path");
7
7
  const ejs = require("ejs");
8
8
  const pascalCase = require("../pascal-case-By_l58S-.cjs");
9
- const saltyReset = require("../salty-reset-zWMaTt2Q.cjs");
9
+ const compiler_asClass = require("../compiler/as-class.cjs");
10
10
  const child_process = require("child_process");
11
11
  const ora = require("ora");
12
- const shouldRestart = require("../should-restart-DoaGoD5T.cjs");
13
- const compiler_asClass = require("../compiler/as-class.cjs");
12
+ const shouldRestart = require("../should-restart-CQsyHls3.cjs");
14
13
  const compiler_helpers = require("../compiler/helpers.cjs");
15
14
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
16
15
  const execAsync = (command) => {
@@ -36,9 +35,9 @@ async function formatWithPrettier(filePath) {
36
35
  const hasPrettier = hasPrettierInstalled();
37
36
  if (!hasPrettier) return;
38
37
  await execAsync(`./node_modules/.bin/prettier --write "${filePath}"`);
39
- saltyReset.logger.info(`Formatted ${filePath} with Prettier`);
38
+ compiler_asClass.logger.info(`Formatted ${filePath} with Prettier`);
40
39
  } catch (error) {
41
- saltyReset.logger.error(`Error formatting ${filePath} with Prettier:`, error);
40
+ compiler_asClass.logger.error(`Error formatting ${filePath} with Prettier:`, error);
42
41
  }
43
42
  }
44
43
  async function main() {
@@ -97,10 +96,10 @@ async function main() {
97
96
  };
98
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 = ".") {
99
98
  const packageJson = await readPackageJson().catch(() => void 0);
100
- if (!packageJson) return saltyReset.logError("Salty CSS project must be initialized in a directory with a package.json file.");
101
- saltyReset.logger.info("Initializing a new Salty-CSS project!");
99
+ if (!packageJson) return compiler_asClass.logError("Salty CSS project must be initialized in a directory with a package.json file.");
100
+ compiler_asClass.logger.info("Initializing a new Salty-CSS project!");
102
101
  const { dir = _dir, cssFile, skipInstall } = this.opts();
103
- 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
+ if (!dir) return compiler_asClass.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
104
103
  if (!skipInstall) await npmInstall(packages.core, packages.react);
105
104
  const rootDir = process.cwd();
106
105
  const projectDir = resolveProjectDir(dir);
@@ -111,12 +110,12 @@ async function main() {
111
110
  const filePath = path.join(projectDir, fileName);
112
111
  const existingContent = await promises.readFile(filePath, "utf-8").catch(() => void 0);
113
112
  if (existingContent !== void 0) {
114
- saltyReset.logger.debug("File already exists: " + filePath);
113
+ compiler_asClass.logger.debug("File already exists: " + filePath);
115
114
  return;
116
115
  }
117
116
  const additionalFolders = fileName.split("/").slice(0, -1).join("/");
118
117
  if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
119
- saltyReset.logger.info("Creating file: " + filePath);
118
+ compiler_asClass.logger.info("Creating file: " + filePath);
120
119
  await promises.writeFile(filePath, content);
121
120
  await formatWithPrettier(filePath);
122
121
  });
@@ -125,7 +124,7 @@ async function main() {
125
124
  const saltyrcPath = path.join(rootDir, ".saltyrc.json");
126
125
  const existingSaltyrc = await promises.readFile(saltyrcPath, "utf-8").catch(() => void 0);
127
126
  if (existingSaltyrc === void 0) {
128
- saltyReset.logger.info("Creating file: " + saltyrcPath);
127
+ compiler_asClass.logger.info("Creating file: " + saltyrcPath);
129
128
  const rcContent = {
130
129
  $schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
131
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.",
@@ -149,7 +148,7 @@ async function main() {
149
148
  rcContent.projects = [...projects];
150
149
  const content = JSON.stringify(rcContent, null, 2);
151
150
  if (content !== existingSaltyrc) {
152
- saltyReset.logger.info("Edit file: " + saltyrcPath);
151
+ compiler_asClass.logger.info("Edit file: " + saltyrcPath);
153
152
  await promises.writeFile(saltyrcPath, content);
154
153
  await formatWithPrettier(saltyrcPath);
155
154
  }
@@ -160,7 +159,7 @@ async function main() {
160
159
  if (gitIgnoreContent !== void 0) {
161
160
  const alreadyIgnoresSaltygen = gitIgnoreContent.includes("saltygen");
162
161
  if (!alreadyIgnoresSaltygen) {
163
- saltyReset.logger.info("Edit file: " + gitIgnorePath);
162
+ compiler_asClass.logger.info("Edit file: " + gitIgnorePath);
164
163
  await promises.writeFile(gitIgnorePath, gitIgnoreContent + "\n\n# Salty-CSS\nsaltygen\n");
165
164
  }
166
165
  }
@@ -196,13 +195,13 @@ async function main() {
196
195
  const cssFileFolder = path.join(cssFilePath, "..");
197
196
  const relativePath = path.relative(cssFileFolder, path.join(projectDir, "saltygen/index.css"));
198
197
  const importStatement = `@import '${relativePath}';`;
199
- saltyReset.logger.info("Adding global import statement to CSS file: " + cssFilePath);
198
+ compiler_asClass.logger.info("Adding global import statement to CSS file: " + cssFilePath);
200
199
  await promises.writeFile(cssFilePath, importStatement + "\n" + cssFileContent);
201
200
  await formatWithPrettier(cssFilePath);
202
201
  }
203
202
  }
204
203
  } else {
205
- saltyReset.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
204
+ compiler_asClass.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
206
205
  }
207
206
  const eslintConfigs = {
208
207
  projectJs: path.join(projectDir, "eslint.config.js"),
@@ -216,10 +215,10 @@ async function main() {
216
215
  if (eslintConfigToUse) {
217
216
  if (!skipInstall) await npmInstall(packages.eslintConfigCore);
218
217
  const eslintConfigContent = await promises.readFile(eslintConfigToUse, "utf-8").catch(() => void 0);
219
- if (!eslintConfigContent) return saltyReset.logError("Could not read ESLint config file.");
218
+ if (!eslintConfigContent) return compiler_asClass.logError("Could not read ESLint config file.");
220
219
  const alreadyHasSaltyConfig = eslintConfigContent.includes("salty-css");
221
220
  if (!alreadyHasSaltyConfig) {
222
- saltyReset.logger.info("Edit file: " + eslintConfigToUse);
221
+ compiler_asClass.logger.info("Edit file: " + eslintConfigToUse);
223
222
  if (eslintConfigToUse.endsWith("js")) {
224
223
  const importStatement = 'import saltyCss from "@salty-css/eslint-config-core/flat";';
225
224
  let newContent = `${importStatement}
@@ -227,11 +226,11 @@ ${eslintConfigContent}`;
227
226
  const isTsEslint = eslintConfigContent.includes("typescript-eslint");
228
227
  if (isTsEslint) {
229
228
  if (newContent.includes(".config(")) newContent = newContent.replace(".config(", ".config(saltyCss,");
230
- else saltyReset.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
229
+ else compiler_asClass.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
231
230
  } else {
232
231
  if (newContent.includes("export default [")) newContent = newContent.replace("export default [", "export default [ saltyCss,");
233
232
  else if (newContent.includes("eslintConfig = [")) newContent = newContent.replace("eslintConfig = [", "eslintConfig = [ saltyCss,");
234
- else saltyReset.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
233
+ else compiler_asClass.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.");
235
234
  }
236
235
  await promises.writeFile(eslintConfigToUse, newContent);
237
236
  await formatWithPrettier(eslintConfigToUse);
@@ -250,13 +249,13 @@ ${eslintConfigContent}`;
250
249
  if (viteConfigContent !== void 0) {
251
250
  const alreadyHasPlugin = viteConfigContent.includes("saltyPlugin");
252
251
  if (!alreadyHasPlugin) {
253
- saltyReset.logger.info("Edit file: " + viteConfigPath);
252
+ compiler_asClass.logger.info("Edit file: " + viteConfigPath);
254
253
  const pluginImport = "import { saltyPlugin } from '@salty-css/vite';\n";
255
254
  const pluginConfig = "saltyPlugin(__dirname),";
256
255
  const newContent = viteConfigContent.replace(/(plugins: \[)/, `$1
257
256
  ${pluginConfig}`);
258
257
  if (!skipInstall) await npmInstall(`-D ${packages.vite}`);
259
- saltyReset.logger.info("Adding Salty-CSS plugin to Vite config...");
258
+ compiler_asClass.logger.info("Adding Salty-CSS plugin to Vite config...");
260
259
  await promises.writeFile(viteConfigPath, pluginImport + newContent);
261
260
  await formatWithPrettier(viteConfigPath);
262
261
  }
@@ -289,46 +288,46 @@ ${eslintConfigContent}`;
289
288
  });
290
289
  }
291
290
  if (!skipInstall) await npmInstall(`-D ${packages.next}`);
292
- saltyReset.logger.info("Adding Salty-CSS plugin to Next.js config...");
291
+ compiler_asClass.logger.info("Adding Salty-CSS plugin to Next.js config...");
293
292
  await promises.writeFile(nextConfigPath, pluginImport + nextConfigContent);
294
293
  await formatWithPrettier(nextConfigPath);
295
294
  }
296
295
  }
297
296
  }
298
- const packageJsonContent = await readPackageJson().catch(() => saltyReset.logError("Could not read package.json file.")).then((content) => {
297
+ const packageJsonContent = await readPackageJson().catch(() => compiler_asClass.logError("Could not read package.json file.")).then((content) => {
299
298
  if (!content.scripts) content.scripts = {};
300
299
  if (content.scripts.prepare) {
301
300
  const alreadyHasSaltyCss = content.scripts.prepare.includes("salty-css");
302
301
  if (!alreadyHasSaltyCss) {
303
- saltyReset.logger.info("Edit file: " + defaultPackageJsonPath);
302
+ compiler_asClass.logger.info("Edit file: " + defaultPackageJsonPath);
304
303
  content.scripts.prepare = content.scripts.prepare + " && npx salty-css build";
305
304
  }
306
305
  } else {
307
- saltyReset.logger.info("Edit file: " + defaultPackageJsonPath);
306
+ compiler_asClass.logger.info("Edit file: " + defaultPackageJsonPath);
308
307
  content.scripts.prepare = "npx salty-css build";
309
308
  }
310
309
  return content;
311
310
  });
312
311
  await updatePackageJson(packageJsonContent);
313
- saltyReset.logger.info("Running the build to generate initial CSS...");
312
+ compiler_asClass.logger.info("Running the build to generate initial CSS...");
314
313
  await saltyCompiler.generateCss();
315
- saltyReset.logger.info("🎉 Salty CSS project initialized successfully!");
316
- saltyReset.logger.info("Next steps:");
317
- saltyReset.logger.info("1. Configure variables and templates in `salty.config.ts`");
318
- saltyReset.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
319
- saltyReset.logger.info("3. Run `npx salty-css build` to generate the CSS");
320
- saltyReset.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
321
- saltyReset.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
314
+ compiler_asClass.logger.info("🎉 Salty CSS project initialized successfully!");
315
+ compiler_asClass.logger.info("Next steps:");
316
+ compiler_asClass.logger.info("1. Configure variables and templates in `salty.config.ts`");
317
+ compiler_asClass.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
318
+ compiler_asClass.logger.info("3. Run `npx salty-css build` to generate the CSS");
319
+ compiler_asClass.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
320
+ compiler_asClass.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
322
321
  });
323
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) {
324
- saltyReset.logger.info("Building the Salty-CSS project...");
323
+ compiler_asClass.logger.info("Building the Salty-CSS project...");
325
324
  const { dir = _dir, watch } = this.opts();
326
- if (!dir) return saltyReset.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
325
+ if (!dir) return compiler_asClass.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
327
326
  const projectDir = resolveProjectDir(dir);
328
327
  const saltyCompiler = new compiler_asClass.SaltyCompiler(projectDir);
329
328
  await saltyCompiler.generateCss();
330
329
  if (watch) {
331
- saltyReset.logger.info("Watching for changes in the project directory...");
330
+ compiler_asClass.logger.info("Watching for changes in the project directory...");
332
331
  fs.watch(projectDir, { recursive: true }, async (event, filePath) => {
333
332
  const shouldRestart$1 = await shouldRestart.checkShouldRestart(filePath);
334
333
  if (shouldRestart$1) {
@@ -342,8 +341,8 @@ ${eslintConfigContent}`;
342
341
  });
343
342
  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) {
344
343
  const { file = _file, dir = _dir, tag, name, className, reactComponent = false } = this.opts();
345
- 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.");
346
- if (!dir) return saltyReset.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
344
+ if (!file) return compiler_asClass.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
345
+ if (!dir) return compiler_asClass.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
347
346
  const projectDir = resolveProjectDir(dir);
348
347
  const additionalFolders = file.split("/").slice(0, -1).join("/");
349
348
  if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
@@ -359,7 +358,7 @@ ${eslintConfigContent}`;
359
358
  const formattedStyledFilePath = path.format(parsedFilePath);
360
359
  const alreadyExists = await promises.readFile(formattedStyledFilePath, "utf-8").catch(() => void 0);
361
360
  if (alreadyExists !== void 0) {
362
- saltyReset.logger.error("File already exists:", formattedStyledFilePath);
361
+ compiler_asClass.logger.error("File already exists:", formattedStyledFilePath);
363
362
  return;
364
363
  }
365
364
  let styledComponentName = pascalCase.pascalCase(name || parsedFilePath.base.replace(/\.css\.\w+$/, ""));
@@ -372,23 +371,23 @@ ${eslintConfigContent}`;
372
371
  parsedFilePath.ext = ".tsx";
373
372
  parsedFilePath.base = parsedFilePath.name + parsedFilePath.ext;
374
373
  const formattedReactFilePath = path.format(parsedFilePath);
375
- saltyReset.logger.info("Generating a new file: " + formattedReactFilePath);
374
+ compiler_asClass.logger.info("Generating a new file: " + formattedReactFilePath);
376
375
  await promises.writeFile(formattedReactFilePath, reactContent);
377
376
  await formatWithPrettier(formattedReactFilePath);
378
377
  }
379
378
  const { content } = await readTemplate("react/react-styled-file.ts", { tag, name: styledComponentName, className });
380
- saltyReset.logger.info("Generating a new file: " + formattedStyledFilePath);
379
+ compiler_asClass.logger.info("Generating a new file: " + formattedStyledFilePath);
381
380
  await promises.writeFile(formattedStyledFilePath, content);
382
381
  await formatWithPrettier(formattedStyledFilePath);
383
382
  });
384
383
  const getSaltyCssPackages = async () => {
385
384
  const packageJSONPath = path.join(process.cwd(), "package.json");
386
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => saltyReset.logError(err));
387
- if (!packageJson) return saltyReset.logError("Could not read package.json file.");
385
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_asClass.logError(err));
386
+ if (!packageJson) return compiler_asClass.logError("Could not read package.json file.");
388
387
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
389
388
  const saltyCssPackages = Object.entries(allDependencies).filter(([name]) => name === "salty-css" || name.startsWith("@salty-css/"));
390
389
  if (!saltyCssPackages.length) {
391
- return saltyReset.logError(
390
+ return compiler_asClass.logError(
392
391
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
393
392
  );
394
393
  }
@@ -397,19 +396,19 @@ ${eslintConfigContent}`;
397
396
  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") {
398
397
  const { legacyPeerDeps, version = _version } = this.opts();
399
398
  const saltyCssPackages = await getSaltyCssPackages();
400
- if (!saltyCssPackages) return saltyReset.logError("Could not update Salty-CSS packages as any were found in package.json.");
399
+ if (!saltyCssPackages) return compiler_asClass.logError("Could not update Salty-CSS packages as any were found in package.json.");
401
400
  const packagesToUpdate = saltyCssPackages.map(([name]) => {
402
401
  if (version === "@") return `${name}@${currentPackageJson.version}`;
403
402
  return `${name}@${version.replace(/^@/, "")}`;
404
403
  });
405
404
  if (legacyPeerDeps) {
406
- saltyReset.logger.warn("Using legacy peer dependencies to update packages.");
405
+ compiler_asClass.logger.warn("Using legacy peer dependencies to update packages.");
407
406
  await npmInstall(...packagesToUpdate, "--legacy-peer-deps");
408
407
  } else {
409
408
  await npmInstall(...packagesToUpdate);
410
409
  }
411
410
  const updatedPackages = await getSaltyCssPackages();
412
- if (!updatedPackages) return saltyReset.logError("Something went wrong while reading the updated packages.");
411
+ if (!updatedPackages) return compiler_asClass.logError("Something went wrong while reading the updated packages.");
413
412
  const mappedByVersions = updatedPackages.reduce((acc, [name, version2]) => {
414
413
  if (!acc[version2]) acc[version2] = [];
415
414
  acc[version2].push(name);
@@ -419,29 +418,29 @@ ${eslintConfigContent}`;
419
418
  if (versionsCount === 1) {
420
419
  const version2 = Object.keys(mappedByVersions)[0];
421
420
  const versionString = version2.replace(/^\^/, "");
422
- saltyReset.logger.info(`Updated to all Salty CSS packages successfully to ${versionString}`);
421
+ compiler_asClass.logger.info(`Updated to all Salty CSS packages successfully to ${versionString}`);
423
422
  } else {
424
423
  for (const [version2, names] of Object.entries(mappedByVersions)) {
425
424
  const versionString = version2.replace(/^\^/, "");
426
- saltyReset.logger.info(`Updated to ${versionString}: ${names.join(", ")}`);
425
+ compiler_asClass.logger.info(`Updated to ${versionString}: ${names.join(", ")}`);
427
426
  }
428
427
  }
429
428
  });
430
429
  program.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
431
430
  const currentPackageJson2 = await readThisPackageJson();
432
- saltyReset.logger.info("CLI is running: " + currentPackageJson2.version);
431
+ compiler_asClass.logger.info("CLI is running: " + currentPackageJson2.version);
433
432
  const packageJSONPath = path.join(process.cwd(), "package.json");
434
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => saltyReset.logError(err));
433
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_asClass.logError(err));
435
434
  if (!packageJson) return;
436
435
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
437
436
  const saltyCssPackages = Object.keys(allDependencies).filter((dep) => dep === "salty-css" || dep.startsWith("@salty-css/"));
438
437
  if (!saltyCssPackages.length) {
439
- return saltyReset.logError(
438
+ return compiler_asClass.logError(
440
439
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
441
440
  );
442
441
  }
443
442
  for (const dep of saltyCssPackages) {
444
- saltyReset.logger.info(`${dep}: ${allDependencies[dep]}`);
443
+ compiler_asClass.logger.info(`${dep}: ${allDependencies[dep]}`);
445
444
  }
446
445
  });
447
446
  program.parseAsync(process.argv);
package/bin/main.js CHANGED
@@ -4,11 +4,10 @@ import { mkdir, readFile, writeFile } from "fs/promises";
4
4
  import { join, relative, parse, format } from "path";
5
5
  import { render } from "ejs";
6
6
  import { p as pascalCase } from "../pascal-case-F3Usi5Wf.js";
7
- import { l as logger, b as logError } from "../salty-reset-D1VR51zL.js";
7
+ import { l as logger, a as logError, SaltyCompiler } from "../compiler/as-class.js";
8
8
  import { exec } from "child_process";
9
9
  import ora from "ora";
10
- import { c as checkShouldRestart } from "../should-restart-5jI-bzz0.js";
11
- import { SaltyCompiler } from "../compiler/as-class.js";
10
+ import { c as checkShouldRestart } from "../should-restart-CXIO0jxY.js";
12
11
  import { isSaltyFile } from "../compiler/helpers.js";
13
12
  const execAsync = (command) => {
14
13
  return new Promise((resolve, reject) => {
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5
5
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
6
  const esbuild = require("esbuild");
7
7
  const path = require("path");
8
- const saltyReset = require("../salty-reset-zWMaTt2Q.cjs");
8
+ const winston = require("winston");
9
9
  const promises = require("fs/promises");
10
10
  const fs = require("fs");
11
11
  const child_process = require("child_process");
@@ -14,9 +14,11 @@ const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
14
14
  const toHash = require("../to-hash-DT2ImSPA.cjs");
15
15
  const parseStyles = require("../parse-styles-gRr_iCy7.cjs");
16
16
  const css_merge = require("../css/merge.cjs");
17
+ const compiler_getFiles = require("./get-files.cjs");
17
18
  const parsers_index = require("../parsers/index.cjs");
18
19
  const console = require("console");
19
20
  const compiler_getFunctionRange = require("./get-function-range.cjs");
21
+ var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
20
22
  function _interopNamespaceDefault(e) {
21
23
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
22
24
  if (e) {
@@ -34,6 +36,80 @@ function _interopNamespaceDefault(e) {
34
36
  return Object.freeze(n);
35
37
  }
36
38
  const esbuild__namespace = /* @__PURE__ */ _interopNamespaceDefault(esbuild);
39
+ const logger = winston.createLogger({
40
+ level: "debug",
41
+ format: winston.format.combine(winston.format.colorize(), winston.format.cli()),
42
+ transports: [new winston.transports.Console({})]
43
+ });
44
+ const logError = (message) => {
45
+ logger.error(message);
46
+ };
47
+ const readPackageJsonModule = async (dirname) => {
48
+ const packageJsonContent = await compiler_getFiles.getPackageJson(dirname);
49
+ if (!packageJsonContent) return void 0;
50
+ return packageJsonContent.type;
51
+ };
52
+ let cachedModuleType;
53
+ const detectCurrentModuleType = async (dirname) => {
54
+ if (cachedModuleType) return cachedModuleType;
55
+ const packageJsonModule = await readPackageJsonModule(dirname);
56
+ if (packageJsonModule === "module") cachedModuleType = "esm";
57
+ else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
58
+ else if ((typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/as-class.cjs", document.baseURI).href).endsWith(".cjs")) cachedModuleType = "cjs";
59
+ return cachedModuleType || "esm";
60
+ };
61
+ function dotCase(str) {
62
+ if (!str) return "";
63
+ if (typeof str !== "string") return dotCase(String(str));
64
+ return str.replace(/[^\d\w]/g, ".");
65
+ }
66
+ const saltyReset = {
67
+ /** Set box model to border-box */
68
+ "*, *::before, *::after": {
69
+ boxSizing: "border-box"
70
+ },
71
+ /** Remove default margin and padding */
72
+ "*": {
73
+ margin: 0
74
+ },
75
+ /** Remove adjust font properties */
76
+ html: {
77
+ lineHeight: 1.15,
78
+ textSizeAdjust: "100%",
79
+ WebkitFontSmoothing: "antialiased"
80
+ },
81
+ /** Make media elements responsive */
82
+ "img, picture, video, canvas, svg": {
83
+ display: "block",
84
+ maxWidth: "100%"
85
+ },
86
+ /** Avoid overflow of text */
87
+ "p, h1, h2, h3, h4, h5, h6": {
88
+ overflowWrap: "break-word"
89
+ },
90
+ /** Improve text wrapping */
91
+ p: {
92
+ textWrap: "pretty"
93
+ },
94
+ "h1, h2, h3, h4, h5, h6": {
95
+ textWrap: "balance"
96
+ },
97
+ /** Improve link color */
98
+ a: {
99
+ color: "currentColor"
100
+ },
101
+ /** Improve button line height */
102
+ button: {
103
+ lineHeight: "1em",
104
+ color: "currentColor"
105
+ },
106
+ /** Improve form elements */
107
+ "input, optgroup, select, textarea": {
108
+ fontFamily: "inherit",
109
+ fontSize: "100%",
110
+ lineHeight: "1.15em"
111
+ }
112
+ };
37
113
  class SaltyCompiler {
38
114
  constructor(projectRootDir) {
39
115
  __publicField(this, "importFile", (path2) => {
@@ -97,7 +173,7 @@ class SaltyCompiler {
97
173
  const destDir = await this.getDestDir();
98
174
  const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
99
175
  const coreConfigDest = path.join(destDir, "salty.config.js");
100
- const moduleType = await saltyReset.detectCurrentModuleType(this.projectRootDir);
176
+ const moduleType = await detectCurrentModuleType(this.projectRootDir);
101
177
  const externalModules = this.getExternalModules(coreConfigPath);
102
178
  await esbuild__namespace.build({
103
179
  entryPoints: [coreConfigPath],
@@ -144,8 +220,8 @@ ${currentFile}`;
144
220
  __publicField(this, "generateCss", async (clean = true) => {
145
221
  try {
146
222
  const start = Date.now();
147
- if (this.isProduction) saltyReset.logger.info("Generating CSS in production mode! 🔥");
148
- else saltyReset.logger.info("Generating CSS in development mode! 🚀");
223
+ if (this.isProduction) logger.info("Generating CSS in production mode! 🔥");
224
+ else logger.info("Generating CSS in development mode! 🚀");
149
225
  const globalCssFiles = [];
150
226
  const cssFiles = [];
151
227
  const destDir = await this.getDestDir();
@@ -317,7 +393,7 @@ ${css}
317
393
  const end = Date.now();
318
394
  const time = end - start;
319
395
  const emoji = time < 200 ? "🔥" : time < 500 ? "🚀" : time < 1e3 ? "🎉" : time < 2e3 ? "🚗" : time < 5e3 ? "🤔" : "🥴";
320
- saltyReset.logger.info(`Generated CSS in ${time}ms! ${emoji}`);
396
+ logger.info(`Generated CSS in ${time}ms! ${emoji}`);
321
397
  } catch (e) {
322
398
  console.error(e);
323
399
  }
@@ -356,7 +432,7 @@ ${css}
356
432
  if (value2 instanceof Promise) return await parseVariable(await value2);
357
433
  if (typeof value2 === "function") return await parseVariable(await value2());
358
434
  if (typeof value2 === "object") return await parseVariables(value2, [...path2, key]);
359
- const dottedKey = saltyReset.dotCase(key);
435
+ const dottedKey = dotCase(key);
360
436
  const dashedKey = toHash.dashCase(key);
361
437
  const tsName = [...path2, dottedKey].join(".");
362
438
  variableTokens.add(`"${tsName}"`);
@@ -426,7 +502,7 @@ ${css}
426
502
  const getResetStyles = () => {
427
503
  if (config.reset === "none") return {};
428
504
  if (typeof config.reset === "object") return config.reset;
429
- return saltyReset.saltyReset;
505
+ return saltyReset;
430
506
  };
431
507
  const resetStyles = getResetStyles();
432
508
  const resetStylesString = await parseStyles.parseAndJoinStyles(resetStyles, "");
@@ -474,7 +550,7 @@ ${css}
474
550
  const rcProject = await this.getRCProjectConfig(this.projectRootDir);
475
551
  const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
476
552
  const externalModules = this.getExternalModules(coreConfigPath);
477
- const moduleType = await saltyReset.detectCurrentModuleType(this.projectRootDir);
553
+ const moduleType = await detectCurrentModuleType(this.projectRootDir);
478
554
  await esbuild__namespace.build({
479
555
  stdin: {
480
556
  contents: currentFile,
@@ -672,3 +748,5 @@ ${newContent}
672
748
  }
673
749
  }
674
750
  exports.SaltyCompiler = SaltyCompiler;
751
+ exports.logError = logError;
752
+ exports.logger = logger;
@@ -19,7 +19,7 @@ export declare class SaltyCompiler {
19
19
  * Get the destination directory for generated files based on the project configuration.
20
20
  * Caches the result to avoid redundant computations.
21
21
  */
22
- private getDestDir;
22
+ getDestDir: () => Promise<string>;
23
23
  private generateConfig;
24
24
  private addConfigCache;
25
25
  private getConfigCache;
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import * as esbuild from "esbuild";
5
5
  import { join, parse } from "path";
6
- import { d as detectCurrentModuleType, l as logger, s as saltyReset, a as dotCase } from "../salty-reset-D1VR51zL.js";
6
+ import { createLogger, transports, format } from "winston";
7
7
  import { readFile } from "fs/promises";
8
8
  import { readFileSync, existsSync, mkdirSync, statSync, readdirSync, writeFileSync } from "fs";
9
9
  import { execSync } from "child_process";
@@ -12,9 +12,84 @@ import { d as defineTemplates } from "../define-templates-CVhhgPnd.js";
12
12
  import { t as toHash, d as dashCase } from "../to-hash-DSoCPs8D.js";
13
13
  import { p as parseAndJoinStyles, a as parseVariableTokens } from "../parse-styles-CS97_e4S.js";
14
14
  import { mergeObjects, mergeFactories } from "../css/merge.js";
15
+ import { getPackageJson } from "./get-files.js";
15
16
  import { parseTemplates, getTemplateTypes } from "../parsers/index.js";
16
17
  import console from "console";
17
18
  import { getFunctionRange } from "./get-function-range.js";
19
+ const logger = createLogger({
20
+ level: "debug",
21
+ format: format.combine(format.colorize(), format.cli()),
22
+ transports: [new transports.Console({})]
23
+ });
24
+ const logError = (message) => {
25
+ logger.error(message);
26
+ };
27
+ const readPackageJsonModule = async (dirname) => {
28
+ const packageJsonContent = await getPackageJson(dirname);
29
+ if (!packageJsonContent) return void 0;
30
+ return packageJsonContent.type;
31
+ };
32
+ let cachedModuleType;
33
+ const detectCurrentModuleType = async (dirname) => {
34
+ if (cachedModuleType) return cachedModuleType;
35
+ const packageJsonModule = await readPackageJsonModule(dirname);
36
+ if (packageJsonModule === "module") cachedModuleType = "esm";
37
+ else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
38
+ else if (import.meta.url.endsWith(".cjs")) cachedModuleType = "cjs";
39
+ return cachedModuleType || "esm";
40
+ };
41
+ function dotCase(str) {
42
+ if (!str) return "";
43
+ if (typeof str !== "string") return dotCase(String(str));
44
+ return str.replace(/[^\d\w]/g, ".");
45
+ }
46
+ const saltyReset = {
47
+ /** Set box model to border-box */
48
+ "*, *::before, *::after": {
49
+ boxSizing: "border-box"
50
+ },
51
+ /** Remove default margin and padding */
52
+ "*": {
53
+ margin: 0
54
+ },
55
+ /** Remove adjust font properties */
56
+ html: {
57
+ lineHeight: 1.15,
58
+ textSizeAdjust: "100%",
59
+ WebkitFontSmoothing: "antialiased"
60
+ },
61
+ /** Make media elements responsive */
62
+ "img, picture, video, canvas, svg": {
63
+ display: "block",
64
+ maxWidth: "100%"
65
+ },
66
+ /** Avoid overflow of text */
67
+ "p, h1, h2, h3, h4, h5, h6": {
68
+ overflowWrap: "break-word"
69
+ },
70
+ /** Improve text wrapping */
71
+ p: {
72
+ textWrap: "pretty"
73
+ },
74
+ "h1, h2, h3, h4, h5, h6": {
75
+ textWrap: "balance"
76
+ },
77
+ /** Improve link color */
78
+ a: {
79
+ color: "currentColor"
80
+ },
81
+ /** Improve button line height */
82
+ button: {
83
+ lineHeight: "1em",
84
+ color: "currentColor"
85
+ },
86
+ /** Improve form elements */
87
+ "input, optgroup, select, textarea": {
88
+ fontFamily: "inherit",
89
+ fontSize: "100%",
90
+ lineHeight: "1.15em"
91
+ }
92
+ };
18
93
  class SaltyCompiler {
19
94
  constructor(projectRootDir) {
20
95
  __publicField(this, "importFile", (path) => {
@@ -653,5 +728,7 @@ ${newContent}
653
728
  }
654
729
  }
655
730
  export {
656
- SaltyCompiler
731
+ SaltyCompiler,
732
+ logError as a,
733
+ logger as l
657
734
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.310",
3
+ "version": "0.0.1-alpha.311",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -47,10 +47,6 @@
47
47
  "import": "./bin/main.js",
48
48
  "require": "./bin/main.cjs"
49
49
  },
50
- "./compiler": {
51
- "import": "./compiler/index.js",
52
- "require": "./compiler/index.cjs"
53
- },
54
50
  "./compiler/as-class": {
55
51
  "import": "./compiler/as-class.js",
56
52
  "require": "./compiler/as-class.cjs"
package/server/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const shouldRestart = require("../should-restart-DoaGoD5T.cjs");
3
+ const shouldRestart = require("../should-restart-CQsyHls3.cjs");
4
4
  exports.checkShouldRestart = shouldRestart.checkShouldRestart;
package/server/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c } from "../should-restart-5jI-bzz0.js";
1
+ import { c } from "../should-restart-CXIO0jxY.js";
2
2
  export {
3
3
  c as checkShouldRestart
4
4
  };
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  const promises = require("fs/promises");
3
- const compiler_index = require("./compiler/index.cjs");
3
+ const compiler_helpers = require("./compiler/helpers.cjs");
4
4
  const checkShouldRestart = async (filename) => {
5
5
  if (!filename) return false;
6
6
  if (filename.includes("node_modules")) return false;
7
7
  if (filename.includes("saltygen")) return false;
8
8
  const isConfig = filename.includes("salty.config");
9
9
  if (isConfig) return true;
10
- const isSalty = compiler_index.isSaltyFile(filename);
10
+ const isSalty = compiler_helpers.isSaltyFile(filename);
11
11
  if (!isSalty) return false;
12
12
  const contents = await promises.readFile(filename, "utf-8");
13
13
  if (/.+define[A-Z]\w+/.test(contents)) return true;