@intrig/plugin-next 0.0.2-0 → 0.0.2-1
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.cjs +63 -2
- package/dist/index.js +63 -2
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -4796,6 +4796,64 @@ async function postBuild(ctx) {
|
|
|
4796
4796
|
}
|
|
4797
4797
|
}
|
|
4798
4798
|
|
|
4799
|
+
async function addSource(ctx) {
|
|
4800
|
+
const { rootDir, source, serverUrl } = ctx;
|
|
4801
|
+
const envPath = path__namespace.resolve(rootDir, '.env');
|
|
4802
|
+
// Generate environment variable name from source ID
|
|
4803
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4804
|
+
// Use serverUrl if available, otherwise fall back to specUrl
|
|
4805
|
+
const apiUrl = serverUrl || source.specUrl;
|
|
4806
|
+
const envVarLine = `${envVarName}=${apiUrl}`;
|
|
4807
|
+
let envContent = '';
|
|
4808
|
+
// Read existing .env file if it exists
|
|
4809
|
+
if (fs__namespace.existsSync(envPath)) {
|
|
4810
|
+
envContent = fs__namespace.readFileSync(envPath, 'utf-8');
|
|
4811
|
+
}
|
|
4812
|
+
// Check if the environment variable already exists
|
|
4813
|
+
const lines = envContent.split('\n');
|
|
4814
|
+
const existingLineIndex = lines.findIndex((line)=>line.trim().startsWith(`${envVarName}=`));
|
|
4815
|
+
if (existingLineIndex >= 0) {
|
|
4816
|
+
// Update existing line
|
|
4817
|
+
lines[existingLineIndex] = envVarLine;
|
|
4818
|
+
} else {
|
|
4819
|
+
// Add new line
|
|
4820
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
4821
|
+
lines.push('');
|
|
4822
|
+
}
|
|
4823
|
+
lines.push(envVarLine);
|
|
4824
|
+
}
|
|
4825
|
+
// Write back to .env file
|
|
4826
|
+
const newContent = lines.join('\n');
|
|
4827
|
+
fs__namespace.writeFileSync(envPath, newContent, 'utf-8');
|
|
4828
|
+
console.log(`Added environment variable ${envVarName} to .env file`);
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4831
|
+
async function removeSource(ctx) {
|
|
4832
|
+
const { rootDir, source } = ctx;
|
|
4833
|
+
const envPath = path__namespace.resolve(rootDir, '.env');
|
|
4834
|
+
// Generate environment variable name from source ID
|
|
4835
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4836
|
+
// Check if .env file exists
|
|
4837
|
+
if (!fs__namespace.existsSync(envPath)) {
|
|
4838
|
+
console.log(`No .env file found at ${envPath}`);
|
|
4839
|
+
return;
|
|
4840
|
+
}
|
|
4841
|
+
// Read existing .env file
|
|
4842
|
+
const envContent = fs__namespace.readFileSync(envPath, 'utf-8');
|
|
4843
|
+
const lines = envContent.split('\n');
|
|
4844
|
+
// Filter out the environment variable line
|
|
4845
|
+
const filteredLines = lines.filter((line)=>!line.trim().startsWith(`${envVarName}=`));
|
|
4846
|
+
// Check if anything was removed
|
|
4847
|
+
if (filteredLines.length === lines.length) {
|
|
4848
|
+
console.log(`Environment variable ${envVarName} not found in .env file`);
|
|
4849
|
+
return;
|
|
4850
|
+
}
|
|
4851
|
+
// Write back to .env file
|
|
4852
|
+
const newContent = filteredLines.join('\n');
|
|
4853
|
+
fs__namespace.writeFileSync(envPath, newContent, 'utf-8');
|
|
4854
|
+
console.log(`Removed environment variable ${envVarName} from .env file`);
|
|
4855
|
+
}
|
|
4856
|
+
|
|
4799
4857
|
const $generatorSchema = {
|
|
4800
4858
|
type: 'object',
|
|
4801
4859
|
properties: {
|
|
@@ -4812,14 +4870,17 @@ function createPlugin() {
|
|
|
4812
4870
|
return {
|
|
4813
4871
|
name: 'intrig-binding',
|
|
4814
4872
|
version: '0.0.1',
|
|
4815
|
-
compat: '^0.0.15'
|
|
4873
|
+
compat: '^0.0.15',
|
|
4874
|
+
generator: 'next'
|
|
4816
4875
|
};
|
|
4817
4876
|
},
|
|
4818
4877
|
generate: generateCode,
|
|
4819
4878
|
getSchemaDocumentation,
|
|
4820
4879
|
getEndpointDocumentation,
|
|
4821
4880
|
init: initPlugin,
|
|
4822
|
-
postBuild: postBuild
|
|
4881
|
+
postBuild: postBuild,
|
|
4882
|
+
addSource: addSource,
|
|
4883
|
+
removeSource: removeSource
|
|
4823
4884
|
};
|
|
4824
4885
|
}
|
|
4825
4886
|
|
package/dist/index.js
CHANGED
|
@@ -4770,6 +4770,64 @@ async function postBuild(ctx) {
|
|
|
4770
4770
|
}
|
|
4771
4771
|
}
|
|
4772
4772
|
|
|
4773
|
+
async function addSource(ctx) {
|
|
4774
|
+
const { rootDir, source, serverUrl } = ctx;
|
|
4775
|
+
const envPath = path.resolve(rootDir, '.env');
|
|
4776
|
+
// Generate environment variable name from source ID
|
|
4777
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4778
|
+
// Use serverUrl if available, otherwise fall back to specUrl
|
|
4779
|
+
const apiUrl = serverUrl || source.specUrl;
|
|
4780
|
+
const envVarLine = `${envVarName}=${apiUrl}`;
|
|
4781
|
+
let envContent = '';
|
|
4782
|
+
// Read existing .env file if it exists
|
|
4783
|
+
if (fs.existsSync(envPath)) {
|
|
4784
|
+
envContent = fs.readFileSync(envPath, 'utf-8');
|
|
4785
|
+
}
|
|
4786
|
+
// Check if the environment variable already exists
|
|
4787
|
+
const lines = envContent.split('\n');
|
|
4788
|
+
const existingLineIndex = lines.findIndex((line)=>line.trim().startsWith(`${envVarName}=`));
|
|
4789
|
+
if (existingLineIndex >= 0) {
|
|
4790
|
+
// Update existing line
|
|
4791
|
+
lines[existingLineIndex] = envVarLine;
|
|
4792
|
+
} else {
|
|
4793
|
+
// Add new line
|
|
4794
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
4795
|
+
lines.push('');
|
|
4796
|
+
}
|
|
4797
|
+
lines.push(envVarLine);
|
|
4798
|
+
}
|
|
4799
|
+
// Write back to .env file
|
|
4800
|
+
const newContent = lines.join('\n');
|
|
4801
|
+
fs.writeFileSync(envPath, newContent, 'utf-8');
|
|
4802
|
+
console.log(`Added environment variable ${envVarName} to .env file`);
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4805
|
+
async function removeSource(ctx) {
|
|
4806
|
+
const { rootDir, source } = ctx;
|
|
4807
|
+
const envPath = path.resolve(rootDir, '.env');
|
|
4808
|
+
// Generate environment variable name from source ID
|
|
4809
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4810
|
+
// Check if .env file exists
|
|
4811
|
+
if (!fs.existsSync(envPath)) {
|
|
4812
|
+
console.log(`No .env file found at ${envPath}`);
|
|
4813
|
+
return;
|
|
4814
|
+
}
|
|
4815
|
+
// Read existing .env file
|
|
4816
|
+
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
4817
|
+
const lines = envContent.split('\n');
|
|
4818
|
+
// Filter out the environment variable line
|
|
4819
|
+
const filteredLines = lines.filter((line)=>!line.trim().startsWith(`${envVarName}=`));
|
|
4820
|
+
// Check if anything was removed
|
|
4821
|
+
if (filteredLines.length === lines.length) {
|
|
4822
|
+
console.log(`Environment variable ${envVarName} not found in .env file`);
|
|
4823
|
+
return;
|
|
4824
|
+
}
|
|
4825
|
+
// Write back to .env file
|
|
4826
|
+
const newContent = filteredLines.join('\n');
|
|
4827
|
+
fs.writeFileSync(envPath, newContent, 'utf-8');
|
|
4828
|
+
console.log(`Removed environment variable ${envVarName} from .env file`);
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4773
4831
|
const $generatorSchema = {
|
|
4774
4832
|
type: 'object',
|
|
4775
4833
|
properties: {
|
|
@@ -4786,14 +4844,17 @@ function createPlugin() {
|
|
|
4786
4844
|
return {
|
|
4787
4845
|
name: 'intrig-binding',
|
|
4788
4846
|
version: '0.0.1',
|
|
4789
|
-
compat: '^0.0.15'
|
|
4847
|
+
compat: '^0.0.15',
|
|
4848
|
+
generator: 'next'
|
|
4790
4849
|
};
|
|
4791
4850
|
},
|
|
4792
4851
|
generate: generateCode,
|
|
4793
4852
|
getSchemaDocumentation,
|
|
4794
4853
|
getEndpointDocumentation,
|
|
4795
4854
|
init: initPlugin,
|
|
4796
|
-
postBuild: postBuild
|
|
4855
|
+
postBuild: postBuild,
|
|
4856
|
+
addSource: addSource,
|
|
4857
|
+
removeSource: removeSource
|
|
4797
4858
|
};
|
|
4798
4859
|
}
|
|
4799
4860
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intrig/plugin-next",
|
|
3
|
-
"version": "0.0.2-
|
|
3
|
+
"version": "0.0.2-1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@intrig/plugin-sdk": "^0.0.2-
|
|
19
|
-
"@swc/helpers": "~0.5.11"
|
|
18
|
+
"@intrig/plugin-sdk": "^0.0.2-4",
|
|
19
|
+
"@swc/helpers": "~0.5.11",
|
|
20
|
+
"inquirer": "^9.0.0"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"dist",
|