@distributionos/cli 0.1.4 → 0.1.7
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 +55 -32
- package/src/mutate.js +30 -10
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'
|
|
@@ -121,16 +129,31 @@ async function readProjectDocs(cwd) {
|
|
|
121
129
|
return {};
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
function extractOverviewExcerpt(text) {
|
|
125
|
-
const normalized = text.replace(/\r\n/g, '\n');
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
132
|
+
function extractOverviewExcerpt(text) {
|
|
133
|
+
const normalized = text.replace(/\r\n/g, '\n');
|
|
134
|
+
if (isScaffoldReadme(normalized)) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const overviewIndex = normalized.search(/(^|\n)#{1,3}\s+(Project Overview|Overview|Solution|What it does)\s*\n/i);
|
|
138
|
+
const source = overviewIndex >= 0 ? normalized.slice(overviewIndex) : normalized;
|
|
139
|
+
return source
|
|
140
|
+
.split(/\n{2,}/)
|
|
141
|
+
.map(block => block.replace(/^#{1,6}\s+[^\n]+\n?/, '').trim())
|
|
142
|
+
.find(block => block.length >= 80 && !/secret|api key|environment variables/i.test(block) && !isScaffoldReadme(block))
|
|
143
|
+
?.slice(0, 700) ?? null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isScaffoldReadme(value) {
|
|
147
|
+
const text = value.toLowerCase();
|
|
148
|
+
return [
|
|
149
|
+
'this is a [next.js]',
|
|
150
|
+
'bootstrapped with [`create-next-app`]',
|
|
151
|
+
'next.js documentation',
|
|
152
|
+
'learn next.js',
|
|
153
|
+
'deploy on vercel',
|
|
154
|
+
'you can start editing the page by modifying',
|
|
155
|
+
].filter(needle => text.includes(needle)).length >= 2;
|
|
156
|
+
}
|
|
134
157
|
|
|
135
158
|
function routeReference(route, files) {
|
|
136
159
|
if (route === '/blog' && files.includes('src/app/blog/page.tsx')) return 'src/app/blog/page.tsx';
|
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');
|