@powerhousedao/ph-clint-cli 0.1.0-dev.95 → 0.1.0-dev.96
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/package.json +21 -21
- package/dist/codegen/actions.d.ts +0 -46
- package/dist/codegen/actions.js +0 -424
- package/dist/codegen/builders/agent-base-md.d.ts +0 -5
- package/dist/codegen/builders/agent-base-md.js +0 -18
- package/dist/codegen/builders/agent-ts.d.ts +0 -9
- package/dist/codegen/builders/agent-ts.js +0 -124
- package/dist/codegen/builders/app-index-ts.d.ts +0 -11
- package/dist/codegen/builders/app-index-ts.js +0 -43
- package/dist/codegen/builders/build-skills-ts.d.ts +0 -4
- package/dist/codegen/builders/build-skills-ts.js +0 -37
- package/dist/codegen/builders/cli-package-json.d.ts +0 -8
- package/dist/codegen/builders/cli-package-json.js +0 -128
- package/dist/codegen/builders/cli-ts.d.ts +0 -7
- package/dist/codegen/builders/cli-ts.js +0 -170
- package/dist/codegen/builders/config-ts.d.ts +0 -8
- package/dist/codegen/builders/config-ts.js +0 -11
- package/dist/codegen/builders/demo-agent-ts.d.ts +0 -8
- package/dist/codegen/builders/demo-agent-ts.js +0 -50
- package/dist/codegen/builders/eslint-config-js.d.ts +0 -4
- package/dist/codegen/builders/eslint-config-js.js +0 -16
- package/dist/codegen/builders/framework-gen-ts.d.ts +0 -25
- package/dist/codegen/builders/framework-gen-ts.js +0 -114
- package/dist/codegen/builders/framework-ts.d.ts +0 -21
- package/dist/codegen/builders/framework-ts.js +0 -100
- package/dist/codegen/builders/gitignore.d.ts +0 -4
- package/dist/codegen/builders/gitignore.js +0 -18
- package/dist/codegen/builders/index.d.ts +0 -52
- package/dist/codegen/builders/index.js +0 -85
- package/dist/codegen/builders/jest-config-js.d.ts +0 -4
- package/dist/codegen/builders/jest-config-js.js +0 -19
- package/dist/codegen/builders/main-ts.d.ts +0 -5
- package/dist/codegen/builders/main-ts.js +0 -13
- package/dist/codegen/builders/manifest-json.d.ts +0 -6
- package/dist/codegen/builders/manifest-json.js +0 -31
- package/dist/codegen/builders/mastra-index-ts.d.ts +0 -11
- package/dist/codegen/builders/mastra-index-ts.js +0 -72
- package/dist/codegen/builders/publish-config-js.d.ts +0 -8
- package/dist/codegen/builders/publish-config-js.js +0 -33
- package/dist/codegen/builders/readme-md.d.ts +0 -5
- package/dist/codegen/builders/readme-md.js +0 -45
- package/dist/codegen/builders/root-package-json.d.ts +0 -10
- package/dist/codegen/builders/root-package-json.js +0 -39
- package/dist/codegen/builders/smoke-test-ts.d.ts +0 -2
- package/dist/codegen/builders/smoke-test-ts.js +0 -15
- package/dist/codegen/builders/tsconfig-json.d.ts +0 -4
- package/dist/codegen/builders/tsconfig-json.js +0 -22
- package/dist/codegen/exec.d.ts +0 -2
- package/dist/codegen/exec.js +0 -14
- package/dist/codegen/generated.d.ts +0 -17
- package/dist/codegen/generated.js +0 -49
- package/dist/codegen/hashes.d.ts +0 -6
- package/dist/codegen/hashes.js +0 -60
- package/dist/codegen/markers.d.ts +0 -36
- package/dist/codegen/markers.js +0 -86
- package/dist/codegen/migrate/flat-to-split.d.ts +0 -15
- package/dist/codegen/migrate/flat-to-split.js +0 -119
- package/dist/codegen/scaffold.d.ts +0 -72
- package/dist/codegen/scaffold.js +0 -150
- package/dist/codegen/write.d.ts +0 -6
- package/dist/codegen/write.js +0 -32
- package/dist/skills/sync.d.ts +0 -40
- package/dist/skills/sync.js +0 -119
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds the project README for a freshly-generated ph-clint project.
|
|
3
|
-
*/
|
|
4
|
-
import { getPackageName, phAtLeast, } from '../../spec/types.js';
|
|
5
|
-
export function buildReadme(spec) {
|
|
6
|
-
const { mastra, routine, powerhouse } = spec.features;
|
|
7
|
-
const ph = powerhouse;
|
|
8
|
-
const title = getPackageName(spec);
|
|
9
|
-
const lines = [];
|
|
10
|
-
lines.push(`# ${title}`);
|
|
11
|
-
lines.push('');
|
|
12
|
-
lines.push(spec.description || 'A ph-clint-based project.');
|
|
13
|
-
lines.push('');
|
|
14
|
-
lines.push('## Getting started');
|
|
15
|
-
lines.push('');
|
|
16
|
-
lines.push('```sh');
|
|
17
|
-
lines.push('pnpm install');
|
|
18
|
-
lines.push('pnpm dev');
|
|
19
|
-
lines.push('```');
|
|
20
|
-
lines.push('');
|
|
21
|
-
lines.push('## Enabled features');
|
|
22
|
-
lines.push('');
|
|
23
|
-
lines.push(`- **Powerhouse**: ${ph !== 'Disabled' ? `on (${ph})` : 'off'}`);
|
|
24
|
-
if (phAtLeast(ph, 'Reactor')) {
|
|
25
|
-
lines.push(` - Switchboard: ${phAtLeast(ph, 'Switchboard') ? 'on' : 'off'}`);
|
|
26
|
-
lines.push(` - Connect: ${phAtLeast(ph, 'Connect') ? 'on' : 'off'}`);
|
|
27
|
-
}
|
|
28
|
-
lines.push(`- **Mastra agent**: ${mastra.enabled ? 'on' : 'off'}`);
|
|
29
|
-
lines.push(`- **Routine loop**: ${routine.enabled ? 'on' : 'off'}`);
|
|
30
|
-
lines.push('');
|
|
31
|
-
lines.push('## Regenerate');
|
|
32
|
-
lines.push('');
|
|
33
|
-
lines.push('Toggle features or update metadata in `.ph/ph-clint-cli/project-spec.json`,');
|
|
34
|
-
lines.push('then re-run `ph-clint clint-project-regen` to regenerate.');
|
|
35
|
-
lines.push('');
|
|
36
|
-
if (phAtLeast(ph, 'Reactor')) {
|
|
37
|
-
lines.push('## Split layout');
|
|
38
|
-
lines.push('');
|
|
39
|
-
lines.push(`This project is split into \`${spec.name}-cli/\` (the CLI) and \`${spec.name}-app/\` (the Powerhouse reactor package).`);
|
|
40
|
-
lines.push('');
|
|
41
|
-
lines.push(`Run \`ph init\` inside \`${spec.name}-app/\` to scaffold the reactor package layout (document-models, editors, manifest, etc.).`);
|
|
42
|
-
lines.push('');
|
|
43
|
-
}
|
|
44
|
-
return lines.join('\n');
|
|
45
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds the *root* `package.json` for split-layout projects (Powerhouse
|
|
3
|
-
* enabled). A plain passthrough — deliberately no pnpm workspaces because
|
|
4
|
-
* they interfere with `{name}-app`'s own `pnpm build`.
|
|
5
|
-
*
|
|
6
|
-
* Uses `pnpm --prefix <dir>` for all orchestration scripts — no cwd mutation.
|
|
7
|
-
* Build order: app first, then cli (cli depends on app via `file:` dep).
|
|
8
|
-
*/
|
|
9
|
-
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
10
|
-
export declare function buildRootPackageJson(spec: ClintProjectSpec): string;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds the *root* `package.json` for split-layout projects (Powerhouse
|
|
3
|
-
* enabled). A plain passthrough — deliberately no pnpm workspaces because
|
|
4
|
-
* they interfere with `{name}-app`'s own `pnpm build`.
|
|
5
|
-
*
|
|
6
|
-
* Uses `pnpm --prefix <dir>` for all orchestration scripts — no cwd mutation.
|
|
7
|
-
* Build order: app first, then cli (cli depends on app via `file:` dep).
|
|
8
|
-
*/
|
|
9
|
-
import { getAppFolderName, getBinName, getCliFolderName, phAtLeast, } from '../../spec/types.js';
|
|
10
|
-
export function buildRootPackageJson(spec) {
|
|
11
|
-
const cli = getCliFolderName(spec);
|
|
12
|
-
const app = getAppFolderName(spec);
|
|
13
|
-
const prefix = (dir, cmd) => `pnpm --prefix ${dir} ${cmd}`;
|
|
14
|
-
const both = (cmd) => `${prefix(app, cmd)} && ${prefix(cli, cmd)}`;
|
|
15
|
-
const connectEnabled = phAtLeast(spec.features.powerhouse, 'Connect');
|
|
16
|
-
const buildScript = connectEnabled
|
|
17
|
-
? `${prefix(app, 'build')} && ${prefix(app, 'connect build --outDir dist/connect')} && ${prefix(cli, 'build')}`
|
|
18
|
-
: both('build');
|
|
19
|
-
const scripts = {
|
|
20
|
-
install: both('install'),
|
|
21
|
-
build: buildScript,
|
|
22
|
-
test: both('test'),
|
|
23
|
-
dev: prefix(cli, 'dev'),
|
|
24
|
-
start: prefix(cli, 'start'),
|
|
25
|
-
lint: both('lint'),
|
|
26
|
-
'publish:dev': `${prefix(cli, 'exec ph-publish')} dev -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
27
|
-
'publish:staging': `${prefix(cli, 'exec ph-publish')} staging -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
28
|
-
'publish:production': `${prefix(cli, 'exec ph-publish')} production -c ../publish.config.js${connectEnabled ? ' --verify-connect' : ''}`,
|
|
29
|
-
};
|
|
30
|
-
const pkg = {
|
|
31
|
-
name: spec.scope ? `${spec.scope}/${getBinName(spec)}` : getBinName(spec),
|
|
32
|
-
version: spec.version,
|
|
33
|
-
private: true,
|
|
34
|
-
type: 'module',
|
|
35
|
-
...(spec.description ? { description: spec.description } : {}),
|
|
36
|
-
scripts,
|
|
37
|
-
};
|
|
38
|
-
return JSON.stringify(pkg, null, 2) + '\n';
|
|
39
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getBinName } from '../../spec/types.js';
|
|
2
|
-
export function buildSmokeTestTs(spec) {
|
|
3
|
-
const bin = getBinName(spec);
|
|
4
|
-
return [
|
|
5
|
-
`import { describe, it, expect } from '@jest/globals';`,
|
|
6
|
-
``,
|
|
7
|
-
`describe('${bin}', () => {`,
|
|
8
|
-
` it('loads without error', async () => {`,
|
|
9
|
-
` const { cli } = await import('../src/cli.js');`,
|
|
10
|
-
` expect(cli).toBeDefined();`,
|
|
11
|
-
` });`,
|
|
12
|
-
`});`,
|
|
13
|
-
``,
|
|
14
|
-
].join('\n');
|
|
15
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds `tsconfig.json` for the CLI.
|
|
3
|
-
*/
|
|
4
|
-
export function buildTsconfigJson() {
|
|
5
|
-
const tsconfig = {
|
|
6
|
-
compilerOptions: {
|
|
7
|
-
target: 'ES2022',
|
|
8
|
-
module: 'Node16',
|
|
9
|
-
moduleResolution: 'Node16',
|
|
10
|
-
outDir: 'dist',
|
|
11
|
-
rootDir: 'src',
|
|
12
|
-
strict: true,
|
|
13
|
-
isolatedModules: true,
|
|
14
|
-
esModuleInterop: true,
|
|
15
|
-
skipLibCheck: true,
|
|
16
|
-
declaration: true,
|
|
17
|
-
types: ['node'],
|
|
18
|
-
},
|
|
19
|
-
include: ['src'],
|
|
20
|
-
};
|
|
21
|
-
return JSON.stringify(tsconfig, null, 2) + '\n';
|
|
22
|
-
}
|
package/dist/codegen/exec.d.ts
DELETED
package/dist/codegen/exec.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small helpers for invoking external commands during code generation.
|
|
3
|
-
*/
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
5
|
-
/** Returns true if `command` is on PATH. */
|
|
6
|
-
export async function hasCommandOnPath(command) {
|
|
7
|
-
return new Promise((resolve) => {
|
|
8
|
-
const child = spawn(process.platform === 'win32' ? 'where' : 'which', [command], {
|
|
9
|
-
stdio: 'ignore',
|
|
10
|
-
});
|
|
11
|
-
child.once('error', () => resolve(false));
|
|
12
|
-
child.once('close', (code) => resolve(code === 0));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ClintProjectSpec } from '../spec/types.js';
|
|
2
|
-
export interface GeneratedState {
|
|
3
|
-
name: string;
|
|
4
|
-
scope: string | undefined;
|
|
5
|
-
cliFolderName: string;
|
|
6
|
-
appFolderName: string;
|
|
7
|
-
/** True once `ph init` has run successfully in the app dir. */
|
|
8
|
-
appInitialized: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function getGeneratedPath(targetDir: string): string;
|
|
11
|
-
export declare function readGeneratedState(targetDir: string): Promise<GeneratedState | null>;
|
|
12
|
-
export declare function writeGeneratedState(targetDir: string, state: GeneratedState): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Derive a `GeneratedState` from a spec. The `appInitialized` flag must be
|
|
15
|
-
* supplied by the caller (it depends on filesystem state, not the spec).
|
|
16
|
-
*/
|
|
17
|
-
export declare function generatedStateFromSpec(spec: ClintProjectSpec, appInitialized: boolean): GeneratedState;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracks the derived state from the last successful code generation.
|
|
3
|
-
*
|
|
4
|
-
* Stored at `{targetDir}/.ph/ph-clint-cli/generated.json`. Used to detect
|
|
5
|
-
* folder renames (name/scope changes) and re-apply patches that depend on
|
|
6
|
-
* the project identity.
|
|
7
|
-
*/
|
|
8
|
-
import fs from 'node:fs/promises';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { getAppFolderName, getCliFolderName, } from '../spec/types.js';
|
|
11
|
-
const GEN_DIR = path.join('.ph', 'ph-clint-cli');
|
|
12
|
-
const GEN_FILE = 'generated.json';
|
|
13
|
-
export function getGeneratedPath(targetDir) {
|
|
14
|
-
return path.join(targetDir, GEN_DIR, GEN_FILE);
|
|
15
|
-
}
|
|
16
|
-
export async function readGeneratedState(targetDir) {
|
|
17
|
-
try {
|
|
18
|
-
const raw = await fs.readFile(getGeneratedPath(targetDir), 'utf8');
|
|
19
|
-
return JSON.parse(raw);
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
if (err &&
|
|
23
|
-
typeof err === 'object' &&
|
|
24
|
-
'code' in err &&
|
|
25
|
-
err.code === 'ENOENT') {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
throw err;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export async function writeGeneratedState(targetDir, state) {
|
|
32
|
-
const file = getGeneratedPath(targetDir);
|
|
33
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
34
|
-
await fs.writeFile(file, JSON.stringify(state, null, 2) + '\n', 'utf8');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Derive a `GeneratedState` from a spec. The `appInitialized` flag must be
|
|
38
|
-
* supplied by the caller (it depends on filesystem state, not the spec).
|
|
39
|
-
*/
|
|
40
|
-
export function generatedStateFromSpec(spec, appInitialized) {
|
|
41
|
-
const split = spec.features.powerhouse !== 'Disabled';
|
|
42
|
-
return {
|
|
43
|
-
name: spec.name,
|
|
44
|
-
scope: spec.scope,
|
|
45
|
-
cliFolderName: split ? getCliFolderName(spec) : '',
|
|
46
|
-
appFolderName: split ? getAppFolderName(spec) : '',
|
|
47
|
-
appInitialized,
|
|
48
|
-
};
|
|
49
|
-
}
|
package/dist/codegen/hashes.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type HashRecord = Record<string, string>;
|
|
2
|
-
export declare function getHashesPath(targetDir: string): string;
|
|
3
|
-
export declare function hashContent(content: string): string;
|
|
4
|
-
export declare function hashFile(filePath: string): Promise<string | null>;
|
|
5
|
-
export declare function readHashes(targetDir: string): Promise<HashRecord>;
|
|
6
|
-
export declare function writeHashes(targetDir: string, hashes: HashRecord): Promise<void>;
|
package/dist/codegen/hashes.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-file content hashes written by the generator so subsequent runs can
|
|
3
|
-
* detect whether a previously-generated file has been hand-edited.
|
|
4
|
-
*
|
|
5
|
-
* Stored at `{targetDir}/.ph/ph-clint-cli/.hashes.json` alongside the project
|
|
6
|
-
* spec. Keys are paths relative to the project root.
|
|
7
|
-
*/
|
|
8
|
-
import crypto from 'node:crypto';
|
|
9
|
-
import fs from 'node:fs/promises';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
const HASHES_DIR = path.join('.ph', 'ph-clint-cli');
|
|
12
|
-
const HASHES_FILE = '.hashes.json';
|
|
13
|
-
export function getHashesPath(targetDir) {
|
|
14
|
-
return path.join(targetDir, HASHES_DIR, HASHES_FILE);
|
|
15
|
-
}
|
|
16
|
-
export function hashContent(content) {
|
|
17
|
-
return crypto.createHash('sha256').update(content, 'utf8').digest('hex');
|
|
18
|
-
}
|
|
19
|
-
function isEnoent(err) {
|
|
20
|
-
return (!!err &&
|
|
21
|
-
typeof err === 'object' &&
|
|
22
|
-
'code' in err &&
|
|
23
|
-
err.code === 'ENOENT');
|
|
24
|
-
}
|
|
25
|
-
export async function hashFile(filePath) {
|
|
26
|
-
try {
|
|
27
|
-
const content = await fs.readFile(filePath, 'utf8');
|
|
28
|
-
return hashContent(content);
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
if (isEnoent(err))
|
|
32
|
-
return null;
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export async function readHashes(targetDir) {
|
|
37
|
-
try {
|
|
38
|
-
const raw = await fs.readFile(getHashesPath(targetDir), 'utf8');
|
|
39
|
-
const parsed = JSON.parse(raw);
|
|
40
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
41
|
-
return parsed;
|
|
42
|
-
}
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
if (isEnoent(err))
|
|
47
|
-
return {};
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export async function writeHashes(targetDir, hashes) {
|
|
52
|
-
const file = getHashesPath(targetDir);
|
|
53
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
54
|
-
// Sort keys for stable output across runs.
|
|
55
|
-
const sorted = {};
|
|
56
|
-
for (const key of Object.keys(hashes).sort()) {
|
|
57
|
-
sorted[key] = hashes[key];
|
|
58
|
-
}
|
|
59
|
-
await fs.writeFile(file, JSON.stringify(sorted, null, 2) + '\n', 'utf8');
|
|
60
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Marker-region parsing for `@clint:begin {name}` / `@clint:end {name}`
|
|
3
|
-
* comment blocks. Used in delta mode to splice freshly-generated regions
|
|
4
|
-
* into an existing, user-edited file while preserving everything outside
|
|
5
|
-
* the markers.
|
|
6
|
-
*
|
|
7
|
-
* The only syntactic requirement is that the markers are on their own lines,
|
|
8
|
-
* as ordinary line comments (`//`). Indentation is preserved for output.
|
|
9
|
-
*/
|
|
10
|
-
export interface MarkerRegion {
|
|
11
|
-
/** Region identifier (the text after `@clint:begin`). */
|
|
12
|
-
name: string;
|
|
13
|
-
/** Lines *between* the begin and end markers (exclusive). */
|
|
14
|
-
body: string[];
|
|
15
|
-
/** Indentation of the begin line — used when rewriting. */
|
|
16
|
-
indent: string;
|
|
17
|
-
/** Line index of the begin marker in the source. */
|
|
18
|
-
beginLine: number;
|
|
19
|
-
/** Line index of the end marker in the source. */
|
|
20
|
-
endLine: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parse every `@clint:begin {name}` … `@clint:end {name}` block in `source`.
|
|
24
|
-
* Throws if markers are mismatched or unclosed.
|
|
25
|
-
*/
|
|
26
|
-
export declare function parseMarkerRegions(source: string): MarkerRegion[];
|
|
27
|
-
/**
|
|
28
|
-
* Replace every region in `target` that also exists in `source` with the
|
|
29
|
-
* `source` region's body. Leaves regions present in `target` but not `source`
|
|
30
|
-
* untouched. Ignores regions in `source` missing from `target`.
|
|
31
|
-
*
|
|
32
|
-
* Returns the rewritten file content.
|
|
33
|
-
*/
|
|
34
|
-
export declare function spliceMarkerRegions(target: string, source: string): string;
|
|
35
|
-
/** Convenience — true if `content` contains at least one `@clint:begin`. */
|
|
36
|
-
export declare function hasMarkers(content: string): boolean;
|
package/dist/codegen/markers.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Marker-region parsing for `@clint:begin {name}` / `@clint:end {name}`
|
|
3
|
-
* comment blocks. Used in delta mode to splice freshly-generated regions
|
|
4
|
-
* into an existing, user-edited file while preserving everything outside
|
|
5
|
-
* the markers.
|
|
6
|
-
*
|
|
7
|
-
* The only syntactic requirement is that the markers are on their own lines,
|
|
8
|
-
* as ordinary line comments (`//`). Indentation is preserved for output.
|
|
9
|
-
*/
|
|
10
|
-
const BEGIN_RE = /^([ \t]*)\/\/\s*@clint:begin\s+(\S+)\s*$/;
|
|
11
|
-
const END_RE = /^([ \t]*)\/\/\s*@clint:end\s+(\S+)\s*$/;
|
|
12
|
-
/**
|
|
13
|
-
* Parse every `@clint:begin {name}` … `@clint:end {name}` block in `source`.
|
|
14
|
-
* Throws if markers are mismatched or unclosed.
|
|
15
|
-
*/
|
|
16
|
-
export function parseMarkerRegions(source) {
|
|
17
|
-
const lines = source.split('\n');
|
|
18
|
-
const regions = [];
|
|
19
|
-
let open = null;
|
|
20
|
-
let bodyStart = 0;
|
|
21
|
-
for (let i = 0; i < lines.length; i++) {
|
|
22
|
-
const line = lines[i];
|
|
23
|
-
const begin = BEGIN_RE.exec(line);
|
|
24
|
-
if (begin) {
|
|
25
|
-
if (open) {
|
|
26
|
-
throw new Error(`nested @clint:begin ${begin[2]} at line ${i + 1} while ${open.name} is still open`);
|
|
27
|
-
}
|
|
28
|
-
open = { name: begin[2], indent: begin[1], beginLine: i };
|
|
29
|
-
bodyStart = i + 1;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const end = END_RE.exec(line);
|
|
33
|
-
if (end) {
|
|
34
|
-
if (!open) {
|
|
35
|
-
throw new Error(`@clint:end ${end[2]} at line ${i + 1} without matching begin`);
|
|
36
|
-
}
|
|
37
|
-
if (open.name !== end[2]) {
|
|
38
|
-
throw new Error(`@clint:end ${end[2]} at line ${i + 1} does not match open @clint:begin ${open.name}`);
|
|
39
|
-
}
|
|
40
|
-
regions.push({
|
|
41
|
-
name: open.name,
|
|
42
|
-
body: lines.slice(bodyStart, i),
|
|
43
|
-
indent: open.indent,
|
|
44
|
-
beginLine: open.beginLine,
|
|
45
|
-
endLine: i,
|
|
46
|
-
});
|
|
47
|
-
open = null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (open) {
|
|
51
|
-
throw new Error(`unterminated @clint:begin ${open.name}`);
|
|
52
|
-
}
|
|
53
|
-
return regions;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Replace every region in `target` that also exists in `source` with the
|
|
57
|
-
* `source` region's body. Leaves regions present in `target` but not `source`
|
|
58
|
-
* untouched. Ignores regions in `source` missing from `target`.
|
|
59
|
-
*
|
|
60
|
-
* Returns the rewritten file content.
|
|
61
|
-
*/
|
|
62
|
-
export function spliceMarkerRegions(target, source) {
|
|
63
|
-
const sourceRegions = parseMarkerRegions(source);
|
|
64
|
-
const sourceByName = new Map();
|
|
65
|
-
for (const r of sourceRegions)
|
|
66
|
-
sourceByName.set(r.name, r);
|
|
67
|
-
const targetRegions = parseMarkerRegions(target);
|
|
68
|
-
if (targetRegions.length === 0)
|
|
69
|
-
return target;
|
|
70
|
-
const lines = target.split('\n');
|
|
71
|
-
// Apply replacements from last to first so line indices stay valid.
|
|
72
|
-
const sorted = [...targetRegions].sort((a, b) => b.beginLine - a.beginLine);
|
|
73
|
-
for (const region of sorted) {
|
|
74
|
-
const fresh = sourceByName.get(region.name);
|
|
75
|
-
if (!fresh)
|
|
76
|
-
continue;
|
|
77
|
-
// Replace the body lines (exclusive of the begin/end marker lines).
|
|
78
|
-
const bodyLen = region.endLine - region.beginLine - 1;
|
|
79
|
-
lines.splice(region.beginLine + 1, bodyLen, ...fresh.body);
|
|
80
|
-
}
|
|
81
|
-
return lines.join('\n');
|
|
82
|
-
}
|
|
83
|
-
/** Convenience — true if `content` contains at least one `@clint:begin`. */
|
|
84
|
-
export function hasMarkers(content) {
|
|
85
|
-
return /^[ \t]*\/\/\s*@clint:begin\s+\S+\s*$/m.test(content);
|
|
86
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ClintProjectSpec } from '../../spec/types.js';
|
|
2
|
-
export interface FlatToSplitOptions {
|
|
3
|
-
targetDir: string;
|
|
4
|
-
spec: ClintProjectSpec;
|
|
5
|
-
/** Bypass the git-dirty guard. */
|
|
6
|
-
force?: boolean;
|
|
7
|
-
/** Optional warn sink for non-fatal messages. */
|
|
8
|
-
onWarn?: (msg: string) => void;
|
|
9
|
-
}
|
|
10
|
-
export interface FlatToSplitResult {
|
|
11
|
-
movedEntries: string[];
|
|
12
|
-
cliDir: string;
|
|
13
|
-
appDir: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function migrateFlatToSplit(options: FlatToSplitOptions): Promise<FlatToSplitResult>;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One-shot migration that runs when a project's spec flips
|
|
3
|
-
* `features.powerhouse.enabled` from `false` to `true`. It reshapes the
|
|
4
|
-
* on-disk layout from flat (everything at the project root) to split
|
|
5
|
-
* (`{name}-cli/` + `{name}-app/` siblings).
|
|
6
|
-
*
|
|
7
|
-
* The follow-up update-mode regeneration then fills in the correct content
|
|
8
|
-
* for each file in its new location — so this migration only moves bytes
|
|
9
|
-
* around. Content updates belong to the generator.
|
|
10
|
-
*
|
|
11
|
-
* `node_modules` is deliberately NOT moved — pnpm `file:` protocol uses
|
|
12
|
-
* symlinks that do not survive a cross-directory rename cleanly. Callers
|
|
13
|
-
* should re-run `pnpm install` after the migration.
|
|
14
|
-
*/
|
|
15
|
-
import fs from 'node:fs/promises';
|
|
16
|
-
import path from 'node:path';
|
|
17
|
-
import { spawn } from 'node:child_process';
|
|
18
|
-
import { getAppFolderName, getCliFolderName, } from '../../spec/types.js';
|
|
19
|
-
import { readHashes, writeHashes } from '../hashes.js';
|
|
20
|
-
/** Entries we never move during a flat → split migration. */
|
|
21
|
-
function isUnmovable(entry, cliFolder, appFolder) {
|
|
22
|
-
if (entry === '.git')
|
|
23
|
-
return true;
|
|
24
|
-
if (entry === '.ph')
|
|
25
|
-
return true;
|
|
26
|
-
if (entry === 'README.md')
|
|
27
|
-
return true;
|
|
28
|
-
if (entry === 'node_modules')
|
|
29
|
-
return true;
|
|
30
|
-
if (entry === cliFolder)
|
|
31
|
-
return true;
|
|
32
|
-
if (entry === appFolder)
|
|
33
|
-
return true;
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Guard: if the target is a git repo with a dirty working tree, refuse to
|
|
38
|
-
* migrate unless `force`. We never want to discard uncommitted edits.
|
|
39
|
-
* Resolves to `null` when the dir is not a git repo.
|
|
40
|
-
*/
|
|
41
|
-
async function gitDirty(dir) {
|
|
42
|
-
return new Promise((resolve) => {
|
|
43
|
-
const child = spawn('git', ['status', '--porcelain'], {
|
|
44
|
-
cwd: dir,
|
|
45
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
46
|
-
});
|
|
47
|
-
let out = '';
|
|
48
|
-
child.stdout?.on('data', (d) => {
|
|
49
|
-
out += d.toString();
|
|
50
|
-
});
|
|
51
|
-
child.once('error', () => resolve(null));
|
|
52
|
-
child.once('close', (code) => {
|
|
53
|
-
if (code !== 0)
|
|
54
|
-
resolve(null);
|
|
55
|
-
else
|
|
56
|
-
resolve(out.trim() || null);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
export async function migrateFlatToSplit(options) {
|
|
61
|
-
const { targetDir, spec } = options;
|
|
62
|
-
const cliFolder = getCliFolderName(spec);
|
|
63
|
-
const appFolder = getAppFolderName(spec);
|
|
64
|
-
const cliDir = path.join(targetDir, cliFolder);
|
|
65
|
-
const appDir = path.join(targetDir, appFolder);
|
|
66
|
-
if (!options.force) {
|
|
67
|
-
const dirty = await gitDirty(targetDir);
|
|
68
|
-
if (dirty) {
|
|
69
|
-
throw new Error(`refusing to migrate flat → split: ${targetDir} has uncommitted changes.\n` +
|
|
70
|
-
'Commit or stash first, or re-run with --force.');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Create the CLI destination. If it already exists and is non-empty we
|
|
74
|
-
// treat that as a malformed state and bail — a previous migration probably
|
|
75
|
-
// got interrupted.
|
|
76
|
-
await fs.mkdir(cliDir, { recursive: true });
|
|
77
|
-
const cliExisting = await fs.readdir(cliDir);
|
|
78
|
-
if (cliExisting.length > 0) {
|
|
79
|
-
throw new Error(`cannot migrate: ${cliDir} already exists and is non-empty. ` +
|
|
80
|
-
'Resolve manually before re-running.');
|
|
81
|
-
}
|
|
82
|
-
const entries = await fs.readdir(targetDir);
|
|
83
|
-
const moved = [];
|
|
84
|
-
for (const entry of entries) {
|
|
85
|
-
if (isUnmovable(entry, cliFolder, appFolder)) {
|
|
86
|
-
if (entry === 'node_modules' && options.onWarn) {
|
|
87
|
-
options.onWarn('skipped node_modules during flat → split migration; re-run `pnpm install`.');
|
|
88
|
-
}
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
const src = path.join(targetDir, entry);
|
|
92
|
-
const dst = path.join(cliDir, entry);
|
|
93
|
-
await fs.rename(src, dst);
|
|
94
|
-
moved.push(entry);
|
|
95
|
-
}
|
|
96
|
-
// Rekey stored hashes so they still line up with the moved paths.
|
|
97
|
-
await rekeyHashes(targetDir, moved, cliFolder);
|
|
98
|
-
// Create the app folder with a placeholder so tooling (git, `ph init`) can
|
|
99
|
-
// find it. The generator and/or `ph init` fills in the real contents.
|
|
100
|
-
await fs.mkdir(appDir, { recursive: true });
|
|
101
|
-
return { movedEntries: moved, cliDir, appDir };
|
|
102
|
-
}
|
|
103
|
-
async function rekeyHashes(targetDir, movedEntries, cliFolder) {
|
|
104
|
-
const before = await readHashes(targetDir);
|
|
105
|
-
if (Object.keys(before).length === 0)
|
|
106
|
-
return;
|
|
107
|
-
const movedSet = new Set(movedEntries);
|
|
108
|
-
const after = {};
|
|
109
|
-
for (const [key, hash] of Object.entries(before)) {
|
|
110
|
-
const top = key.split(/[\\/]/)[0];
|
|
111
|
-
if (movedSet.has(top)) {
|
|
112
|
-
after[path.posix.join(cliFolder, key)] = hash;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
after[key] = hash;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
await writeHashes(targetDir, after);
|
|
119
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { ClintProjectSpec } from '../spec/types.js';
|
|
2
|
-
import type { ProcessRunOptions } from '@powerhousedao/ph-clint';
|
|
3
|
-
/**
|
|
4
|
-
* Signature for the subprocess runner — matches CommandContext.runProcess.
|
|
5
|
-
*/
|
|
6
|
-
type RunProcess = (command: string, opts?: Omit<ProcessRunOptions, 'onOutput'>) => Promise<{
|
|
7
|
-
success: boolean;
|
|
8
|
-
output: string;
|
|
9
|
-
}>;
|
|
10
|
-
export type { RunProcess };
|
|
11
|
-
export interface PhInitOptions {
|
|
12
|
-
/** Absolute path to the project root. */
|
|
13
|
-
targetDir: string;
|
|
14
|
-
/** Absolute path to `{targetDir}/{name}-app` (exists with our placeholder). */
|
|
15
|
-
appDir: string;
|
|
16
|
-
spec: ClintProjectSpec;
|
|
17
|
-
/** Logger; defaults to noop. */
|
|
18
|
-
log?: (msg: string) => void;
|
|
19
|
-
/** Override `ph` binary name (for tests). */
|
|
20
|
-
binName?: string;
|
|
21
|
-
/** Subprocess runner — matches CommandContext.runProcess. */
|
|
22
|
-
runProcess: RunProcess;
|
|
23
|
-
/** Explicit Powerhouse version to pin `ph init` to (tag or semver). */
|
|
24
|
-
phVersion?: string;
|
|
25
|
-
}
|
|
26
|
-
export interface PhInitResult {
|
|
27
|
-
ran: boolean;
|
|
28
|
-
exitCode?: number;
|
|
29
|
-
reason?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Detect the installed `ph` CLI version by parsing `ph --version` output.
|
|
33
|
-
* Returns the version string (e.g. '6.0.0-dev.194') or undefined if
|
|
34
|
-
* detection fails.
|
|
35
|
-
*/
|
|
36
|
-
export declare function getPhVersion(binName: string): string | undefined;
|
|
37
|
-
export declare function runPhInit(options: PhInitOptions): Promise<PhInitResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Patch the app `package.json` name to the scoped form (`@scope/name-app`).
|
|
40
|
-
* Called after `ph init` and after name/scope renames.
|
|
41
|
-
*
|
|
42
|
-
* Returns `true` if the file was actually changed.
|
|
43
|
-
*/
|
|
44
|
-
export declare function patchAppPackageName(appDir: string, spec: {
|
|
45
|
-
name: string;
|
|
46
|
-
scope?: string;
|
|
47
|
-
}, log?: (msg: string) => void): Promise<boolean>;
|
|
48
|
-
/**
|
|
49
|
-
* Run `ph install <packages> --local --pnpm` in the app directory to register
|
|
50
|
-
* external packages in `powerhouse.config.json`.
|
|
51
|
-
*/
|
|
52
|
-
export declare function runPhInstallPackages(options: {
|
|
53
|
-
appDir: string;
|
|
54
|
-
packages: string[];
|
|
55
|
-
log?: (msg: string) => void;
|
|
56
|
-
runProcess: RunProcess;
|
|
57
|
-
}): Promise<boolean>;
|
|
58
|
-
export interface PnpmInstallOptions {
|
|
59
|
-
/** Directories to run `pnpm install` in, in order. */
|
|
60
|
-
dirs: string[];
|
|
61
|
-
log?: (msg: string) => void;
|
|
62
|
-
/** Override `pnpm` binary name (for tests). */
|
|
63
|
-
binName?: string;
|
|
64
|
-
/** Subprocess runner — matches CommandContext.runProcess. */
|
|
65
|
-
runProcess: RunProcess;
|
|
66
|
-
}
|
|
67
|
-
export interface PnpmInstallResult {
|
|
68
|
-
ran: string[];
|
|
69
|
-
skipped: string[];
|
|
70
|
-
reason?: string;
|
|
71
|
-
}
|
|
72
|
-
export declare function runPnpmInstall(options: PnpmInstallOptions): Promise<PnpmInstallResult>;
|