@intrig/plugin-next 0.0.2-0 → 0.0.2-2
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 +69 -34
- package/dist/index.js +69 -34
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,6 @@ var fsx = require('fs-extra');
|
|
|
8
8
|
var mimeType = require('mime-types');
|
|
9
9
|
var _ = require('lodash');
|
|
10
10
|
var fs = require('fs');
|
|
11
|
-
var inquirer = require('inquirer');
|
|
12
11
|
|
|
13
12
|
function _interopNamespaceDefault(e) {
|
|
14
13
|
var n = Object.create(null);
|
|
@@ -4734,37 +4733,11 @@ function updateGitIgnore(rootDir, entryToAdd) {
|
|
|
4734
4733
|
fs__namespace.writeFileSync(gitIgnorePath, gitIgnoreContent.join('\n'), 'utf-8');
|
|
4735
4734
|
}
|
|
4736
4735
|
}
|
|
4737
|
-
function updateIntrigConfig(rootDir, apiRoutesDir) {
|
|
4738
|
-
const configPath = path__namespace.resolve(rootDir, 'intrig.config.json');
|
|
4739
|
-
if (fs__namespace.existsSync(configPath)) {
|
|
4740
|
-
const config = JSON.parse(fs__namespace.readFileSync(configPath, 'utf-8'));
|
|
4741
|
-
config.generatorOptions = config.generatorOptions || {};
|
|
4742
|
-
config.generatorOptions.apiRoutesDir = apiRoutesDir;
|
|
4743
|
-
fs__namespace.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
4744
|
-
}
|
|
4745
|
-
}
|
|
4746
4736
|
async function initPlugin(ctx) {
|
|
4747
|
-
const { rootDir } = ctx;
|
|
4748
|
-
const
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
updateGitIgnore(rootDir, 'src/app/api/(generated)');
|
|
4752
|
-
} else {
|
|
4753
|
-
// Ask user for apiRoutesDir
|
|
4754
|
-
const { apiRoutesDir } = await inquirer.prompt([
|
|
4755
|
-
{
|
|
4756
|
-
type: 'input',
|
|
4757
|
-
name: 'apiRoutesDir',
|
|
4758
|
-
message: 'Enter the API routes directory path:',
|
|
4759
|
-
default: 'src/app/api',
|
|
4760
|
-
validate: (input)=>input.trim().length > 0 || 'Please enter a valid directory path'
|
|
4761
|
-
}
|
|
4762
|
-
]);
|
|
4763
|
-
// Update intrig.config.json with the apiRoutesDir value
|
|
4764
|
-
updateIntrigConfig(rootDir, apiRoutesDir);
|
|
4765
|
-
// Add the directory with (generated) to gitignore
|
|
4766
|
-
updateGitIgnore(rootDir, `${apiRoutesDir}/(generated)`);
|
|
4767
|
-
}
|
|
4737
|
+
const { rootDir, options } = ctx;
|
|
4738
|
+
const apiRoutesDir = (options == null ? void 0 : options.apiRoutesDir) || 'src/app/api';
|
|
4739
|
+
// Add the directory with (generated) to gitignore
|
|
4740
|
+
updateGitIgnore(rootDir, `${apiRoutesDir}/(generated)`);
|
|
4768
4741
|
}
|
|
4769
4742
|
|
|
4770
4743
|
async function postBuild(ctx) {
|
|
@@ -4796,12 +4769,71 @@ async function postBuild(ctx) {
|
|
|
4796
4769
|
}
|
|
4797
4770
|
}
|
|
4798
4771
|
|
|
4772
|
+
async function addSource(ctx) {
|
|
4773
|
+
const { rootDir, source, serverUrl } = ctx;
|
|
4774
|
+
const envPath = path__namespace.resolve(rootDir, '.env');
|
|
4775
|
+
// Generate environment variable name from source ID
|
|
4776
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4777
|
+
// Use serverUrl if available, otherwise fall back to specUrl
|
|
4778
|
+
const apiUrl = serverUrl || source.specUrl;
|
|
4779
|
+
const envVarLine = `${envVarName}=${apiUrl}`;
|
|
4780
|
+
let envContent = '';
|
|
4781
|
+
// Read existing .env file if it exists
|
|
4782
|
+
if (fs__namespace.existsSync(envPath)) {
|
|
4783
|
+
envContent = fs__namespace.readFileSync(envPath, 'utf-8');
|
|
4784
|
+
}
|
|
4785
|
+
// Check if the environment variable already exists
|
|
4786
|
+
const lines = envContent.split('\n');
|
|
4787
|
+
const existingLineIndex = lines.findIndex((line)=>line.trim().startsWith(`${envVarName}=`));
|
|
4788
|
+
if (existingLineIndex >= 0) {
|
|
4789
|
+
// Update existing line
|
|
4790
|
+
lines[existingLineIndex] = envVarLine;
|
|
4791
|
+
} else {
|
|
4792
|
+
// Add new line
|
|
4793
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
4794
|
+
lines.push('');
|
|
4795
|
+
}
|
|
4796
|
+
lines.push(envVarLine);
|
|
4797
|
+
}
|
|
4798
|
+
// Write back to .env file
|
|
4799
|
+
const newContent = lines.join('\n');
|
|
4800
|
+
fs__namespace.writeFileSync(envPath, newContent, 'utf-8');
|
|
4801
|
+
console.log(`Added environment variable ${envVarName} to .env file`);
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4804
|
+
async function removeSource(ctx) {
|
|
4805
|
+
const { rootDir, source } = ctx;
|
|
4806
|
+
const envPath = path__namespace.resolve(rootDir, '.env');
|
|
4807
|
+
// Generate environment variable name from source ID
|
|
4808
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4809
|
+
// Check if .env file exists
|
|
4810
|
+
if (!fs__namespace.existsSync(envPath)) {
|
|
4811
|
+
console.log(`No .env file found at ${envPath}`);
|
|
4812
|
+
return;
|
|
4813
|
+
}
|
|
4814
|
+
// Read existing .env file
|
|
4815
|
+
const envContent = fs__namespace.readFileSync(envPath, 'utf-8');
|
|
4816
|
+
const lines = envContent.split('\n');
|
|
4817
|
+
// Filter out the environment variable line
|
|
4818
|
+
const filteredLines = lines.filter((line)=>!line.trim().startsWith(`${envVarName}=`));
|
|
4819
|
+
// Check if anything was removed
|
|
4820
|
+
if (filteredLines.length === lines.length) {
|
|
4821
|
+
console.log(`Environment variable ${envVarName} not found in .env file`);
|
|
4822
|
+
return;
|
|
4823
|
+
}
|
|
4824
|
+
// Write back to .env file
|
|
4825
|
+
const newContent = filteredLines.join('\n');
|
|
4826
|
+
fs__namespace.writeFileSync(envPath, newContent, 'utf-8');
|
|
4827
|
+
console.log(`Removed environment variable ${envVarName} from .env file`);
|
|
4828
|
+
}
|
|
4829
|
+
|
|
4799
4830
|
const $generatorSchema = {
|
|
4800
4831
|
type: 'object',
|
|
4801
4832
|
properties: {
|
|
4802
4833
|
"apiRoutesDir": {
|
|
4803
4834
|
type: 'string',
|
|
4804
|
-
description: 'The directory where the API routes are stored.'
|
|
4835
|
+
description: 'The directory where the API routes are stored.',
|
|
4836
|
+
default: 'src/app/api'
|
|
4805
4837
|
}
|
|
4806
4838
|
}
|
|
4807
4839
|
};
|
|
@@ -4812,14 +4844,17 @@ function createPlugin() {
|
|
|
4812
4844
|
return {
|
|
4813
4845
|
name: 'intrig-binding',
|
|
4814
4846
|
version: '0.0.1',
|
|
4815
|
-
compat: '^0.0.15'
|
|
4847
|
+
compat: '^0.0.15',
|
|
4848
|
+
generator: 'next'
|
|
4816
4849
|
};
|
|
4817
4850
|
},
|
|
4818
4851
|
generate: generateCode,
|
|
4819
4852
|
getSchemaDocumentation,
|
|
4820
4853
|
getEndpointDocumentation,
|
|
4821
4854
|
init: initPlugin,
|
|
4822
|
-
postBuild: postBuild
|
|
4855
|
+
postBuild: postBuild,
|
|
4856
|
+
addSource: addSource,
|
|
4857
|
+
removeSource: removeSource
|
|
4823
4858
|
};
|
|
4824
4859
|
}
|
|
4825
4860
|
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import * as fsx from 'fs-extra';
|
|
|
5
5
|
import * as mimeType from 'mime-types';
|
|
6
6
|
import * as _ from 'lodash';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
|
-
import inquirer from 'inquirer';
|
|
9
8
|
|
|
10
9
|
class InternalGeneratorContext {
|
|
11
10
|
getCounter(sourceId) {
|
|
@@ -4708,37 +4707,11 @@ function updateGitIgnore(rootDir, entryToAdd) {
|
|
|
4708
4707
|
fs.writeFileSync(gitIgnorePath, gitIgnoreContent.join('\n'), 'utf-8');
|
|
4709
4708
|
}
|
|
4710
4709
|
}
|
|
4711
|
-
function updateIntrigConfig(rootDir, apiRoutesDir) {
|
|
4712
|
-
const configPath = path.resolve(rootDir, 'intrig.config.json');
|
|
4713
|
-
if (fs.existsSync(configPath)) {
|
|
4714
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
4715
|
-
config.generatorOptions = config.generatorOptions || {};
|
|
4716
|
-
config.generatorOptions.apiRoutesDir = apiRoutesDir;
|
|
4717
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
4718
|
-
}
|
|
4719
|
-
}
|
|
4720
4710
|
async function initPlugin(ctx) {
|
|
4721
|
-
const { rootDir } = ctx;
|
|
4722
|
-
const
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
updateGitIgnore(rootDir, 'src/app/api/(generated)');
|
|
4726
|
-
} else {
|
|
4727
|
-
// Ask user for apiRoutesDir
|
|
4728
|
-
const { apiRoutesDir } = await inquirer.prompt([
|
|
4729
|
-
{
|
|
4730
|
-
type: 'input',
|
|
4731
|
-
name: 'apiRoutesDir',
|
|
4732
|
-
message: 'Enter the API routes directory path:',
|
|
4733
|
-
default: 'src/app/api',
|
|
4734
|
-
validate: (input)=>input.trim().length > 0 || 'Please enter a valid directory path'
|
|
4735
|
-
}
|
|
4736
|
-
]);
|
|
4737
|
-
// Update intrig.config.json with the apiRoutesDir value
|
|
4738
|
-
updateIntrigConfig(rootDir, apiRoutesDir);
|
|
4739
|
-
// Add the directory with (generated) to gitignore
|
|
4740
|
-
updateGitIgnore(rootDir, `${apiRoutesDir}/(generated)`);
|
|
4741
|
-
}
|
|
4711
|
+
const { rootDir, options } = ctx;
|
|
4712
|
+
const apiRoutesDir = (options == null ? void 0 : options.apiRoutesDir) || 'src/app/api';
|
|
4713
|
+
// Add the directory with (generated) to gitignore
|
|
4714
|
+
updateGitIgnore(rootDir, `${apiRoutesDir}/(generated)`);
|
|
4742
4715
|
}
|
|
4743
4716
|
|
|
4744
4717
|
async function postBuild(ctx) {
|
|
@@ -4770,12 +4743,71 @@ async function postBuild(ctx) {
|
|
|
4770
4743
|
}
|
|
4771
4744
|
}
|
|
4772
4745
|
|
|
4746
|
+
async function addSource(ctx) {
|
|
4747
|
+
const { rootDir, source, serverUrl } = ctx;
|
|
4748
|
+
const envPath = path.resolve(rootDir, '.env');
|
|
4749
|
+
// Generate environment variable name from source ID
|
|
4750
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4751
|
+
// Use serverUrl if available, otherwise fall back to specUrl
|
|
4752
|
+
const apiUrl = serverUrl || source.specUrl;
|
|
4753
|
+
const envVarLine = `${envVarName}=${apiUrl}`;
|
|
4754
|
+
let envContent = '';
|
|
4755
|
+
// Read existing .env file if it exists
|
|
4756
|
+
if (fs.existsSync(envPath)) {
|
|
4757
|
+
envContent = fs.readFileSync(envPath, 'utf-8');
|
|
4758
|
+
}
|
|
4759
|
+
// Check if the environment variable already exists
|
|
4760
|
+
const lines = envContent.split('\n');
|
|
4761
|
+
const existingLineIndex = lines.findIndex((line)=>line.trim().startsWith(`${envVarName}=`));
|
|
4762
|
+
if (existingLineIndex >= 0) {
|
|
4763
|
+
// Update existing line
|
|
4764
|
+
lines[existingLineIndex] = envVarLine;
|
|
4765
|
+
} else {
|
|
4766
|
+
// Add new line
|
|
4767
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
4768
|
+
lines.push('');
|
|
4769
|
+
}
|
|
4770
|
+
lines.push(envVarLine);
|
|
4771
|
+
}
|
|
4772
|
+
// Write back to .env file
|
|
4773
|
+
const newContent = lines.join('\n');
|
|
4774
|
+
fs.writeFileSync(envPath, newContent, 'utf-8');
|
|
4775
|
+
console.log(`Added environment variable ${envVarName} to .env file`);
|
|
4776
|
+
}
|
|
4777
|
+
|
|
4778
|
+
async function removeSource(ctx) {
|
|
4779
|
+
const { rootDir, source } = ctx;
|
|
4780
|
+
const envPath = path.resolve(rootDir, '.env');
|
|
4781
|
+
// Generate environment variable name from source ID
|
|
4782
|
+
const envVarName = `${source.id.toUpperCase()}_API_URL`;
|
|
4783
|
+
// Check if .env file exists
|
|
4784
|
+
if (!fs.existsSync(envPath)) {
|
|
4785
|
+
console.log(`No .env file found at ${envPath}`);
|
|
4786
|
+
return;
|
|
4787
|
+
}
|
|
4788
|
+
// Read existing .env file
|
|
4789
|
+
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
4790
|
+
const lines = envContent.split('\n');
|
|
4791
|
+
// Filter out the environment variable line
|
|
4792
|
+
const filteredLines = lines.filter((line)=>!line.trim().startsWith(`${envVarName}=`));
|
|
4793
|
+
// Check if anything was removed
|
|
4794
|
+
if (filteredLines.length === lines.length) {
|
|
4795
|
+
console.log(`Environment variable ${envVarName} not found in .env file`);
|
|
4796
|
+
return;
|
|
4797
|
+
}
|
|
4798
|
+
// Write back to .env file
|
|
4799
|
+
const newContent = filteredLines.join('\n');
|
|
4800
|
+
fs.writeFileSync(envPath, newContent, 'utf-8');
|
|
4801
|
+
console.log(`Removed environment variable ${envVarName} from .env file`);
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4773
4804
|
const $generatorSchema = {
|
|
4774
4805
|
type: 'object',
|
|
4775
4806
|
properties: {
|
|
4776
4807
|
"apiRoutesDir": {
|
|
4777
4808
|
type: 'string',
|
|
4778
|
-
description: 'The directory where the API routes are stored.'
|
|
4809
|
+
description: 'The directory where the API routes are stored.',
|
|
4810
|
+
default: 'src/app/api'
|
|
4779
4811
|
}
|
|
4780
4812
|
}
|
|
4781
4813
|
};
|
|
@@ -4786,14 +4818,17 @@ function createPlugin() {
|
|
|
4786
4818
|
return {
|
|
4787
4819
|
name: 'intrig-binding',
|
|
4788
4820
|
version: '0.0.1',
|
|
4789
|
-
compat: '^0.0.15'
|
|
4821
|
+
compat: '^0.0.15',
|
|
4822
|
+
generator: 'next'
|
|
4790
4823
|
};
|
|
4791
4824
|
},
|
|
4792
4825
|
generate: generateCode,
|
|
4793
4826
|
getSchemaDocumentation,
|
|
4794
4827
|
getEndpointDocumentation,
|
|
4795
4828
|
init: initPlugin,
|
|
4796
|
-
postBuild: postBuild
|
|
4829
|
+
postBuild: postBuild,
|
|
4830
|
+
addSource: addSource,
|
|
4831
|
+
removeSource: removeSource
|
|
4797
4832
|
};
|
|
4798
4833
|
}
|
|
4799
4834
|
|
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-2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@intrig/plugin-sdk": "^0.0.2-
|
|
18
|
+
"@intrig/plugin-sdk": "^0.0.2-5",
|
|
19
19
|
"@swc/helpers": "~0.5.11"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|