@salty-css/core 0.1.0-alpha.6 → 0.1.0-alpha.8

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/context.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RCFile } from '../types/cli-types';
2
2
  import { PackageJson } from './package-json';
3
3
  export interface ProjectContext {
4
- rootDir: string;
4
+ cwd: string;
5
5
  projectDir: string;
6
6
  relativeProjectPath: string;
7
7
  packageJson?: PackageJson;
@@ -11,6 +11,8 @@ export interface ComponentTemplates {
11
11
  }
12
12
  export interface FrameworkAdapter {
13
13
  name: FrameworkName;
14
+ /** The path to the framework's source files. */
15
+ srcDirectory: string;
14
16
  /** True when this framework matches the project. Adapters are evaluated in registry order. */
15
17
  detect(ctx: ProjectContext): Promise<boolean> | boolean;
16
18
  /** The runtime npm spec to install for this framework, e.g. `@salty-css/react@1.2.3`. */
package/bin/main.cjs CHANGED
@@ -85,27 +85,28 @@ const getDefaultProject = async (rootDir = process.cwd()) => {
85
85
  return rc.defaultProject;
86
86
  };
87
87
  const upsertProjectInRc = (existingRaw, relativeProjectPath, framework) => {
88
+ const projectPath = path.join(relativeProjectPath, framework.srcDirectory);
88
89
  if (existingRaw === void 0) {
89
90
  const fresh = {
90
91
  $schema: SALTYRC_SCHEMA,
91
92
  info: SALTYRC_INFO,
92
- defaultProject: relativeProjectPath,
93
- projects: [{ dir: relativeProjectPath, framework }]
93
+ defaultProject: projectPath,
94
+ projects: [{ dir: projectPath, framework: framework.name }]
94
95
  };
95
96
  return { content: JSON.stringify(fresh, null, 2), changed: true, created: true };
96
97
  }
97
98
  const rc = JSON.parse(existingRaw);
98
99
  const projects = rc.projects || [];
99
- const exists = projects.some((p) => p.dir === relativeProjectPath);
100
+ const exists = projects.some((p) => p.dir === projectPath);
100
101
  if (exists) return { content: existingRaw, changed: false, created: false };
101
- projects.push({ dir: relativeProjectPath, framework });
102
+ projects.push({ dir: projectPath, framework: framework.name });
102
103
  rc.projects = [...projects];
103
104
  const next = JSON.stringify(rc, null, 2);
104
105
  return { content: next, changed: next !== existingRaw, created: false };
105
106
  };
106
- const writeProjectToRc = async (rootDir, relativeProjectPath, framework) => {
107
- const path2 = saltyrcPath(rootDir);
108
- const existing = await readRawRc(rootDir);
107
+ const writeProjectToRc = async (cwd, relativeProjectPath, framework) => {
108
+ const path2 = saltyrcPath(cwd);
109
+ const existing = await readRawRc(cwd);
109
110
  const { content, changed, created } = upsertProjectInRc(existing, relativeProjectPath, framework);
110
111
  if (!changed) return false;
111
112
  if (created) compiler_saltyCompiler.logger.info("Creating file: " + path2);
@@ -124,17 +125,17 @@ const resolveProjectDir = (dir, rootDir = process.cwd()) => {
124
125
  return path.join(rootDir, dirName);
125
126
  };
126
127
  const buildContext = async (opts) => {
127
- const rootDir = process.cwd();
128
- const projectDir = resolveProjectDir(opts.dir, rootDir);
129
- const relativeProjectPath = path.relative(rootDir, projectDir) || ".";
128
+ const cwd = process.cwd();
129
+ const projectDir = resolveProjectDir(opts.dir, cwd);
130
+ const relativeProjectPath = path.relative(cwd, projectDir) || ".";
130
131
  const packageJson = await readPackageJson().catch(() => void 0);
131
132
  if (opts.requirePackageJson !== false && !packageJson) {
132
133
  throw new Error("Salty CSS project must be initialized in a directory with a package.json file.");
133
134
  }
134
- const rcFile = await readRc(rootDir);
135
+ const rcFile = await readRc(cwd);
135
136
  const cliPackageJson = await readThisPackageJson();
136
137
  return {
137
- rootDir,
138
+ cwd,
138
139
  projectDir,
139
140
  relativeProjectPath,
140
141
  packageJson,
@@ -181,6 +182,7 @@ const hasAstroDependency = (ctx) => {
181
182
  };
182
183
  const astroFramework = {
183
184
  name: "astro",
185
+ srcDirectory: "src",
184
186
  detect: (ctx) => Boolean(findAstroConfig(ctx.projectDir)) || hasAstroDependency(ctx),
185
187
  runtimePackage: (version) => `@salty-css/astro@${version}`,
186
188
  templates: {
@@ -194,6 +196,7 @@ const astroFramework = {
194
196
  };
195
197
  const reactFramework = {
196
198
  name: "react",
199
+ srcDirectory: "",
197
200
  detect: () => true,
198
201
  // default fallback — evaluated last in the registry
199
202
  runtimePackage: (version) => `@salty-css/react@${version}`,
@@ -402,7 +405,7 @@ ${existing}`;
402
405
  const eslintIntegration = {
403
406
  name: "eslint",
404
407
  detect: (ctx) => {
405
- const candidates = eslintConfigCandidates(ctx.projectDir, ctx.rootDir);
408
+ const candidates = eslintConfigCandidates(ctx.projectDir, ctx.cwd);
406
409
  return candidates.find((p) => fs.existsSync(p)) ?? null;
407
410
  },
408
411
  apply: async (ctx, configPath) => {
@@ -561,8 +564,8 @@ const registerInitCommand = (program) => {
561
564
  const projectFiles = await Promise.all([readTemplate("salty.config.ts"), readTemplate("saltygen/index.css")]);
562
565
  await promises.mkdir(ctx.projectDir, { recursive: true });
563
566
  await Promise.all(projectFiles.map(({ fileName, content }) => writeProjectFile(ctx.projectDir, fileName, content)));
564
- await writeProjectToRc(ctx.rootDir, ctx.relativeProjectPath, framework.name);
565
- await ensureGitignoreSaltygen(ctx.rootDir);
567
+ await writeProjectToRc(ctx.cwd, ctx.relativeProjectPath, framework);
568
+ await ensureGitignoreSaltygen(ctx.cwd);
566
569
  await importSaltygenIntoCss(ctx.projectDir, opts.cssFile);
567
570
  await detectAndApplyIntegrations(ctx);
568
571
  await wirePrepareScript();
package/bin/main.js CHANGED
@@ -82,27 +82,28 @@ const getDefaultProject = async (rootDir = process.cwd()) => {
82
82
  return rc.defaultProject;
83
83
  };
84
84
  const upsertProjectInRc = (existingRaw, relativeProjectPath, framework) => {
85
+ const projectPath = join(relativeProjectPath, framework.srcDirectory);
85
86
  if (existingRaw === void 0) {
86
87
  const fresh = {
87
88
  $schema: SALTYRC_SCHEMA,
88
89
  info: SALTYRC_INFO,
89
- defaultProject: relativeProjectPath,
90
- projects: [{ dir: relativeProjectPath, framework }]
90
+ defaultProject: projectPath,
91
+ projects: [{ dir: projectPath, framework: framework.name }]
91
92
  };
92
93
  return { content: JSON.stringify(fresh, null, 2), changed: true, created: true };
93
94
  }
94
95
  const rc = JSON.parse(existingRaw);
95
96
  const projects = rc.projects || [];
96
- const exists = projects.some((p) => p.dir === relativeProjectPath);
97
+ const exists = projects.some((p) => p.dir === projectPath);
97
98
  if (exists) return { content: existingRaw, changed: false, created: false };
98
- projects.push({ dir: relativeProjectPath, framework });
99
+ projects.push({ dir: projectPath, framework: framework.name });
99
100
  rc.projects = [...projects];
100
101
  const next = JSON.stringify(rc, null, 2);
101
102
  return { content: next, changed: next !== existingRaw, created: false };
102
103
  };
103
- const writeProjectToRc = async (rootDir, relativeProjectPath, framework) => {
104
- const path = saltyrcPath(rootDir);
105
- const existing = await readRawRc(rootDir);
104
+ const writeProjectToRc = async (cwd, relativeProjectPath, framework) => {
105
+ const path = saltyrcPath(cwd);
106
+ const existing = await readRawRc(cwd);
106
107
  const { content, changed, created } = upsertProjectInRc(existing, relativeProjectPath, framework);
107
108
  if (!changed) return false;
108
109
  if (created) logger.info("Creating file: " + path);
@@ -121,17 +122,17 @@ const resolveProjectDir = (dir, rootDir = process.cwd()) => {
121
122
  return join(rootDir, dirName);
122
123
  };
123
124
  const buildContext = async (opts) => {
124
- const rootDir = process.cwd();
125
- const projectDir = resolveProjectDir(opts.dir, rootDir);
126
- const relativeProjectPath = relative(rootDir, projectDir) || ".";
125
+ const cwd = process.cwd();
126
+ const projectDir = resolveProjectDir(opts.dir, cwd);
127
+ const relativeProjectPath = relative(cwd, projectDir) || ".";
127
128
  const packageJson = await readPackageJson().catch(() => void 0);
128
129
  if (opts.requirePackageJson !== false && !packageJson) {
129
130
  throw new Error("Salty CSS project must be initialized in a directory with a package.json file.");
130
131
  }
131
- const rcFile = await readRc(rootDir);
132
+ const rcFile = await readRc(cwd);
132
133
  const cliPackageJson = await readThisPackageJson();
133
134
  return {
134
- rootDir,
135
+ cwd,
135
136
  projectDir,
136
137
  relativeProjectPath,
137
138
  packageJson,
@@ -178,6 +179,7 @@ const hasAstroDependency = (ctx) => {
178
179
  };
179
180
  const astroFramework = {
180
181
  name: "astro",
182
+ srcDirectory: "src",
181
183
  detect: (ctx) => Boolean(findAstroConfig(ctx.projectDir)) || hasAstroDependency(ctx),
182
184
  runtimePackage: (version) => `@salty-css/astro@${version}`,
183
185
  templates: {
@@ -191,6 +193,7 @@ const astroFramework = {
191
193
  };
192
194
  const reactFramework = {
193
195
  name: "react",
196
+ srcDirectory: "",
194
197
  detect: () => true,
195
198
  // default fallback — evaluated last in the registry
196
199
  runtimePackage: (version) => `@salty-css/react@${version}`,
@@ -399,7 +402,7 @@ ${existing}`;
399
402
  const eslintIntegration = {
400
403
  name: "eslint",
401
404
  detect: (ctx) => {
402
- const candidates = eslintConfigCandidates(ctx.projectDir, ctx.rootDir);
405
+ const candidates = eslintConfigCandidates(ctx.projectDir, ctx.cwd);
403
406
  return candidates.find((p) => existsSync(p)) ?? null;
404
407
  },
405
408
  apply: async (ctx, configPath) => {
@@ -558,8 +561,8 @@ const registerInitCommand = (program) => {
558
561
  const projectFiles = await Promise.all([readTemplate("salty.config.ts"), readTemplate("saltygen/index.css")]);
559
562
  await mkdir(ctx.projectDir, { recursive: true });
560
563
  await Promise.all(projectFiles.map(({ fileName, content }) => writeProjectFile(ctx.projectDir, fileName, content)));
561
- await writeProjectToRc(ctx.rootDir, ctx.relativeProjectPath, framework.name);
562
- await ensureGitignoreSaltygen(ctx.rootDir);
564
+ await writeProjectToRc(ctx.cwd, ctx.relativeProjectPath, framework);
565
+ await ensureGitignoreSaltygen(ctx.cwd);
563
566
  await importSaltygenIntoCss(ctx.projectDir, opts.cssFile);
564
567
  await detectAndApplyIntegrations(ctx);
565
568
  await wirePrepareScript();
package/bin/saltyrc.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RCFile } from '../types/cli-types';
2
+ import { FrameworkAdapter } from './frameworks';
2
3
  export declare const SALTYRC_FILENAME = ".saltyrc.json";
3
4
  export declare const SALTYRC_SCHEMA = "./node_modules/@salty-css/core/.saltyrc.schema.json";
4
5
  export declare 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.";
@@ -17,7 +18,7 @@ export declare const getDefaultProject: (rootDir?: string) => Promise<string | u
17
18
  * - If the project entry already exists, returns the same content (no-op).
18
19
  * - Otherwise appends the new entry and returns updated content.
19
20
  */
20
- export declare const upsertProjectInRc: (existingRaw: string | undefined, relativeProjectPath: string, framework: string) => {
21
+ export declare const upsertProjectInRc: (existingRaw: string | undefined, relativeProjectPath: string, framework: FrameworkAdapter) => {
21
22
  content: string;
22
23
  changed: boolean;
23
24
  created: boolean;
@@ -26,5 +27,5 @@ export declare const upsertProjectInRc: (existingRaw: string | undefined, relati
26
27
  * Writes the saltyrc file, creating or updating the project entry for the given dir.
27
28
  * Returns true when a write occurred.
28
29
  */
29
- export declare const writeProjectToRc: (rootDir: string, relativeProjectPath: string, framework: string) => Promise<boolean>;
30
+ export declare const writeProjectToRc: (cwd: string, relativeProjectPath: string, framework: FrameworkAdapter) => Promise<boolean>;
30
31
  export declare const getProjectFramework: (rc: RCFile, relativeProjectPath: string) => string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",