-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 946bdf2
Showing
7 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish to npm | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*.*.*' # Publish only on version tags | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '14' | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Publish to npm | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npm publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Node.js dependencies | ||
node_modules | ||
npm-debug.log | ||
yarn-error.log | ||
package-lock.json | ||
yarn.lock | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# macOS files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Hydra-JS CLI | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
- Node.js (v14 or later) | ||
- npm (v7 or later) | ||
|
||
### Setup | ||
|
||
```bash | ||
git clone [email protected]:hydra-js/cli.git hydra-cli | ||
cd hydra-cli | ||
npm install | ||
``` | ||
|
||
### Running locally | ||
|
||
To run the CLI tool locally without installing it globally, use: | ||
|
||
```bash | ||
node index.js init [appName] | ||
``` | ||
|
||
### Running locally with `npm link` | ||
|
||
> This section provides instructions on how to use `npm link` for local development, enabling you to test the CLI tool as if it were installed globally. | ||
|
||
To link the CLI tool locally for development and testing, use `npm link`: | ||
|
||
1. Run `npm link` in the project directory. This creates a symlink globally: | ||
|
||
```bash | ||
npm link | ||
``` | ||
|
||
2. Now you can run the `hydra` command from anywhere on your system: | ||
|
||
```bash | ||
hydra init [appName] | ||
``` | ||
|
||
This allows you to test changes to the CLI tool without needing to reinstall it each time you make modifications. | ||
|
||
### Publishing | ||
|
||
To publish the package to npm: | ||
|
||
1. Ensure you are logged in to npm: | ||
|
||
```bash | ||
npm login | ||
``` | ||
|
||
2. Make sure the NPM_TOKEN secret is added to your GitHub repository. | ||
|
||
3. Create a new version tag and push it to GitHub: | ||
|
||
```bash | ||
git tag v1.0.0 | ||
git push origin v1.0.0 | ||
``` | ||
|
||
The GitHub Actions workflow will automatically publish the package to npm when a new tag is pushed. | ||
|
||
### Contributing | ||
|
||
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas. | ||
|
||
### License | ||
|
||
This project is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
describe('CLI', () => { | ||
test('init command', () => { | ||
// Run the init command | ||
const output = execSync('node ../index.js init my-hydra-app').toString(); | ||
|
||
// Verify output | ||
expect(output).toContain('Project my-hydra-app generated successfully.'); | ||
expect(output).toContain('Repository cloned successfully.'); | ||
expect(output).toContain('Subdirectory copied successfully.'); | ||
expect(output).toContain('Cleanup completed.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env node | ||
|
||
const { Command } = require('commander'); | ||
const simpleGit = require('simple-git'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
|
||
const program = new Command(); | ||
const git = simpleGit(); | ||
|
||
const pkg = require('./package.json'); | ||
|
||
const templateRepoUrl = 'https://github.com/hydra-js/monorepo'; | ||
const subdirectory = 'packages/server-nodejs'; | ||
|
||
program.name('hydra').description(pkg.description).version(pkg.version); | ||
|
||
program | ||
.command('init [appName]') | ||
.description( | ||
'Initialize a Hydra App' | ||
) | ||
.action(async (appName = 'my-hydra-app') => { | ||
const tempRepoPath = path.join(process.cwd(), appName, '__tmp'); | ||
const appPath = path.join(process.cwd(), appName); | ||
|
||
if (fs.existsSync(appPath)) { | ||
console.error(`Error: Directory ${appName} already exists.`); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
console.log(`Cloning repository from ${templateRepoUrl}...`); | ||
await git.clone(templateRepoUrl, tempRepoPath); | ||
console.log('Repository cloned successfully.'); | ||
|
||
const sourcePath = path.join(tempRepoPath, subdirectory); | ||
|
||
if (!fs.existsSync(sourcePath)) { | ||
throw new Error( | ||
`Subdirectory ${subdirectory} does not exist in the repository.` | ||
); | ||
} | ||
|
||
console.log(`Copying ${subdirectory} to ${appName}...`); | ||
await fs.copy(sourcePath, appPath); | ||
console.log('Subdirectory copied successfully.'); | ||
|
||
// @TODO: Make necessory changes | ||
|
||
console.log('Cleaning up temporary files...'); | ||
await fs.remove(tempRepoPath); | ||
console.log('Cleanup completed.'); | ||
|
||
console.log(`Project ${appName} generated successfully.`); | ||
} catch (err) { | ||
console.error('Failed to generate project:', err); | ||
await fs.remove(tempRepoPath); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@hydra-js/cli", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Hydra-JS Command-line Toolkit", | ||
"bin": { | ||
"hydra": "./index.js" | ||
}, | ||
"scripts": { | ||
"start": "node index.js", | ||
"test": "jest" | ||
}, | ||
"keywords": [ | ||
"hydra", | ||
"hydra-js", | ||
"cli" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:hydra-js/cli.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "heimdallrj", | ||
"email": "[email protected]", | ||
"url": "https://github.com/heimdallrj" | ||
} | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"commander": "^12.1.0", | ||
"fs-extra": "^11.2.0", | ||
"simple-git": "^3.24.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"jest": "^29.7.0" | ||
} | ||
} |