netlify-cli 21.2.1 → 21.4.0
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/commands/api/api.d.ts.map +1 -1
- package/dist/commands/api/api.js +1 -1
- package/dist/commands/api/api.js.map +1 -1
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/base-command.js +1 -1
- package/dist/commands/base-command.js.map +1 -1
- package/dist/commands/deploy/deploy.js +1 -1
- package/dist/commands/deploy/deploy.js.map +1 -1
- package/dist/commands/watch/watch.js.map +1 -1
- package/dist/lib/api.d.ts +1 -1
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/recipes/ai-context/context.d.ts +28 -2
- package/dist/recipes/ai-context/context.d.ts.map +1 -1
- package/dist/recipes/ai-context/context.js +100 -6
- package/dist/recipes/ai-context/context.js.map +1 -1
- package/dist/recipes/ai-context/index.d.ts +1 -1
- package/dist/recipes/ai-context/index.d.ts.map +1 -1
- package/dist/recipes/ai-context/index.js +103 -55
- package/dist/recipes/ai-context/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/command-helpers.d.ts +1 -1
- package/dist/utils/command-helpers.d.ts.map +1 -1
- package/dist/utils/command-helpers.js.map +1 -1
- package/dist/utils/dev.d.ts +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/env/index.d.ts +1 -1
- package/dist/utils/env/index.d.ts.map +1 -1
- package/dist/utils/get-site.d.ts +1 -1
- package/dist/utils/get-site.d.ts.map +1 -1
- package/dist/utils/init/config-github.js.map +1 -1
- package/dist/utils/init/utils.d.ts +1 -1
- package/dist/utils/init/utils.d.ts.map +1 -1
- package/dist/utils/init/utils.js.map +1 -1
- package/npm-shrinkwrap.json +77 -77
- package/package.json +5 -5
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import execa from 'execa';
|
|
4
|
+
import { logAndThrowError, log, version } from '../../utils/command-helpers.js';
|
|
5
|
+
import { getExistingContext, NTL_DEV_MCP_FILE_NAME, getContextConsumers, deleteFile, downloadAndWriteContextFiles, } from './context.js';
|
|
6
6
|
export const description = 'Manage context files for AI tools';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
7
|
+
// context consumers endpoints returns all supported IDE and other consumers
|
|
8
|
+
// that can be used to pull context files. It also includes a catchall consumer
|
|
9
|
+
// for outlining all context that an unspecified consumer would handle.
|
|
10
|
+
const allContextConsumers = (await getContextConsumers(version)).filter((consumer) => !consumer.hideFromCLI);
|
|
11
|
+
const cliContextConsumers = allContextConsumers.filter((consumer) => !consumer.hideFromCLI);
|
|
12
|
+
const rulesForDefaultConsumer = allContextConsumers.find((consumer) => consumer.key === 'catchall-consumer') ?? {
|
|
13
|
+
key: 'catchall-consumer',
|
|
14
|
+
path: './ai-context',
|
|
15
|
+
presentedName: '',
|
|
16
|
+
ext: 'mdc',
|
|
17
|
+
contextScopes: {},
|
|
18
|
+
hideFromCLI: true,
|
|
19
|
+
};
|
|
20
|
+
const presets = cliContextConsumers.map((consumer) => ({
|
|
21
|
+
name: consumer.presentedName,
|
|
22
|
+
value: consumer.key,
|
|
23
|
+
}));
|
|
24
|
+
// always add the custom location option (not preset from API)
|
|
25
|
+
presets.push({ name: 'Custom location', value: rulesForDefaultConsumer.key });
|
|
26
|
+
const promptForContextConsumerSelection = async () => {
|
|
27
|
+
const { consumerKey } = await inquirer.prompt([
|
|
14
28
|
{
|
|
15
|
-
name: '
|
|
29
|
+
name: 'consumerKey',
|
|
16
30
|
message: 'Where should we put the context files?',
|
|
17
31
|
type: 'list',
|
|
18
32
|
choices: presets,
|
|
19
33
|
},
|
|
20
34
|
]);
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
const contextConsumer = consumerKey ? cliContextConsumers.find((consumer) => consumer.key === consumerKey) : null;
|
|
36
|
+
if (contextConsumer) {
|
|
37
|
+
return contextConsumer;
|
|
23
38
|
}
|
|
24
39
|
const { customPath } = await inquirer.prompt([
|
|
25
40
|
{
|
|
@@ -30,55 +45,88 @@ const promptForPath = async () => {
|
|
|
30
45
|
},
|
|
31
46
|
]);
|
|
32
47
|
if (customPath) {
|
|
33
|
-
return customPath;
|
|
48
|
+
return { ...rulesForDefaultConsumer, path: customPath || rulesForDefaultConsumer.path };
|
|
34
49
|
}
|
|
35
50
|
log('You must select a path.');
|
|
36
|
-
return
|
|
51
|
+
return promptForContextConsumerSelection();
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a command belongs to a known IDEs by checking if it includes a specific string.
|
|
55
|
+
* For example, the command that starts windsurf looks something like "/applications/windsurf.app/contents/...".
|
|
56
|
+
*/
|
|
57
|
+
const getConsumerKeyFromCommand = (command) => {
|
|
58
|
+
// The actual command is something like "/applications/windsurf.app/contents/...", but we are only looking for windsurf
|
|
59
|
+
const match = cliContextConsumers.find((consumer) => consumer.consumerProcessCmd && command.includes(consumer.consumerProcessCmd));
|
|
60
|
+
return match ? match.key : null;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Receives a process ID (pid) and returns both the command that the process was run with and its parent process ID. If the process is a known IDE, also returns information about that IDE.
|
|
64
|
+
*/
|
|
65
|
+
const getCommandAndParentPID = async (pid) => {
|
|
66
|
+
const { stdout } = await execa('ps', ['-p', String(pid), '-o', 'ppid=,comm=']);
|
|
67
|
+
const output = stdout.trim();
|
|
68
|
+
const spaceIndex = output.indexOf(' ');
|
|
69
|
+
const parentPID = output.substring(0, spaceIndex);
|
|
70
|
+
const command = output.substring(spaceIndex + 1).toLowerCase();
|
|
71
|
+
return {
|
|
72
|
+
parentPID: Number(parentPID),
|
|
73
|
+
command,
|
|
74
|
+
consumerKey: getConsumerKeyFromCommand(command),
|
|
75
|
+
};
|
|
37
76
|
};
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
77
|
+
const getPathByDetectingIDE = async () => {
|
|
78
|
+
// Go up the chain of ancestor process IDs and find if one of their commands matches an IDE.
|
|
79
|
+
const ppid = process.ppid;
|
|
80
|
+
let result;
|
|
81
|
+
try {
|
|
82
|
+
result = await getCommandAndParentPID(ppid);
|
|
83
|
+
while (result.parentPID !== 1 && !result.consumerKey) {
|
|
84
|
+
result = await getCommandAndParentPID(result.parentPID);
|
|
85
|
+
}
|
|
45
86
|
}
|
|
46
|
-
|
|
47
|
-
|
|
87
|
+
catch {
|
|
88
|
+
// The command "ps -p {pid} -o ppid=,comm=" didn't work,
|
|
89
|
+
// perhaps we are on a machine that doesn't support it.
|
|
90
|
+
return null;
|
|
48
91
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Does a file already exist at this path?
|
|
54
|
-
if (existing) {
|
|
55
|
-
// If it's a file we've created, let's check the version and bail if we're
|
|
56
|
-
// already on the latest, otherwise rewrite it with the latest version.
|
|
57
|
-
if (existing.provider?.toLowerCase() === NETLIFY_PROVIDER) {
|
|
58
|
-
if (remote?.version === existing.version) {
|
|
59
|
-
log(`You're all up to date! ${chalk.underline(absoluteFilePath)} contains the latest version of the context files.`);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// We must preserve any overrides found in the existing file.
|
|
63
|
-
contents = applyOverrides(remote.contents, existing.overrides?.innerContents);
|
|
92
|
+
if (result?.consumerKey) {
|
|
93
|
+
const contextConsumer = cliContextConsumers.find((consumer) => consumer.key === result.consumerKey);
|
|
94
|
+
if (contextConsumer) {
|
|
95
|
+
return contextConsumer;
|
|
64
96
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
};
|
|
100
|
+
export const run = async (runOptions) => {
|
|
101
|
+
const { args, command } = runOptions;
|
|
102
|
+
let consumer = null;
|
|
103
|
+
const filePath = args[0];
|
|
104
|
+
if (filePath) {
|
|
105
|
+
consumer = { ...rulesForDefaultConsumer, path: filePath };
|
|
106
|
+
}
|
|
107
|
+
if (!consumer && process.env.AI_CONTEXT_SKIP_DETECTION !== 'true') {
|
|
108
|
+
consumer = await getPathByDetectingIDE();
|
|
109
|
+
}
|
|
110
|
+
if (!consumer) {
|
|
111
|
+
consumer = await promptForContextConsumerSelection();
|
|
112
|
+
}
|
|
113
|
+
if (!consumer?.contextScopes) {
|
|
114
|
+
log('No context files found for this consumer. Try again or let us know if this happens again via our support channels.');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await downloadAndWriteContextFiles(consumer, runOptions);
|
|
119
|
+
// the deprecated MCP file path
|
|
120
|
+
// let's remove that file if it exists.
|
|
121
|
+
const priorContextFilePath = resolve(command?.workingDir ?? '', consumer.path, NTL_DEV_MCP_FILE_NAME);
|
|
122
|
+
const priorExists = await getExistingContext(priorContextFilePath);
|
|
123
|
+
if (priorExists) {
|
|
124
|
+
await deleteFile(priorContextFilePath);
|
|
79
125
|
}
|
|
126
|
+
log('All context files have been added!');
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
logAndThrowError(error);
|
|
80
130
|
}
|
|
81
|
-
await writeFile(absoluteFilePath, contents);
|
|
82
|
-
log(`${existing ? 'Updated' : 'Created'} context files at ${chalk.underline(absoluteFilePath)}`);
|
|
83
131
|
};
|
|
84
132
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/recipes/ai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