@typokit/turbo 0.1.4
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/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline.d.ts +32 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +50 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/scripts.d.ts +29 -0
- package/dist/scripts.d.ts.map +1 -0
- package/dist/scripts.js +51 -0
- package/dist/scripts.js.map +1 -0
- package/dist/setup.d.ts +11 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +125 -0
- package/dist/setup.js.map +1 -0
- package/package.json +25 -0
- package/src/env.d.ts +7 -0
- package/src/index.test.ts +178 -0
- package/src/index.ts +16 -0
- package/src/pipeline.ts +83 -0
- package/src/scripts.ts +80 -0
- package/src/setup.ts +130 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createTurboConfig, defaultPipeline } from "./pipeline.js";
|
|
2
|
+
export type { TurboPipeline, TurboTaskConfig, TurboConfig, } from "./pipeline.js";
|
|
3
|
+
export { runBuild, runDev, runTest, runTypokitTask } from "./scripts.js";
|
|
4
|
+
export type { TaskOptions } from "./scripts.js";
|
|
5
|
+
export { getSetupInstructions, getTurboJsonTemplate } from "./setup.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACnE,YAAY,EACV,aAAa,EACb,eAAe,EACf,WAAW,GACZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACzE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @typokit/turbo — Turborepo Integration Helpers
|
|
2
|
+
// Pipeline configuration
|
|
3
|
+
export { createTurboConfig, defaultPipeline } from "./pipeline.js";
|
|
4
|
+
// Helper scripts
|
|
5
|
+
export { runBuild, runDev, runTest, runTypokitTask } from "./scripts.js";
|
|
6
|
+
// Setup utilities
|
|
7
|
+
export { getSetupInstructions, getTurboJsonTemplate } from "./setup.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,yBAAyB;AACzB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAOnE,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGzE,kBAAkB;AAClB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Configuration for a single Turborepo task */
|
|
2
|
+
export interface TurboTaskConfig {
|
|
3
|
+
dependsOn?: string[];
|
|
4
|
+
outputs?: string[];
|
|
5
|
+
cache?: boolean;
|
|
6
|
+
persistent?: boolean;
|
|
7
|
+
env?: string[];
|
|
8
|
+
inputs?: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Map of task names to their configuration */
|
|
11
|
+
export interface TurboPipeline {
|
|
12
|
+
[taskName: string]: TurboTaskConfig;
|
|
13
|
+
}
|
|
14
|
+
/** Root turbo.json structure */
|
|
15
|
+
export interface TurboConfig {
|
|
16
|
+
$schema?: string;
|
|
17
|
+
tasks: TurboPipeline;
|
|
18
|
+
globalDependencies?: string[];
|
|
19
|
+
globalEnv?: string[];
|
|
20
|
+
}
|
|
21
|
+
/** Default pipeline tasks for a TypoKit project */
|
|
22
|
+
export declare const defaultPipeline: TurboPipeline;
|
|
23
|
+
/**
|
|
24
|
+
* Create a turbo.json configuration object with TypoKit defaults.
|
|
25
|
+
* Merges user overrides on top of the default pipeline.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createTurboConfig(overrides?: {
|
|
28
|
+
tasks?: TurboPipeline;
|
|
29
|
+
globalDependencies?: string[];
|
|
30
|
+
globalEnv?: string[];
|
|
31
|
+
}): TurboConfig;
|
|
32
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAEA,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAAC;CACrC;AAED,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,mDAAmD;AACnD,eAAO,MAAM,eAAe,EAAE,aAuB7B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE;IAC5C,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,GAAG,WAAW,CAuBd"}
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @typokit/turbo — Turborepo pipeline configuration helpers
|
|
2
|
+
/** Default pipeline tasks for a TypoKit project */
|
|
3
|
+
export const defaultPipeline = {
|
|
4
|
+
build: {
|
|
5
|
+
dependsOn: ["^build"],
|
|
6
|
+
outputs: ["dist/**", ".typokit/**"],
|
|
7
|
+
inputs: ["src/**/*.ts", "tsconfig.json"],
|
|
8
|
+
},
|
|
9
|
+
dev: {
|
|
10
|
+
dependsOn: ["^build"],
|
|
11
|
+
cache: false,
|
|
12
|
+
persistent: true,
|
|
13
|
+
},
|
|
14
|
+
test: {
|
|
15
|
+
dependsOn: ["build"],
|
|
16
|
+
outputs: [],
|
|
17
|
+
inputs: ["src/**/*.ts", "src/**/*.test.ts"],
|
|
18
|
+
},
|
|
19
|
+
typecheck: {
|
|
20
|
+
dependsOn: ["^build"],
|
|
21
|
+
outputs: [],
|
|
22
|
+
},
|
|
23
|
+
lint: {
|
|
24
|
+
outputs: [],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Create a turbo.json configuration object with TypoKit defaults.
|
|
29
|
+
* Merges user overrides on top of the default pipeline.
|
|
30
|
+
*/
|
|
31
|
+
export function createTurboConfig(overrides) {
|
|
32
|
+
const tasks = { ...defaultPipeline };
|
|
33
|
+
if (overrides?.tasks) {
|
|
34
|
+
for (const [key, value] of Object.entries(overrides.tasks)) {
|
|
35
|
+
tasks[key] = { ...tasks[key], ...value };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const config = {
|
|
39
|
+
$schema: "https://turbo.build/schema.json",
|
|
40
|
+
tasks,
|
|
41
|
+
};
|
|
42
|
+
if (overrides?.globalDependencies) {
|
|
43
|
+
config.globalDependencies = overrides.globalDependencies;
|
|
44
|
+
}
|
|
45
|
+
if (overrides?.globalEnv) {
|
|
46
|
+
config.globalEnv = overrides.globalEnv;
|
|
47
|
+
}
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAyB5D,mDAAmD;AACnD,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC5C,KAAK,EAAE;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,OAAO,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC;QACnC,MAAM,EAAE,CAAC,aAAa,EAAE,eAAe,CAAC;KACzC;IACD,GAAG,EAAE;QACH,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,IAAI;KACjB;IACD,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,OAAO,CAAC;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,CAAC,aAAa,EAAE,kBAAkB,CAAC;KAC5C;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,OAAO,EAAE,EAAE;KACZ;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,EAAE;KACZ;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAIjC;IACC,MAAM,KAAK,GAAkB,EAAE,GAAG,eAAe,EAAE,CAAC;IAEpD,IAAI,SAAS,EAAE,KAAK,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3D,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAgB;QAC1B,OAAO,EAAE,iCAAiC;QAC1C,KAAK;KACN,CAAC;IAEF,IAAI,SAAS,EAAE,kBAAkB,EAAE,CAAC;QAClC,MAAM,CAAC,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC;IAC3D,CAAC;IAED,IAAI,SAAS,EAAE,SAAS,EAAE,CAAC;QACzB,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Options for running a TypoKit task */
|
|
2
|
+
export interface TaskOptions {
|
|
3
|
+
/** Working directory (defaults to process.cwd()) */
|
|
4
|
+
cwd?: string;
|
|
5
|
+
/** Additional CLI arguments */
|
|
6
|
+
args?: string[];
|
|
7
|
+
/** Environment variables to set */
|
|
8
|
+
env?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Run a typokit CLI command as a child process.
|
|
12
|
+
* Designed for use in Turborepo task scripts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runTypokitTask(command: string, options?: TaskOptions): Promise<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/** Run `typokit build` — suitable as a Turborepo build task */
|
|
18
|
+
export declare function runBuild(options?: TaskOptions): Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
/** Run `typokit dev` — suitable as a Turborepo dev task */
|
|
22
|
+
export declare function runDev(options?: TaskOptions): Promise<{
|
|
23
|
+
success: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
/** Run `typokit test` — suitable as a Turborepo test task */
|
|
26
|
+
export declare function runTest(options?: TaskOptions): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAkBD;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAuB/B;AAED,+DAA+D;AAC/D,wBAAsB,QAAQ,CAC5B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAE/B;AAED,2DAA2D;AAC3D,wBAAsB,MAAM,CAC1B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAE/B;AAED,6DAA6D;AAC7D,wBAAsB,OAAO,CAC3B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAE/B"}
|
package/dist/scripts.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @typokit/turbo — Helper scripts wrapping typokit CLI for Turborepo
|
|
2
|
+
/** Get process.env safely (no @types/node) */
|
|
3
|
+
function getProcessEnv() {
|
|
4
|
+
const g = globalThis;
|
|
5
|
+
const proc = g["process"];
|
|
6
|
+
return proc?.env ?? {};
|
|
7
|
+
}
|
|
8
|
+
/** Get process.cwd() safely */
|
|
9
|
+
function getProcessCwd() {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
const proc = g["process"];
|
|
12
|
+
return proc?.cwd() ?? ".";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Run a typokit CLI command as a child process.
|
|
16
|
+
* Designed for use in Turborepo task scripts.
|
|
17
|
+
*/
|
|
18
|
+
export async function runTypokitTask(command, options) {
|
|
19
|
+
const cp = (await import(/* @vite-ignore */ "child_process"));
|
|
20
|
+
const cwd = options?.cwd ?? getProcessCwd();
|
|
21
|
+
const extraArgs = options?.args?.join(" ") ?? "";
|
|
22
|
+
const fullCommand = `npx typokit ${command}${extraArgs ? " " + extraArgs : ""}`;
|
|
23
|
+
try {
|
|
24
|
+
cp.execSync(fullCommand, {
|
|
25
|
+
cwd,
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
env: {
|
|
28
|
+
...getProcessEnv(),
|
|
29
|
+
FORCE_COLOR: "true",
|
|
30
|
+
...options?.env,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return { success: true };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return { success: false };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Run `typokit build` — suitable as a Turborepo build task */
|
|
40
|
+
export async function runBuild(options) {
|
|
41
|
+
return runTypokitTask("build", options);
|
|
42
|
+
}
|
|
43
|
+
/** Run `typokit dev` — suitable as a Turborepo dev task */
|
|
44
|
+
export async function runDev(options) {
|
|
45
|
+
return runTypokitTask("dev", options);
|
|
46
|
+
}
|
|
47
|
+
/** Run `typokit test` — suitable as a Turborepo test task */
|
|
48
|
+
export async function runTest(options) {
|
|
49
|
+
return runTypokitTask("test", options);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAYrE,8CAA8C;AAC9C,SAAS,aAAa;IACpB,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,MAAM,IAAI,GAAG,CAAC,CAAC,SAAS,CAEX,CAAC;IACd,OAAO,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,+BAA+B;AAC/B,SAAS,aAAa;IACpB,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,MAAM,IAAI,GAAG,CAAC,CAAC,SAAS,CAAsC,CAAC;IAC/D,OAAO,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAe,EACf,OAAqB;IAErB,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAE3D,CAAC;IAEF,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,aAAa,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACjD,MAAM,WAAW,GAAG,eAAe,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEhF,IAAI,CAAC;QACH,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE;YACvB,GAAG;YACH,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE;gBACH,GAAG,aAAa,EAAE;gBAClB,WAAW,EAAE,MAAM;gBACnB,GAAG,OAAO,EAAE,GAAG;aAChB;SACF,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAAqB;IAErB,OAAO,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAqB;IAErB,OAAO,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,OAAqB;IAErB,OAAO,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createTurboConfig } from "./pipeline.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a turbo.json template string ready to write to disk.
|
|
4
|
+
* Generates a complete turbo.json with TypoKit-optimized pipeline tasks.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getTurboJsonTemplate(overrides?: Parameters<typeof createTurboConfig>[0]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns setup instructions for integrating TypoKit into a Turborepo workspace.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSetupInstructions(): string;
|
|
11
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAClD,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA8G7C"}
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @typokit/turbo — Setup instructions and template generation
|
|
2
|
+
import { createTurboConfig } from "./pipeline.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns a turbo.json template string ready to write to disk.
|
|
5
|
+
* Generates a complete turbo.json with TypoKit-optimized pipeline tasks.
|
|
6
|
+
*/
|
|
7
|
+
export function getTurboJsonTemplate(overrides) {
|
|
8
|
+
const config = createTurboConfig(overrides);
|
|
9
|
+
return JSON.stringify(config, null, 2) + "\n";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns setup instructions for integrating TypoKit into a Turborepo workspace.
|
|
13
|
+
*/
|
|
14
|
+
export function getSetupInstructions() {
|
|
15
|
+
return `# Setting up TypoKit in a Turborepo workspace
|
|
16
|
+
|
|
17
|
+
## 1. Install dependencies
|
|
18
|
+
|
|
19
|
+
In your Turborepo root:
|
|
20
|
+
|
|
21
|
+
\`\`\`bash
|
|
22
|
+
npm install @typokit/turbo --save-dev
|
|
23
|
+
# or
|
|
24
|
+
pnpm add @typokit/turbo --save-dev -w
|
|
25
|
+
\`\`\`
|
|
26
|
+
|
|
27
|
+
In your TypoKit server package:
|
|
28
|
+
|
|
29
|
+
\`\`\`bash
|
|
30
|
+
npm install @typokit/core @typokit/types
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
## 2. Configure turbo.json
|
|
34
|
+
|
|
35
|
+
Add TypoKit-aware pipeline tasks to your \`turbo.json\`:
|
|
36
|
+
|
|
37
|
+
\`\`\`json
|
|
38
|
+
{
|
|
39
|
+
"$schema": "https://turbo.build/schema.json",
|
|
40
|
+
"tasks": {
|
|
41
|
+
"build": {
|
|
42
|
+
"dependsOn": ["^build"],
|
|
43
|
+
"outputs": ["dist/**", ".typokit/**"],
|
|
44
|
+
"inputs": ["src/**/*.ts", "tsconfig.json"]
|
|
45
|
+
},
|
|
46
|
+
"dev": {
|
|
47
|
+
"dependsOn": ["^build"],
|
|
48
|
+
"cache": false,
|
|
49
|
+
"persistent": true
|
|
50
|
+
},
|
|
51
|
+
"test": {
|
|
52
|
+
"dependsOn": ["build"],
|
|
53
|
+
"outputs": [],
|
|
54
|
+
"inputs": ["src/**/*.ts", "src/**/*.test.ts"]
|
|
55
|
+
},
|
|
56
|
+
"typecheck": {
|
|
57
|
+
"dependsOn": ["^build"],
|
|
58
|
+
"outputs": []
|
|
59
|
+
},
|
|
60
|
+
"lint": {
|
|
61
|
+
"outputs": []
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
Key points:
|
|
68
|
+
- \`build\` outputs include \`.typokit/\` (generated code directory)
|
|
69
|
+
- \`dev\` is non-cacheable and persistent (watch mode)
|
|
70
|
+
- \`test\` depends on \`build\` (needs generated code)
|
|
71
|
+
|
|
72
|
+
## 3. Add scripts to your TypoKit package
|
|
73
|
+
|
|
74
|
+
In your server package's \`package.json\`:
|
|
75
|
+
|
|
76
|
+
\`\`\`json
|
|
77
|
+
{
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "typokit build",
|
|
80
|
+
"dev": "typokit dev",
|
|
81
|
+
"test": "typokit test"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
\`\`\`
|
|
85
|
+
|
|
86
|
+
## 4. Run with Turborepo
|
|
87
|
+
|
|
88
|
+
\`\`\`bash
|
|
89
|
+
# Build all packages (TypoKit packages built in dependency order)
|
|
90
|
+
turbo build
|
|
91
|
+
|
|
92
|
+
# Start dev mode for all packages
|
|
93
|
+
turbo dev
|
|
94
|
+
|
|
95
|
+
# Run tests
|
|
96
|
+
turbo test
|
|
97
|
+
\`\`\`
|
|
98
|
+
|
|
99
|
+
## Programmatic Usage
|
|
100
|
+
|
|
101
|
+
You can also use the helper scripts programmatically:
|
|
102
|
+
|
|
103
|
+
\`\`\`typescript
|
|
104
|
+
import { runBuild, runDev, runTest } from "@typokit/turbo";
|
|
105
|
+
|
|
106
|
+
// In a custom build script
|
|
107
|
+
await runBuild({ cwd: "./packages/server" });
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
Or generate a turbo.json configuration:
|
|
111
|
+
|
|
112
|
+
\`\`\`typescript
|
|
113
|
+
import { createTurboConfig, getTurboJsonTemplate } from "@typokit/turbo";
|
|
114
|
+
|
|
115
|
+
// Get a config object
|
|
116
|
+
const config = createTurboConfig({
|
|
117
|
+
tasks: { "build": { env: ["DATABASE_URL"] } }
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Or get a ready-to-write JSON string
|
|
121
|
+
const json = getTurboJsonTemplate();
|
|
122
|
+
\`\`\`
|
|
123
|
+
`;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAmD;IAEnD,MAAM,MAAM,GAAgB,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4GR,CAAC;AACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typokit/turbo",
|
|
3
|
+
"exports": {
|
|
4
|
+
".": {
|
|
5
|
+
"import": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"version": "0.1.4",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/KyleBastien/typokit",
|
|
20
|
+
"directory": "packages/turbo"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "rstest run --passWithNoTests"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/env.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// @typokit/turbo — Unit tests
|
|
2
|
+
import { describe, it, expect } from "@rstest/core";
|
|
3
|
+
import { createTurboConfig, defaultPipeline } from "./pipeline.js";
|
|
4
|
+
import type { TurboConfig, TurboTaskConfig } from "./pipeline.js";
|
|
5
|
+
import { getTurboJsonTemplate, getSetupInstructions } from "./setup.js";
|
|
6
|
+
|
|
7
|
+
// ---------- defaultPipeline ----------
|
|
8
|
+
|
|
9
|
+
describe("defaultPipeline", () => {
|
|
10
|
+
it("defines build task with correct outputs", () => {
|
|
11
|
+
const build = defaultPipeline["build"] as TurboTaskConfig;
|
|
12
|
+
expect(build.dependsOn).toEqual(["^build"]);
|
|
13
|
+
expect(build.outputs).toContain("dist/**");
|
|
14
|
+
expect(build.outputs).toContain(".typokit/**");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("defines dev task as non-cacheable and persistent", () => {
|
|
18
|
+
const dev = defaultPipeline["dev"] as TurboTaskConfig;
|
|
19
|
+
expect(dev.cache).toBe(false);
|
|
20
|
+
expect(dev.persistent).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("defines test task depending on build", () => {
|
|
24
|
+
const test = defaultPipeline["test"] as TurboTaskConfig;
|
|
25
|
+
expect(test.dependsOn).toEqual(["build"]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("includes typecheck and lint tasks", () => {
|
|
29
|
+
expect(defaultPipeline["typecheck"]).toBeDefined();
|
|
30
|
+
expect(defaultPipeline["lint"]).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// ---------- createTurboConfig ----------
|
|
35
|
+
|
|
36
|
+
describe("createTurboConfig", () => {
|
|
37
|
+
it("returns config with schema and default tasks", () => {
|
|
38
|
+
const config: TurboConfig = createTurboConfig();
|
|
39
|
+
expect(config.$schema).toBe("https://turbo.build/schema.json");
|
|
40
|
+
expect(config.tasks["build"]).toBeDefined();
|
|
41
|
+
expect(config.tasks["dev"]).toBeDefined();
|
|
42
|
+
expect(config.tasks["test"]).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("merges task overrides", () => {
|
|
46
|
+
const config = createTurboConfig({
|
|
47
|
+
tasks: { build: { env: ["DATABASE_URL"] } },
|
|
48
|
+
});
|
|
49
|
+
const build = config.tasks["build"] as TurboTaskConfig;
|
|
50
|
+
expect(build.env).toEqual(["DATABASE_URL"]);
|
|
51
|
+
// Original fields preserved
|
|
52
|
+
expect(build.dependsOn).toEqual(["^build"]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("adds new tasks via overrides", () => {
|
|
56
|
+
const config = createTurboConfig({
|
|
57
|
+
tasks: { deploy: { dependsOn: ["build", "test"] } },
|
|
58
|
+
});
|
|
59
|
+
expect(config.tasks["deploy"]).toBeDefined();
|
|
60
|
+
expect((config.tasks["deploy"] as TurboTaskConfig).dependsOn).toEqual([
|
|
61
|
+
"build",
|
|
62
|
+
"test",
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("includes globalDependencies when provided", () => {
|
|
67
|
+
const config = createTurboConfig({
|
|
68
|
+
globalDependencies: [".env"],
|
|
69
|
+
});
|
|
70
|
+
expect(config.globalDependencies).toEqual([".env"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("includes globalEnv when provided", () => {
|
|
74
|
+
const config = createTurboConfig({
|
|
75
|
+
globalEnv: ["NODE_ENV"],
|
|
76
|
+
});
|
|
77
|
+
expect(config.globalEnv).toEqual(["NODE_ENV"]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("omits globalDependencies/globalEnv when not provided", () => {
|
|
81
|
+
const config = createTurboConfig();
|
|
82
|
+
expect(config.globalDependencies).toBeUndefined();
|
|
83
|
+
expect(config.globalEnv).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ---------- getTurboJsonTemplate ----------
|
|
88
|
+
|
|
89
|
+
describe("getTurboJsonTemplate", () => {
|
|
90
|
+
it("returns valid JSON string", () => {
|
|
91
|
+
const template = getTurboJsonTemplate();
|
|
92
|
+
const parsed = JSON.parse(template) as TurboConfig;
|
|
93
|
+
expect(parsed.$schema).toBe("https://turbo.build/schema.json");
|
|
94
|
+
expect(parsed.tasks).toBeDefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("ends with newline", () => {
|
|
98
|
+
const template = getTurboJsonTemplate();
|
|
99
|
+
expect(template.endsWith("\n")).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("accepts overrides", () => {
|
|
103
|
+
const template = getTurboJsonTemplate({
|
|
104
|
+
tasks: { custom: { cache: false } },
|
|
105
|
+
});
|
|
106
|
+
const parsed = JSON.parse(template) as TurboConfig;
|
|
107
|
+
expect(parsed.tasks["custom"]).toBeDefined();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ---------- getSetupInstructions ----------
|
|
112
|
+
|
|
113
|
+
describe("getSetupInstructions", () => {
|
|
114
|
+
it("returns non-empty string", () => {
|
|
115
|
+
const instructions = getSetupInstructions();
|
|
116
|
+
expect(instructions.length).toBeGreaterThan(0);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("includes key setup steps", () => {
|
|
120
|
+
const instructions = getSetupInstructions();
|
|
121
|
+
expect(instructions).toContain("turbo.json");
|
|
122
|
+
expect(instructions).toContain("typokit build");
|
|
123
|
+
expect(instructions).toContain("@typokit/turbo");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("mentions .typokit/ output directory", () => {
|
|
127
|
+
const instructions = getSetupInstructions();
|
|
128
|
+
expect(instructions).toContain(".typokit/");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// ---------- Helper script exports ----------
|
|
133
|
+
|
|
134
|
+
describe("@typokit/turbo script exports", () => {
|
|
135
|
+
it("exports runBuild function", async () => {
|
|
136
|
+
const mod = await import("./scripts.js");
|
|
137
|
+
expect(typeof mod.runBuild).toBe("function");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("exports runDev function", async () => {
|
|
141
|
+
const mod = await import("./scripts.js");
|
|
142
|
+
expect(typeof mod.runDev).toBe("function");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("exports runTest function", async () => {
|
|
146
|
+
const mod = await import("./scripts.js");
|
|
147
|
+
expect(typeof mod.runTest).toBe("function");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("exports runTypokitTask function", async () => {
|
|
151
|
+
const mod = await import("./scripts.js");
|
|
152
|
+
expect(typeof mod.runTypokitTask).toBe("function");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ---------- Main index exports ----------
|
|
157
|
+
|
|
158
|
+
describe("@typokit/turbo exports", () => {
|
|
159
|
+
it("exports pipeline configuration", async () => {
|
|
160
|
+
const mod = await import("./index.js");
|
|
161
|
+
expect(typeof mod.createTurboConfig).toBe("function");
|
|
162
|
+
expect(mod.defaultPipeline).toBeDefined();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("exports helper scripts", async () => {
|
|
166
|
+
const mod = await import("./index.js");
|
|
167
|
+
expect(typeof mod.runBuild).toBe("function");
|
|
168
|
+
expect(typeof mod.runDev).toBe("function");
|
|
169
|
+
expect(typeof mod.runTest).toBe("function");
|
|
170
|
+
expect(typeof mod.runTypokitTask).toBe("function");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("exports setup utilities", async () => {
|
|
174
|
+
const mod = await import("./index.js");
|
|
175
|
+
expect(typeof mod.getTurboJsonTemplate).toBe("function");
|
|
176
|
+
expect(typeof mod.getSetupInstructions).toBe("function");
|
|
177
|
+
});
|
|
178
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @typokit/turbo — Turborepo Integration Helpers
|
|
2
|
+
|
|
3
|
+
// Pipeline configuration
|
|
4
|
+
export { createTurboConfig, defaultPipeline } from "./pipeline.js";
|
|
5
|
+
export type {
|
|
6
|
+
TurboPipeline,
|
|
7
|
+
TurboTaskConfig,
|
|
8
|
+
TurboConfig,
|
|
9
|
+
} from "./pipeline.js";
|
|
10
|
+
|
|
11
|
+
// Helper scripts
|
|
12
|
+
export { runBuild, runDev, runTest, runTypokitTask } from "./scripts.js";
|
|
13
|
+
export type { TaskOptions } from "./scripts.js";
|
|
14
|
+
|
|
15
|
+
// Setup utilities
|
|
16
|
+
export { getSetupInstructions, getTurboJsonTemplate } from "./setup.js";
|
package/src/pipeline.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @typokit/turbo — Turborepo pipeline configuration helpers
|
|
2
|
+
|
|
3
|
+
/** Configuration for a single Turborepo task */
|
|
4
|
+
export interface TurboTaskConfig {
|
|
5
|
+
dependsOn?: string[];
|
|
6
|
+
outputs?: string[];
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
persistent?: boolean;
|
|
9
|
+
env?: string[];
|
|
10
|
+
inputs?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Map of task names to their configuration */
|
|
14
|
+
export interface TurboPipeline {
|
|
15
|
+
[taskName: string]: TurboTaskConfig;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Root turbo.json structure */
|
|
19
|
+
export interface TurboConfig {
|
|
20
|
+
$schema?: string;
|
|
21
|
+
tasks: TurboPipeline;
|
|
22
|
+
globalDependencies?: string[];
|
|
23
|
+
globalEnv?: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Default pipeline tasks for a TypoKit project */
|
|
27
|
+
export const defaultPipeline: TurboPipeline = {
|
|
28
|
+
build: {
|
|
29
|
+
dependsOn: ["^build"],
|
|
30
|
+
outputs: ["dist/**", ".typokit/**"],
|
|
31
|
+
inputs: ["src/**/*.ts", "tsconfig.json"],
|
|
32
|
+
},
|
|
33
|
+
dev: {
|
|
34
|
+
dependsOn: ["^build"],
|
|
35
|
+
cache: false,
|
|
36
|
+
persistent: true,
|
|
37
|
+
},
|
|
38
|
+
test: {
|
|
39
|
+
dependsOn: ["build"],
|
|
40
|
+
outputs: [],
|
|
41
|
+
inputs: ["src/**/*.ts", "src/**/*.test.ts"],
|
|
42
|
+
},
|
|
43
|
+
typecheck: {
|
|
44
|
+
dependsOn: ["^build"],
|
|
45
|
+
outputs: [],
|
|
46
|
+
},
|
|
47
|
+
lint: {
|
|
48
|
+
outputs: [],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a turbo.json configuration object with TypoKit defaults.
|
|
54
|
+
* Merges user overrides on top of the default pipeline.
|
|
55
|
+
*/
|
|
56
|
+
export function createTurboConfig(overrides?: {
|
|
57
|
+
tasks?: TurboPipeline;
|
|
58
|
+
globalDependencies?: string[];
|
|
59
|
+
globalEnv?: string[];
|
|
60
|
+
}): TurboConfig {
|
|
61
|
+
const tasks: TurboPipeline = { ...defaultPipeline };
|
|
62
|
+
|
|
63
|
+
if (overrides?.tasks) {
|
|
64
|
+
for (const [key, value] of Object.entries(overrides.tasks)) {
|
|
65
|
+
tasks[key] = { ...tasks[key], ...value };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const config: TurboConfig = {
|
|
70
|
+
$schema: "https://turbo.build/schema.json",
|
|
71
|
+
tasks,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (overrides?.globalDependencies) {
|
|
75
|
+
config.globalDependencies = overrides.globalDependencies;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (overrides?.globalEnv) {
|
|
79
|
+
config.globalEnv = overrides.globalEnv;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return config;
|
|
83
|
+
}
|
package/src/scripts.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @typokit/turbo — Helper scripts wrapping typokit CLI for Turborepo
|
|
2
|
+
|
|
3
|
+
/** Options for running a TypoKit task */
|
|
4
|
+
export interface TaskOptions {
|
|
5
|
+
/** Working directory (defaults to process.cwd()) */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Additional CLI arguments */
|
|
8
|
+
args?: string[];
|
|
9
|
+
/** Environment variables to set */
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Get process.env safely (no @types/node) */
|
|
14
|
+
function getProcessEnv(): Record<string, string | undefined> {
|
|
15
|
+
const g = globalThis as Record<string, unknown>;
|
|
16
|
+
const proc = g["process"] as
|
|
17
|
+
| { env: Record<string, string | undefined> }
|
|
18
|
+
| undefined;
|
|
19
|
+
return proc?.env ?? {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Get process.cwd() safely */
|
|
23
|
+
function getProcessCwd(): string {
|
|
24
|
+
const g = globalThis as Record<string, unknown>;
|
|
25
|
+
const proc = g["process"] as { cwd: () => string } | undefined;
|
|
26
|
+
return proc?.cwd() ?? ".";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Run a typokit CLI command as a child process.
|
|
31
|
+
* Designed for use in Turborepo task scripts.
|
|
32
|
+
*/
|
|
33
|
+
export async function runTypokitTask(
|
|
34
|
+
command: string,
|
|
35
|
+
options?: TaskOptions,
|
|
36
|
+
): Promise<{ success: boolean }> {
|
|
37
|
+
const cp = (await import(/* @vite-ignore */ "child_process")) as {
|
|
38
|
+
execSync: (cmd: string, opts: Record<string, unknown>) => unknown;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const cwd = options?.cwd ?? getProcessCwd();
|
|
42
|
+
const extraArgs = options?.args?.join(" ") ?? "";
|
|
43
|
+
const fullCommand = `npx typokit ${command}${extraArgs ? " " + extraArgs : ""}`;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
cp.execSync(fullCommand, {
|
|
47
|
+
cwd,
|
|
48
|
+
stdio: "inherit",
|
|
49
|
+
env: {
|
|
50
|
+
...getProcessEnv(),
|
|
51
|
+
FORCE_COLOR: "true",
|
|
52
|
+
...options?.env,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return { success: true };
|
|
56
|
+
} catch {
|
|
57
|
+
return { success: false };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Run `typokit build` — suitable as a Turborepo build task */
|
|
62
|
+
export async function runBuild(
|
|
63
|
+
options?: TaskOptions,
|
|
64
|
+
): Promise<{ success: boolean }> {
|
|
65
|
+
return runTypokitTask("build", options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Run `typokit dev` — suitable as a Turborepo dev task */
|
|
69
|
+
export async function runDev(
|
|
70
|
+
options?: TaskOptions,
|
|
71
|
+
): Promise<{ success: boolean }> {
|
|
72
|
+
return runTypokitTask("dev", options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Run `typokit test` — suitable as a Turborepo test task */
|
|
76
|
+
export async function runTest(
|
|
77
|
+
options?: TaskOptions,
|
|
78
|
+
): Promise<{ success: boolean }> {
|
|
79
|
+
return runTypokitTask("test", options);
|
|
80
|
+
}
|
package/src/setup.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// @typokit/turbo — Setup instructions and template generation
|
|
2
|
+
|
|
3
|
+
import { createTurboConfig } from "./pipeline.js";
|
|
4
|
+
import type { TurboConfig } from "./pipeline.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a turbo.json template string ready to write to disk.
|
|
8
|
+
* Generates a complete turbo.json with TypoKit-optimized pipeline tasks.
|
|
9
|
+
*/
|
|
10
|
+
export function getTurboJsonTemplate(
|
|
11
|
+
overrides?: Parameters<typeof createTurboConfig>[0],
|
|
12
|
+
): string {
|
|
13
|
+
const config: TurboConfig = createTurboConfig(overrides);
|
|
14
|
+
return JSON.stringify(config, null, 2) + "\n";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns setup instructions for integrating TypoKit into a Turborepo workspace.
|
|
19
|
+
*/
|
|
20
|
+
export function getSetupInstructions(): string {
|
|
21
|
+
return `# Setting up TypoKit in a Turborepo workspace
|
|
22
|
+
|
|
23
|
+
## 1. Install dependencies
|
|
24
|
+
|
|
25
|
+
In your Turborepo root:
|
|
26
|
+
|
|
27
|
+
\`\`\`bash
|
|
28
|
+
npm install @typokit/turbo --save-dev
|
|
29
|
+
# or
|
|
30
|
+
pnpm add @typokit/turbo --save-dev -w
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
In your TypoKit server package:
|
|
34
|
+
|
|
35
|
+
\`\`\`bash
|
|
36
|
+
npm install @typokit/core @typokit/types
|
|
37
|
+
\`\`\`
|
|
38
|
+
|
|
39
|
+
## 2. Configure turbo.json
|
|
40
|
+
|
|
41
|
+
Add TypoKit-aware pipeline tasks to your \`turbo.json\`:
|
|
42
|
+
|
|
43
|
+
\`\`\`json
|
|
44
|
+
{
|
|
45
|
+
"$schema": "https://turbo.build/schema.json",
|
|
46
|
+
"tasks": {
|
|
47
|
+
"build": {
|
|
48
|
+
"dependsOn": ["^build"],
|
|
49
|
+
"outputs": ["dist/**", ".typokit/**"],
|
|
50
|
+
"inputs": ["src/**/*.ts", "tsconfig.json"]
|
|
51
|
+
},
|
|
52
|
+
"dev": {
|
|
53
|
+
"dependsOn": ["^build"],
|
|
54
|
+
"cache": false,
|
|
55
|
+
"persistent": true
|
|
56
|
+
},
|
|
57
|
+
"test": {
|
|
58
|
+
"dependsOn": ["build"],
|
|
59
|
+
"outputs": [],
|
|
60
|
+
"inputs": ["src/**/*.ts", "src/**/*.test.ts"]
|
|
61
|
+
},
|
|
62
|
+
"typecheck": {
|
|
63
|
+
"dependsOn": ["^build"],
|
|
64
|
+
"outputs": []
|
|
65
|
+
},
|
|
66
|
+
"lint": {
|
|
67
|
+
"outputs": []
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
\`\`\`
|
|
72
|
+
|
|
73
|
+
Key points:
|
|
74
|
+
- \`build\` outputs include \`.typokit/\` (generated code directory)
|
|
75
|
+
- \`dev\` is non-cacheable and persistent (watch mode)
|
|
76
|
+
- \`test\` depends on \`build\` (needs generated code)
|
|
77
|
+
|
|
78
|
+
## 3. Add scripts to your TypoKit package
|
|
79
|
+
|
|
80
|
+
In your server package's \`package.json\`:
|
|
81
|
+
|
|
82
|
+
\`\`\`json
|
|
83
|
+
{
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "typokit build",
|
|
86
|
+
"dev": "typokit dev",
|
|
87
|
+
"test": "typokit test"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
\`\`\`
|
|
91
|
+
|
|
92
|
+
## 4. Run with Turborepo
|
|
93
|
+
|
|
94
|
+
\`\`\`bash
|
|
95
|
+
# Build all packages (TypoKit packages built in dependency order)
|
|
96
|
+
turbo build
|
|
97
|
+
|
|
98
|
+
# Start dev mode for all packages
|
|
99
|
+
turbo dev
|
|
100
|
+
|
|
101
|
+
# Run tests
|
|
102
|
+
turbo test
|
|
103
|
+
\`\`\`
|
|
104
|
+
|
|
105
|
+
## Programmatic Usage
|
|
106
|
+
|
|
107
|
+
You can also use the helper scripts programmatically:
|
|
108
|
+
|
|
109
|
+
\`\`\`typescript
|
|
110
|
+
import { runBuild, runDev, runTest } from "@typokit/turbo";
|
|
111
|
+
|
|
112
|
+
// In a custom build script
|
|
113
|
+
await runBuild({ cwd: "./packages/server" });
|
|
114
|
+
\`\`\`
|
|
115
|
+
|
|
116
|
+
Or generate a turbo.json configuration:
|
|
117
|
+
|
|
118
|
+
\`\`\`typescript
|
|
119
|
+
import { createTurboConfig, getTurboJsonTemplate } from "@typokit/turbo";
|
|
120
|
+
|
|
121
|
+
// Get a config object
|
|
122
|
+
const config = createTurboConfig({
|
|
123
|
+
tasks: { "build": { env: ["DATABASE_URL"] } }
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Or get a ready-to-write JSON string
|
|
127
|
+
const json = getTurboJsonTemplate();
|
|
128
|
+
\`\`\`
|
|
129
|
+
`;
|
|
130
|
+
}
|