@distributionos/cli 0.1.3 → 0.1.6
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 +1 -1
- package/src/initialization.js +30 -22
- package/src/mutate.js +30 -10
- package/src/plan.js +3 -3
package/package.json
CHANGED
package/src/initialization.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
export async function buildInitializationPayload(plan, options = {}) {
|
|
5
|
-
const appName = titleFromPackageName(plan.repo.packageJson?.name ?? plan.appId);
|
|
6
|
-
const docs = await readProjectDocs(plan.cwd);
|
|
7
|
-
const publicBlogRoute = plan.repo.routes.find(route => route === '/blog' || route.startsWith('/blog/'));
|
|
8
|
-
const
|
|
4
|
+
export async function buildInitializationPayload(plan, options = {}) {
|
|
5
|
+
const appName = titleFromPackageName(plan.repo.packageJson?.name ?? plan.appId);
|
|
6
|
+
const docs = await readProjectDocs(plan.cwd);
|
|
7
|
+
const publicBlogRoute = plan.repo.routes.find(route => route === '/blog' || route.startsWith('/blog/'));
|
|
8
|
+
const appIdentity = {
|
|
9
|
+
name: appName,
|
|
10
|
+
};
|
|
11
|
+
if (options.domain) {
|
|
12
|
+
appIdentity.domain = options.domain;
|
|
13
|
+
}
|
|
14
|
+
if (docs.overview?.claim) {
|
|
15
|
+
appIdentity.description = docs.overview.claim;
|
|
16
|
+
}
|
|
17
|
+
const repo = {
|
|
18
|
+
root: path.basename(plan.cwd),
|
|
19
|
+
frameworks: [plan.repo.framework].filter(value => value && value !== 'unknown'),
|
|
20
|
+
languages: ['TypeScript', 'JavaScript'],
|
|
21
|
+
packageManagers: [plan.repo.packageManager].filter(value => value && value !== 'unknown'),
|
|
22
|
+
notableFiles: [
|
|
23
|
+
'package.json',
|
|
24
|
+
...plan.repo.layoutCandidates,
|
|
25
|
+
...plan.repo.contentFiles.slice(0, 12),
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
if (plan.repo.git.branch) {
|
|
29
|
+
repo.defaultBranch = plan.repo.git.branch;
|
|
30
|
+
}
|
|
31
|
+
const claims = [
|
|
9
32
|
{
|
|
10
33
|
category: 'repo',
|
|
11
34
|
claim: `The repo package name is ${plan.repo.packageJson?.name ?? appName}.`,
|
|
@@ -47,23 +70,8 @@ export async function buildInitializationPayload(plan, options = {}) {
|
|
|
47
70
|
client: 'distributionos-cli',
|
|
48
71
|
instructionPackVersion: plan.instructionPackVersion,
|
|
49
72
|
sourceSummary: 'DistributionOS CLI inspected package metadata, routes, content files, deploy hints, and agent instruction files. It did not read .env files or secrets.',
|
|
50
|
-
appIdentity
|
|
51
|
-
|
|
52
|
-
domain: options.domain,
|
|
53
|
-
description: docs.overview?.claim,
|
|
54
|
-
},
|
|
55
|
-
repo: {
|
|
56
|
-
root: path.basename(plan.cwd),
|
|
57
|
-
defaultBranch: plan.repo.git.branch ?? null,
|
|
58
|
-
frameworks: [plan.repo.framework].filter(value => value && value !== 'unknown'),
|
|
59
|
-
languages: ['TypeScript', 'JavaScript'],
|
|
60
|
-
packageManagers: [plan.repo.packageManager].filter(value => value && value !== 'unknown'),
|
|
61
|
-
notableFiles: [
|
|
62
|
-
'package.json',
|
|
63
|
-
...plan.repo.layoutCandidates,
|
|
64
|
-
...plan.repo.contentFiles.slice(0, 12),
|
|
65
|
-
],
|
|
66
|
-
},
|
|
73
|
+
appIdentity,
|
|
74
|
+
repo,
|
|
67
75
|
distribution: {
|
|
68
76
|
blogRoute: publicBlogRoute ?? undefined,
|
|
69
77
|
analytics: plan.analytics.status === 'enabled'
|
package/src/mutate.js
CHANGED
|
@@ -91,9 +91,9 @@ async function applyNextAppRouterAnalytics(cwd, analytics, scriptSrc) {
|
|
|
91
91
|
contractVersion: analytics.contractVersion,
|
|
92
92
|
configScript: analytics.configScript,
|
|
93
93
|
});
|
|
94
|
-
const next = ANALYTICS_BLOCK_RE.test(existing)
|
|
95
|
-
? existing.replace(ANALYTICS_BLOCK_RE, `\n${block}\n`)
|
|
96
|
-
:
|
|
94
|
+
const next = ANALYTICS_BLOCK_RE.test(existing)
|
|
95
|
+
? existing.replace(ANALYTICS_BLOCK_RE, `\n${block}\n`)
|
|
96
|
+
: insertIntoNextAppRouterLayout(existing, block);
|
|
97
97
|
|
|
98
98
|
if (next === existing) {
|
|
99
99
|
return { type: 'analytics', changed: false, file: analytics.layoutTarget, reason: 'No analytics change needed.' };
|
|
@@ -156,13 +156,33 @@ function buildHtmlAnalyticsBlock({ scriptSrc, contractVersion, configScript }) {
|
|
|
156
156
|
].join('\n');
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
function insertBeforeHeadClose(content, block) {
|
|
160
|
-
const headClose = content.match(/^(\s*)<\/head>/im);
|
|
161
|
-
if (headClose?.index === undefined) {
|
|
162
|
-
throw new Error('Could not find </head> in shared layout.');
|
|
163
|
-
}
|
|
164
|
-
return `${content.slice(0, headClose.index)}${block}\n${content.slice(headClose.index)}`;
|
|
165
|
-
}
|
|
159
|
+
function insertBeforeHeadClose(content, block) {
|
|
160
|
+
const headClose = content.match(/^(\s*)<\/head>/im);
|
|
161
|
+
if (headClose?.index === undefined) {
|
|
162
|
+
throw new Error('Could not find </head> in shared layout.');
|
|
163
|
+
}
|
|
164
|
+
return `${content.slice(0, headClose.index)}${block}\n${content.slice(headClose.index)}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function insertIntoNextAppRouterLayout(content, block) {
|
|
168
|
+
const headClose = content.match(/^(\s*)<\/head>/im);
|
|
169
|
+
if (headClose?.index !== undefined) {
|
|
170
|
+
return `${content.slice(0, headClose.index)}${block}\n${content.slice(headClose.index)}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const bodyOpen = content.match(/^(\s*)<body(\s|>)/im);
|
|
174
|
+
if (bodyOpen?.index === undefined) {
|
|
175
|
+
throw new Error('Could not find <body> in shared layout.');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const indent = bodyOpen[1] || ' ';
|
|
179
|
+
const headBlock = [
|
|
180
|
+
`${indent}<head>`,
|
|
181
|
+
block,
|
|
182
|
+
`${indent}</head>`,
|
|
183
|
+
].join('\n');
|
|
184
|
+
return `${content.slice(0, bodyOpen.index)}${headBlock}\n${content.slice(bodyOpen.index)}`;
|
|
185
|
+
}
|
|
166
186
|
|
|
167
187
|
function indentLines(value, prefix) {
|
|
168
188
|
return String(value).split(/\r?\n/).map(line => `${prefix}${line}`).join('\n');
|
package/src/plan.js
CHANGED
|
@@ -311,9 +311,9 @@ function analyticsSummary(analytics) {
|
|
|
311
311
|
if (analytics.status === 'enabled') {
|
|
312
312
|
return `contract ${analytics.contractVersion}; install script in ${analytics.layoutTarget ?? 'reviewed shared layout'}`;
|
|
313
313
|
}
|
|
314
|
-
if (analytics.status === 'disabled') {
|
|
315
|
-
return 'tracker
|
|
316
|
-
}
|
|
314
|
+
if (analytics.status === 'disabled') {
|
|
315
|
+
return 'tracker will be created or fetched during apply before analytics is installed';
|
|
316
|
+
}
|
|
317
317
|
return 'contract not fetched; print manual guidance only';
|
|
318
318
|
}
|
|
319
319
|
|