@adrifer/winix 0.1.1 → 0.1.2-preview.0

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.
@@ -5,7 +5,7 @@ import { existsSync } from "node:fs";
5
5
  import { loadWorkspace } from "../loader.js";
6
6
  import { evaluate } from "../../evaluator/index.js";
7
7
  import { generateNix } from "../../backends/nix/index.js";
8
- import { activationCommand, platformForEvaluatedHost } from "../activation.js";
8
+ import { platformForEvaluatedHost } from "../activation.js";
9
9
  export async function applyWorkspace(cwd, opts) {
10
10
  const { workspace, configDir } = await loadWorkspace(cwd);
11
11
  let evaluated = evaluate(workspace);
@@ -64,17 +64,14 @@ function resultFor(configDir, outDir, evaluated) {
64
64
  hostPlatforms: new Map(evaluated.map((host) => [host.name, platformForEvaluatedHost(host)])),
65
65
  };
66
66
  }
67
- function printNextSteps(cwd, outDir, evaluated) {
68
- const relativeOutDir = relative(cwd, outDir) || ".winix/out";
69
- const flakeBase = `path:$(pwd)/${relativeOutDir}`;
70
- const commands = evaluated.map((host) => activationCommand(platformForEvaluatedHost(host), `${flakeBase}#${host.name}`, false).join(" "));
71
- if (commands.length === 1) {
72
- console.log(`\nNext: ${commands[0]}`);
67
+ function printNextSteps(_cwd, _outDir, evaluated) {
68
+ if (evaluated.length === 1) {
69
+ console.log(`\nNext: winix switch`);
73
70
  return;
74
71
  }
75
72
  console.log("\nNext:");
76
- for (const command of commands) {
77
- console.log(` ${command}`);
73
+ for (const host of evaluated) {
74
+ console.log(` winix switch --host ${host.name}`);
78
75
  }
79
76
  }
80
77
  function printWarnings(warnings) {
@@ -2,4 +2,5 @@ interface InitOptions {
2
2
  force: boolean;
3
3
  }
4
4
  export declare function init(cwd: string, opts: InitOptions): Promise<void>;
5
+ export declare function resolveWinixVersionRange(): Promise<string>;
5
6
  export {};
@@ -1,11 +1,14 @@
1
1
  import { join } from "node:path";
2
- import { mkdir, writeFile } from "node:fs/promises";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { existsSync } from "node:fs";
4
+ import { fileURLToPath } from "node:url";
4
5
  export async function init(cwd, opts) {
5
6
  await mkdir(cwd, { recursive: true });
7
+ const versionRange = await resolveWinixVersionRange();
8
+ const packageJson = renderPackageJson(versionRange);
6
9
  await writeIfAllowed(join(cwd, "winix.config.ts"), CONFIG, opts.force);
7
10
  await writeIfAllowed(join(cwd, "tsconfig.json"), TSCONFIG, opts.force);
8
- await writeIfAllowed(join(cwd, "package.json"), PACKAGE_JSON, opts.force);
11
+ await writeIfAllowed(join(cwd, "package.json"), packageJson, opts.force);
9
12
  await writeIfAllowed(join(cwd, ".gitignore"), GITIGNORE, opts.force);
10
13
  console.log("✓ Initialized Winix project");
11
14
  console.log("");
@@ -18,6 +21,45 @@ async function writeIfAllowed(path, content, force) {
18
21
  }
19
22
  await writeFile(path, content);
20
23
  }
24
+ const FALLBACK_VERSION_RANGE = "^0.1.0";
25
+ export async function resolveWinixVersionRange() {
26
+ try {
27
+ const here = currentDir();
28
+ // Compiled layout: dist/cli/commands/init.js → ../../../package.json
29
+ // Source layout: src/cli/commands/init.ts → ../../../package.json
30
+ const pkgPath = join(here, "..", "..", "..", "package.json");
31
+ const raw = await readFile(pkgPath, "utf-8");
32
+ const parsed = JSON.parse(raw);
33
+ if (typeof parsed.version === "string" && /^\d+\.\d+\.\d+/.test(parsed.version)) {
34
+ return `^${parsed.version}`;
35
+ }
36
+ }
37
+ catch {
38
+ // fall through to default
39
+ }
40
+ return FALLBACK_VERSION_RANGE;
41
+ }
42
+ function currentDir() {
43
+ const filePath = fileURLToPath(import.meta.url);
44
+ const idx = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
45
+ return idx === -1 ? "." : filePath.slice(0, idx);
46
+ }
47
+ function renderPackageJson(versionRange) {
48
+ const escaped = JSON.stringify(versionRange);
49
+ return `{
50
+ "type": "module",
51
+ "private": true,
52
+ "dependencies": {
53
+ "@adrifer/winix": ${escaped}
54
+ },
55
+ "scripts": {
56
+ "check": "winix check",
57
+ "apply": "winix apply",
58
+ "switch": "winix switch"
59
+ }
60
+ }
61
+ `;
62
+ }
21
63
  const CONFIG = `import { account, host, nixos, platforms, workspace } from "@adrifer/winix";
22
64
 
23
65
  export default workspace({
@@ -36,19 +78,6 @@ export default workspace({
36
78
  ],
37
79
  });
38
80
  `;
39
- const PACKAGE_JSON = `{
40
- "type": "module",
41
- "private": true,
42
- "dependencies": {
43
- "@adrifer/winix": "^0.1.0"
44
- },
45
- "scripts": {
46
- "check": "winix check",
47
- "apply": "winix apply",
48
- "switch": "winix switch"
49
- }
50
- }
51
- `;
52
81
  const GITIGNORE = `.winix/
53
82
  node_modules/
54
83
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adrifer/winix",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-preview.0",
4
4
  "description": "TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager",
5
5
  "license": "MIT",
6
6
  "author": "Adrian Fernandez",