tangled
alpha
login
or
join now
danabra.mov
/
typelex
56
fork
atom
An experimental TypeSpec syntax for Lexicon
56
fork
atom
overview
issues
1
pulls
2
pipelines
handoff
danabra.mov
5 months ago
f3211ace
3cf2e105
+55
-10
2 changed files
expand all
collapse all
unified
split
packages
cli
src
cli.ts
commands
init.ts
+10
-3
packages/cli/src/cli.ts
···
10
.command(
11
"init",
12
"Initialize a new typelex project",
13
-
() => {},
14
-
async () => {
15
-
await initCommand();
0
0
0
0
0
0
0
16
}
17
)
18
.command(
···
10
.command(
11
"init",
12
"Initialize a new typelex project",
13
+
(yargs) => {
14
+
return yargs.option("setup", {
15
+
describe: "Internal: run setup after installation",
16
+
type: "boolean",
17
+
hidden: true,
18
+
default: false,
19
+
});
20
+
},
21
+
async (argv) => {
22
+
await initCommand(argv.setup);
23
}
24
)
25
.command(
+45
-7
packages/cli/src/commands/init.ts
···
39
}
40
41
/**
42
-
* Initialize a new typelex project
0
43
*/
44
-
export async function initCommand(): Promise<void> {
45
const cwd = process.cwd();
46
-
const typelexDir = resolve(cwd, "typelex");
47
-
const mainTspPath = resolve(typelexDir, "main.tsp");
48
-
const externalsTspPath = resolve(typelexDir, "externals.tsp");
0
0
49
50
console.log(pc.bold("Initializing typelex project...\n"));
51
console.log("Installing dependencies...");
···
71
dir = resolve(dir, "..");
72
}
73
74
-
// Install dependencies and only proceed if successful
75
await new Promise<void>((resolvePromise, reject) => {
76
const args = packageManager === "npm"
77
? ["install", "--save-dev", "@typelex/cli", "@typelex/emitter"]
···
98
});
99
});
100
101
-
// Prompt for namespace after successful installation
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
102
let namespace = await promptNamespace();
103
104
// Validate namespace format
···
39
}
40
41
/**
42
+
* Initialize command - installs packages and hands off to local version
43
+
* This is what gets called by npx
44
*/
45
+
export async function initCommand(isSetup: boolean = false): Promise<void> {
46
const cwd = process.cwd();
47
+
48
+
// If this is the second pass (after handoff), run setup
49
+
if (isSetup) {
50
+
return initSetup();
51
+
}
52
53
console.log(pc.bold("Initializing typelex project...\n"));
54
console.log("Installing dependencies...");
···
74
dir = resolve(dir, "..");
75
}
76
77
+
// Install dependencies
78
await new Promise<void>((resolvePromise, reject) => {
79
const args = packageManager === "npm"
80
? ["install", "--save-dev", "@typelex/cli", "@typelex/emitter"]
···
101
});
102
});
103
104
+
// Hand off to locally installed version
105
+
console.log("Continuing with local installation...\n");
106
+
107
+
return new Promise((resolvePromise, reject) => {
108
+
const localCli = resolve(cwd, "node_modules/.bin/typelex");
109
+
const setup = spawn(localCli, ["init", "--setup"], {
110
+
cwd,
111
+
stdio: "inherit",
112
+
});
113
+
114
+
setup.on("close", (code) => {
115
+
if (code === 0) {
116
+
resolvePromise();
117
+
} else {
118
+
process.exit(code ?? 1);
119
+
}
120
+
});
121
+
122
+
setup.on("error", (err) => {
123
+
console.error(pc.red("✗ Failed to run setup:"), err);
124
+
reject(err);
125
+
});
126
+
});
127
+
}
128
+
129
+
/**
130
+
* Setup function - called after packages are installed
131
+
* This runs from the locally installed version
132
+
*/
133
+
export async function initSetup(): Promise<void> {
134
+
const cwd = process.cwd();
135
+
const typelexDir = resolve(cwd, "typelex");
136
+
const mainTspPath = resolve(typelexDir, "main.tsp");
137
+
const externalsTspPath = resolve(typelexDir, "externals.tsp");
138
+
139
+
// Prompt for namespace
140
let namespace = await promptNamespace();
141
142
// Validate namespace format