@naganpm/fetch-prompts 1.0.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/.env.example ADDED
@@ -0,0 +1,6 @@
1
+ # GitLab Personal Access Token
2
+ # For private repositories, create a token at:
3
+ # https://gitlab.com/-/profile/personal_access_tokens
4
+ # Required scopes: read_api, read_repository
5
+
6
+ GITLAB_TOKEN=glpat-your-token-here
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # fetch-angular-prompts
2
+
3
+ Fetch Angular routing prompts from your GitLab repository.
4
+
5
+ ## Setup
6
+
7
+ 1. **Edit `bin/index.js`** and update the configuration:
8
+ ```js
9
+ const GITLAB_PROJECT = 'youruser/yourproject'; // Your GitLab project path
10
+ const GITLAB_BRANCH = 'main'; // Your branch name
11
+ const PROMPTS_PATH = 'prompts'; // Folder containing .md files
12
+ const GITLAB_HOST = 'gitlab.com'; // Or your GitLab instance
13
+ ```
14
+
15
+ 2. **For private repos**, create a `.env` file in the package root:
16
+ ```bash
17
+ # Copy the example
18
+ cp .env.example .env
19
+
20
+ # Edit .env and add your GitLab token
21
+ GITLAB_TOKEN=glpat-xxxxxxxxxxxx
22
+ ```
23
+
24
+ Create a token at: https://gitlab.com/-/profile/personal_access_tokens
25
+ Required scopes: `read_api`, `read_repository`
26
+
27
+ 3. **Prepare your GitLab repo** with a `prompts/` folder containing `.md` files:
28
+ ```
29
+ your-gitlab-repo/
30
+ └── prompts/
31
+ ├── assessments-result-feed.md
32
+ └── other-prompt.md
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ After publishing to npm:
38
+ ```bash
39
+ npx -y fetch-angular-prompts
40
+ ```
41
+
42
+ This creates a `prompts/` folder in the current directory with all `.md` files from your GitLab repo.
43
+
44
+ ## Publishing
45
+
46
+ ### To npm:
47
+ ```bash
48
+ npm login
49
+ npm publish
50
+ ```
51
+
52
+ ### Or use from GitHub:
53
+ Push this package to GitHub, then users can run:
54
+ ```bash
55
+ npx github:youruser/your-repo
56
+ ```
57
+
58
+ ## Local Testing
59
+
60
+ ```bash
61
+ # Install dependencies
62
+ npm install
63
+
64
+ # Make bin/index.js executable
65
+ chmod +x bin/index.js
66
+
67
+ # Create .env with your token (for private repos)
68
+ cp .env.example .env
69
+ # Edit .env and add your GITLAB_TOKEN
70
+
71
+ # Test locally
72
+ npm link
73
+ npx -y fetch-angular-prompts
74
+
75
+ # Or run directly
76
+ node bin/index.js
77
+ ```
78
+
79
+ ## GitLab Repository Structure
80
+
81
+ Your GitLab repo should have:
82
+ ```
83
+ prompts/
84
+ ├── assessments-result-feed.md
85
+ ├── another-route.md
86
+ └── more-prompts.md
87
+ ```
88
+
89
+ All `.md` files in the `prompts/` folder will be downloaded.
package/bin/index.js ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ const https = require('https');
3
+ const http = require('http');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const dotenv = require('dotenv');
7
+
8
+ // Load .env from package directory (where this script lives)
9
+ const envPath = path.join(__dirname, '..', '.env');
10
+ if (fs.existsSync(envPath)) {
11
+ dotenv.config({ path: envPath });
12
+ }
13
+
14
+ // Configuration - update these with your GitLab details
15
+ const GITLAB_PROJECT = 'nagavadlapudi/prompt-manager'; // e.g., 'john/angular-prompts'
16
+ const GITLAB_BRANCH = 'main'; // or 'master'
17
+ const PROMPTS_PATH = 'prompts'; // folder in your GitLab repo
18
+ const GITLAB_HOST = 'gitlab.com'; // or your self-hosted GitLab domain
19
+
20
+ // GitLab token from .env file or environment variable
21
+ const GITLAB_TOKEN = process.env.GITLAB_TOKEN || '';
22
+
23
+ function downloadFile(url, destPath, token = '') {
24
+ return new Promise((resolve, reject) => {
25
+ const protocol = url.startsWith('https') ? https : http;
26
+ const options = {
27
+ headers: token ? { 'PRIVATE-TOKEN': token } : {}
28
+ };
29
+
30
+ protocol.get(url, options, (res) => {
31
+ if (res.statusCode === 302 || res.statusCode === 301) {
32
+ // Follow redirect
33
+ return downloadFile(res.headers.location, destPath, token)
34
+ .then(resolve)
35
+ .catch(reject);
36
+ }
37
+
38
+ if (res.statusCode !== 200) {
39
+ reject(new Error(`Failed to download: ${res.statusCode} ${url}`));
40
+ return;
41
+ }
42
+
43
+ const dir = path.dirname(destPath);
44
+ fs.mkdirSync(dir, { recursive: true });
45
+
46
+ const file = fs.createWriteStream(destPath);
47
+ res.pipe(file);
48
+ file.on('finish', () => {
49
+ file.close();
50
+ resolve();
51
+ });
52
+ }).on('error', reject);
53
+ });
54
+ }
55
+
56
+ async function fetchPrompts() {
57
+ try {
58
+ console.log('Fetching prompts from GitLab...');
59
+
60
+ // GitLab API: list files in directory
61
+ const apiUrl = `https://${GITLAB_HOST}/api/v4/projects/${encodeURIComponent(GITLAB_PROJECT)}/repository/tree?path=${PROMPTS_PATH}&ref=${GITLAB_BRANCH}`;
62
+
63
+ // Get list of files
64
+ const listResponse = await new Promise((resolve, reject) => {
65
+ const protocol = apiUrl.startsWith('https') ? https : http;
66
+ const options = {
67
+ headers: GITLAB_TOKEN ? { 'PRIVATE-TOKEN': GITLAB_TOKEN } : {}
68
+ };
69
+
70
+ protocol.get(apiUrl, options, (res) => {
71
+ let data = '';
72
+ res.on('data', chunk => data += chunk);
73
+ res.on('end', () => {
74
+ if (res.statusCode === 200) {
75
+ resolve(JSON.parse(data));
76
+ } else {
77
+ reject(new Error(`API error: ${res.statusCode} - ${data}`));
78
+ }
79
+ });
80
+ }).on('error', reject);
81
+ });
82
+
83
+ // Download each .md file
84
+ const mdFiles = listResponse.filter(item =>
85
+ item.type === 'blob' && item.name.endsWith('.md')
86
+ );
87
+
88
+ if (mdFiles.length === 0) {
89
+ console.log('No markdown files found in the prompts directory.');
90
+ return;
91
+ }
92
+
93
+ for (const file of mdFiles) {
94
+ // GitLab raw file URL
95
+ const rawUrl = `https://${GITLAB_HOST}/${GITLAB_PROJECT}/-/raw/${GITLAB_BRANCH}/${PROMPTS_PATH}/${file.name}`;
96
+ const destPath = path.join(process.cwd(), 'prompts', file.name);
97
+
98
+ console.log(`Downloading ${file.name}...`);
99
+ await downloadFile(rawUrl, destPath, GITLAB_TOKEN);
100
+ }
101
+
102
+ console.log(`\n✓ Downloaded ${mdFiles.length} prompt(s) to ./prompts/`);
103
+ console.log('Files:');
104
+ mdFiles.forEach(f => console.log(` - prompts/${f.name}`));
105
+
106
+ } catch (error) {
107
+ console.error('Error fetching prompts:', error.message);
108
+ console.error('\nPlease check:');
109
+ console.error('1. GITLAB_PROJECT is set correctly in bin/index.js');
110
+ console.error('2. Repository and branch exist');
111
+ console.error('3. For private repos, set GITLAB_TOKEN environment variable');
112
+ process.exit(1);
113
+ }
114
+ }
115
+
116
+ fetchPrompts();
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@naganpm/fetch-prompts",
3
+ "version": "1.0.0",
4
+ "description": "Fetch prompts from GitLab repository",
5
+ "bin": {
6
+ "fetch-prompts": "bin/index.js"
7
+ },
8
+ "keywords": ["prompts", "gitlab"],
9
+ "license": "MIT",
10
+ "engines": {
11
+ "node": ">=14"
12
+ },
13
+ "dependencies": {
14
+ "dotenv": "^16.0.0"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }
package/prompt.md ADDED
@@ -0,0 +1,6 @@
1
+ Create a child route from
2
+ localhost:4200/assessments
3
+ called
4
+ localhost:4200/assessments/result-feed
5
+ and point it to same component as
6
+ Localhost:4200/ecdo/result-feed