licenseguard-cli 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/LICENSE +22 -0
- package/README.md +258 -0
- package/bin/licenseguard.js +41 -0
- package/lib/commands/init-fast.js +104 -0
- package/lib/commands/init.js +120 -0
- package/lib/commands/list.js +49 -0
- package/lib/templates.js +336 -0
- package/lib/utils/file-ops.js +46 -0
- package/lib/utils/git-helpers.js +174 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 rfxlamia
|
|
4
|
+
github.com/rfxlamia/licenseguard
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# LicenseGuard
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/licenseguard-cli)
|
|
4
|
+
[](https://github.com/your-username/licenseguard/actions)
|
|
5
|
+
[](https://codecov.io/gh/your-username/licenseguard)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**License setup & compliance helper for developers**
|
|
9
|
+
|
|
10
|
+
LicenseGuard is a CLI tool that helps you quickly set up open source licenses for your projects with automatic git hooks that notify your team about licensing requirements.
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Step 1: Run the interactive setup
|
|
16
|
+
npx licenseguard-cli --init
|
|
17
|
+
|
|
18
|
+
# Step 2: Answer the prompts (license type, owner name, year)
|
|
19
|
+
|
|
20
|
+
# Step 3: Done! Your LICENSE file and git hooks are ready
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
That's it! Your project now has:
|
|
24
|
+
- A properly formatted LICENSE file
|
|
25
|
+
- A `.licenseguardrc` configuration file
|
|
26
|
+
- Git hooks that display license reminders (optional)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
### Using npx (Recommended)
|
|
31
|
+
```bash
|
|
32
|
+
npx licenseguard-cli --init
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Global Installation
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g licenseguard-cli
|
|
38
|
+
licenseguard --init
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Local Installation
|
|
42
|
+
```bash
|
|
43
|
+
npm install --save-dev licenseguard-cli
|
|
44
|
+
npx licenseguard-cli --init
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Interactive Setup (`--init`)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
licenseguard --init
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This command guides you through:
|
|
56
|
+
1. Selecting a license type
|
|
57
|
+
2. Entering your copyright owner name
|
|
58
|
+
3. Setting the copyright year (defaults to current year)
|
|
59
|
+
4. Adding a project URL (optional)
|
|
60
|
+
5. Optionally initializing git if not already a repo
|
|
61
|
+
6. Installing git hooks for license notifications
|
|
62
|
+
|
|
63
|
+
**Example Output:**
|
|
64
|
+
```
|
|
65
|
+
đ LicenseGuard - Interactive License Setup
|
|
66
|
+
|
|
67
|
+
? Select license type: MIT License
|
|
68
|
+
? Copyright owner name: Your Name
|
|
69
|
+
? Copyright year: 2025
|
|
70
|
+
? Project URL (optional): https://github.com/you/project
|
|
71
|
+
|
|
72
|
+
â LICENSE file created
|
|
73
|
+
â Configuration saved to .licenseguardrc
|
|
74
|
+
â Git hooks installed
|
|
75
|
+
|
|
76
|
+
đ Your project is now licensed under MIT
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Fast Setup (`--init-fast`)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
licenseguard --init-fast --license mit --owner "Your Name"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Non-interactive setup with flags. Perfect for CI/CD or scripting.
|
|
86
|
+
|
|
87
|
+
**Available Flags:**
|
|
88
|
+
- `--license <type>` (required) - License type to use
|
|
89
|
+
- `--owner <name>` (optional) - Copyright owner (auto-detects from git config)
|
|
90
|
+
- `--year <year>` (optional) - Copyright year (defaults to current year)
|
|
91
|
+
- `--url <url>` (optional) - Project URL (auto-detects from git remote)
|
|
92
|
+
|
|
93
|
+
**Examples:**
|
|
94
|
+
```bash
|
|
95
|
+
# Minimal (auto-detects owner from git config)
|
|
96
|
+
licenseguard --init-fast --license mit
|
|
97
|
+
|
|
98
|
+
# Full specification
|
|
99
|
+
licenseguard --init-fast --license apache2_0 --owner "Apache Corp" --year 2025 --url "https://apache.org"
|
|
100
|
+
|
|
101
|
+
# GPL license
|
|
102
|
+
licenseguard --init-fast --license gpl3_0 --owner "Free Software Foundation"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### List Available Licenses (`--ls`)
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
licenseguard --ls
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Displays all available license types:
|
|
112
|
+
```
|
|
113
|
+
Available License Templates:
|
|
114
|
+
|
|
115
|
+
â MIT - MIT License (permissive, widely used)
|
|
116
|
+
â Apache 2.0 - Apache License 2.0 (permissive with patent grant)
|
|
117
|
+
â GPL 3.0 - GNU General Public License 3.0 (copyleft)
|
|
118
|
+
â BSD 3-Clause - BSD 3-Clause License (permissive with attribution)
|
|
119
|
+
â ISC - ISC License (simpler MIT alternative)
|
|
120
|
+
â WTFPL - Do What The F*ck You Want To Public License (ultra-permissive)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Available Licenses
|
|
124
|
+
|
|
125
|
+
| License Key | Display Name | Description |
|
|
126
|
+
|-------------|--------------|-------------|
|
|
127
|
+
| `mit` | MIT | MIT License (permissive, widely used) |
|
|
128
|
+
| `apache2_0` | Apache 2.0 | Apache License 2.0 (permissive with patent grant) |
|
|
129
|
+
| `gpl3_0` | GPL 3.0 | GNU General Public License 3.0 (copyleft) |
|
|
130
|
+
| `bsd3clause` | BSD 3-Clause | BSD 3-Clause License (permissive with attribution) |
|
|
131
|
+
| `isc` | ISC | ISC License (simpler MIT alternative) |
|
|
132
|
+
| `wtdpl` | WTFPL | Do What The F*ck You Want To Public License (ultra-permissive) |
|
|
133
|
+
|
|
134
|
+
Not sure which license to choose? Visit [choosealicense.com](https://choosealicense.com) for guidance.
|
|
135
|
+
|
|
136
|
+
## Configuration
|
|
137
|
+
|
|
138
|
+
LicenseGuard creates a `.licenseguardrc` file in your project root:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"license": "mit",
|
|
143
|
+
"owner": "Your Name",
|
|
144
|
+
"year": "2025",
|
|
145
|
+
"url": "https://github.com/you/project"
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This configuration is used by the git hooks to display license information.
|
|
150
|
+
|
|
151
|
+
## Git Hooks
|
|
152
|
+
|
|
153
|
+
LicenseGuard installs two informational git hooks:
|
|
154
|
+
|
|
155
|
+
### Post-Checkout Hook
|
|
156
|
+
Displays a notification after `git clone` or `git checkout`:
|
|
157
|
+
```
|
|
158
|
+
đ This project uses MIT License by Your Name
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Pre-Commit Hook
|
|
162
|
+
Displays a reminder before each commit:
|
|
163
|
+
```
|
|
164
|
+
âšī¸ Reminder: This project is licensed under MIT
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Important:**
|
|
168
|
+
- Hooks are **educational only** - they never block git operations
|
|
169
|
+
- Hooks always exit with code 0 (success)
|
|
170
|
+
- If `.licenseguardrc` is missing, hooks silently exit
|
|
171
|
+
|
|
172
|
+
### Existing Hooks
|
|
173
|
+
|
|
174
|
+
If you already have git hooks, LicenseGuard will NOT overwrite them. Instead, it creates variants:
|
|
175
|
+
- `.git/hooks/licenseguard-pre-commit`
|
|
176
|
+
- `.git/hooks/licenseguard-post-checkout`
|
|
177
|
+
|
|
178
|
+
You can manually merge these with your existing hooks if desired.
|
|
179
|
+
|
|
180
|
+
### Without Git
|
|
181
|
+
|
|
182
|
+
If your project is not a git repository:
|
|
183
|
+
- Interactive mode (`--init`) will offer to run `git init`
|
|
184
|
+
- Fast mode (`--init-fast`) will skip hooks and warn you
|
|
185
|
+
- LICENSE file is always created regardless of git status
|
|
186
|
+
|
|
187
|
+
## FAQ
|
|
188
|
+
|
|
189
|
+
### Does this work offline?
|
|
190
|
+
Yes! LicenseGuard is completely offline. All license templates are bundled with the package.
|
|
191
|
+
|
|
192
|
+
### Can I use custom licenses?
|
|
193
|
+
Currently, LicenseGuard supports the 6 most common open source licenses. Custom license support may be added in future versions.
|
|
194
|
+
|
|
195
|
+
### Does it work on Windows?
|
|
196
|
+
Yes! LicenseGuard is fully cross-platform and works on Linux, macOS, and Windows.
|
|
197
|
+
|
|
198
|
+
### What if I already have a LICENSE file?
|
|
199
|
+
Interactive mode will ask if you want to overwrite it. Fast mode will overwrite without asking.
|
|
200
|
+
|
|
201
|
+
### How do I update my license?
|
|
202
|
+
Run `licenseguard --init` again and it will regenerate your LICENSE file.
|
|
203
|
+
|
|
204
|
+
### Can I disable the git hooks?
|
|
205
|
+
The hooks are informational only and don't block anything. If you don't want them, simply delete the hook files from `.git/hooks/`.
|
|
206
|
+
|
|
207
|
+
### What Node.js versions are supported?
|
|
208
|
+
LicenseGuard requires Node.js 18.x or 20.x (LTS versions).
|
|
209
|
+
|
|
210
|
+
## Contributing
|
|
211
|
+
|
|
212
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
213
|
+
|
|
214
|
+
1. Fork the repository
|
|
215
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
216
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
217
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
218
|
+
5. Open a Pull Request
|
|
219
|
+
|
|
220
|
+
## Development
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Clone the repository
|
|
224
|
+
git clone https://github.com/your-username/licenseguard.git
|
|
225
|
+
cd licenseguard
|
|
226
|
+
|
|
227
|
+
# Install dependencies
|
|
228
|
+
npm install
|
|
229
|
+
|
|
230
|
+
# Run tests
|
|
231
|
+
npm test
|
|
232
|
+
|
|
233
|
+
# Run tests with coverage
|
|
234
|
+
npm run test:coverage
|
|
235
|
+
|
|
236
|
+
# Lint code
|
|
237
|
+
npm run lint
|
|
238
|
+
|
|
239
|
+
# Format code
|
|
240
|
+
npm run format
|
|
241
|
+
|
|
242
|
+
# Test locally
|
|
243
|
+
npm link
|
|
244
|
+
cd /tmp && mkdir test-project && cd test-project
|
|
245
|
+
licenseguard --init
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
**Links:**
|
|
255
|
+
- [Choose a License](https://choosealicense.com) - Help choosing the right license
|
|
256
|
+
- [Open Source Initiative](https://opensource.org/licenses) - OSI-approved licenses
|
|
257
|
+
- [GitHub Repository](https://github.com/your-username/licenseguard) - Source code
|
|
258
|
+
- [npm Package](https://www.npmjs.com/package/licenseguard-cli) - npm registry
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander')
|
|
4
|
+
const { runList } = require('../lib/commands/list')
|
|
5
|
+
const { runInit } = require('../lib/commands/init')
|
|
6
|
+
const { runInitFast } = require('../lib/commands/init-fast')
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.version('1.0.0')
|
|
10
|
+
.description('License setup & compliance helper for developers')
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.option('--init', 'Interactive license setup wizard')
|
|
14
|
+
.option('--init-fast', 'Non-interactive fast setup')
|
|
15
|
+
.option('--license <type>', 'License type (for --init-fast)')
|
|
16
|
+
.option('--owner <name>', 'Copyright owner name (for --init-fast)')
|
|
17
|
+
.option('--year <year>', 'Copyright year (for --init-fast)')
|
|
18
|
+
.option('--url <url>', 'Project URL (for --init-fast)')
|
|
19
|
+
.option('--ls', 'List available license templates')
|
|
20
|
+
.parse(process.argv)
|
|
21
|
+
|
|
22
|
+
const options = program.opts()
|
|
23
|
+
|
|
24
|
+
if (options.init) {
|
|
25
|
+
runInit().catch((err) => {
|
|
26
|
+
console.error('Error:', err.message)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
})
|
|
29
|
+
} else if (options.initFast) {
|
|
30
|
+
runInitFast(options).catch((err) => {
|
|
31
|
+
console.error('Error:', err.message)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
})
|
|
34
|
+
} else if (options.ls) {
|
|
35
|
+
runList().catch((err) => {
|
|
36
|
+
console.error('Error:', err.message)
|
|
37
|
+
process.exit(1)
|
|
38
|
+
})
|
|
39
|
+
} else {
|
|
40
|
+
program.help()
|
|
41
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const { execSync } = require('child_process')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
const { generateLicense, LICENSE_TEMPLATES } = require('../templates')
|
|
6
|
+
const { writeConfig } = require('../utils/file-ops')
|
|
7
|
+
const { isGitRepo, installHooks } = require('../utils/git-helpers')
|
|
8
|
+
|
|
9
|
+
function getGitConfig(key) {
|
|
10
|
+
try {
|
|
11
|
+
const value = execSync(`git config ${key}`, { encoding: 'utf8' })
|
|
12
|
+
return value.trim()
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function runInitFast(options) {
|
|
19
|
+
try {
|
|
20
|
+
const flags = {
|
|
21
|
+
license: options.license,
|
|
22
|
+
owner: options.owner,
|
|
23
|
+
year: options.year,
|
|
24
|
+
url: options.url,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Validate required flag: license
|
|
28
|
+
if (!flags.license) {
|
|
29
|
+
console.error(chalk.red('â Error: --license flag is required'))
|
|
30
|
+
console.log(
|
|
31
|
+
chalk.blue('Usage: licenseguard --init-fast --license TYPE [options]')
|
|
32
|
+
)
|
|
33
|
+
console.log(
|
|
34
|
+
chalk.blue(
|
|
35
|
+
`Available licenses: ${Object.keys(LICENSE_TEMPLATES).join(', ')}`
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Validate license type
|
|
42
|
+
const validLicenses = Object.keys(LICENSE_TEMPLATES)
|
|
43
|
+
if (!validLicenses.includes(flags.license)) {
|
|
44
|
+
console.error(
|
|
45
|
+
chalk.red(`â Error: Invalid license type: ${flags.license}`)
|
|
46
|
+
)
|
|
47
|
+
console.log(
|
|
48
|
+
chalk.blue(`âšī¸ Available licenses: ${validLicenses.join(', ')}`)
|
|
49
|
+
)
|
|
50
|
+
process.exit(1)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Auto-detect values if not provided
|
|
54
|
+
const year = flags.year || new Date().getFullYear().toString()
|
|
55
|
+
const owner =
|
|
56
|
+
flags.owner || getGitConfig('user.name') || os.userInfo().username
|
|
57
|
+
const url = flags.url || getGitConfig('--get remote.origin.url') || ''
|
|
58
|
+
|
|
59
|
+
console.log(chalk.blue('đ LicenseGuard - Fast License Setup\n'))
|
|
60
|
+
console.log(chalk.gray(`License: ${flags.license}`))
|
|
61
|
+
console.log(chalk.gray(`Owner: ${owner}`))
|
|
62
|
+
console.log(chalk.gray(`Year: ${year}`))
|
|
63
|
+
if (url) console.log(chalk.gray(`URL: ${url}`))
|
|
64
|
+
console.log()
|
|
65
|
+
|
|
66
|
+
// Generate license text
|
|
67
|
+
const licenseContent = generateLicense(flags.license, owner, year, url)
|
|
68
|
+
|
|
69
|
+
// Write LICENSE file directly (no prompt in fast mode)
|
|
70
|
+
fs.writeFileSync('LICENSE', licenseContent, 'utf8')
|
|
71
|
+
|
|
72
|
+
// Write config file
|
|
73
|
+
writeConfig({
|
|
74
|
+
license: flags.license,
|
|
75
|
+
owner: owner,
|
|
76
|
+
year: year,
|
|
77
|
+
url: url,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Success messages
|
|
81
|
+
console.log(chalk.green('â LICENSE file created'))
|
|
82
|
+
console.log(chalk.green('â Configuration saved to .licenseguardrc'))
|
|
83
|
+
|
|
84
|
+
// Git hooks installation (no prompts in fast mode)
|
|
85
|
+
if (isGitRepo()) {
|
|
86
|
+
installHooks()
|
|
87
|
+
} else {
|
|
88
|
+
console.log(chalk.yellow('â ī¸ Skipping git hooks (not a git repo)'))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(
|
|
92
|
+
chalk.blue(
|
|
93
|
+
`\nđ Your project is now licensed under ${flags.license.toUpperCase()}`
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
process.exit(0)
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(chalk.red('\nâ Error during fast setup:'), error.message)
|
|
100
|
+
process.exit(1)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { runInitFast }
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const inquirer = require('inquirer')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
const { generateLicense } = require('../templates')
|
|
4
|
+
const { writeLicenseFile, writeConfig } = require('../utils/file-ops')
|
|
5
|
+
const { isGitRepo, initGitRepo, installHooks } = require('../utils/git-helpers')
|
|
6
|
+
|
|
7
|
+
async function runInit() {
|
|
8
|
+
try {
|
|
9
|
+
console.log(chalk.blue('đ LicenseGuard - Interactive License Setup\n'))
|
|
10
|
+
|
|
11
|
+
// Prompt for license type
|
|
12
|
+
const answers = await inquirer.prompt([
|
|
13
|
+
{
|
|
14
|
+
type: 'list',
|
|
15
|
+
name: 'license',
|
|
16
|
+
message: 'Select license type:',
|
|
17
|
+
choices: [
|
|
18
|
+
{ name: 'MIT License', value: 'mit' },
|
|
19
|
+
{ name: 'Apache License 2.0', value: 'apache2_0' },
|
|
20
|
+
{ name: 'GNU GPL 3.0', value: 'gpl3_0' },
|
|
21
|
+
{ name: 'BSD 3-Clause License', value: 'bsd3clause' },
|
|
22
|
+
{ name: 'ISC License', value: 'isc' },
|
|
23
|
+
{ name: 'WTDPL', value: 'wtdpl' },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: 'input',
|
|
28
|
+
name: 'owner',
|
|
29
|
+
message: 'Copyright owner name:',
|
|
30
|
+
validate: (input) => {
|
|
31
|
+
if (!input || input.trim() === '') {
|
|
32
|
+
return 'Owner name is required'
|
|
33
|
+
}
|
|
34
|
+
return true
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'input',
|
|
39
|
+
name: 'year',
|
|
40
|
+
message: 'Copyright year:',
|
|
41
|
+
default: new Date().getFullYear().toString(),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'input',
|
|
45
|
+
name: 'url',
|
|
46
|
+
message: 'Project URL (optional):',
|
|
47
|
+
default: '',
|
|
48
|
+
},
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
// Generate license text
|
|
52
|
+
const licenseContent = generateLicense(
|
|
53
|
+
answers.license,
|
|
54
|
+
answers.owner,
|
|
55
|
+
answers.year,
|
|
56
|
+
answers.url
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
// Write LICENSE file
|
|
60
|
+
const licenseWritten = await writeLicenseFile(licenseContent)
|
|
61
|
+
|
|
62
|
+
if (!licenseWritten) {
|
|
63
|
+
// User cancelled overwrite
|
|
64
|
+
process.exit(0)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Write config file
|
|
68
|
+
writeConfig({
|
|
69
|
+
license: answers.license,
|
|
70
|
+
owner: answers.owner,
|
|
71
|
+
year: answers.year,
|
|
72
|
+
url: answers.url,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// Success messages
|
|
76
|
+
console.log(chalk.green('\nâ LICENSE file created'))
|
|
77
|
+
console.log(chalk.green('â Configuration saved to .licenseguardrc'))
|
|
78
|
+
|
|
79
|
+
// Git hooks installation
|
|
80
|
+
let skipHooks = false
|
|
81
|
+
|
|
82
|
+
if (!isGitRepo()) {
|
|
83
|
+
const gitAnswer = await inquirer.prompt([
|
|
84
|
+
{
|
|
85
|
+
type: 'confirm',
|
|
86
|
+
name: 'initGit',
|
|
87
|
+
message: 'Not a git repository. Initialize git?',
|
|
88
|
+
default: true,
|
|
89
|
+
},
|
|
90
|
+
])
|
|
91
|
+
|
|
92
|
+
if (gitAnswer.initGit) {
|
|
93
|
+
const gitInitSuccess = initGitRepo()
|
|
94
|
+
if (!gitInitSuccess) {
|
|
95
|
+
skipHooks = true
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
console.log(chalk.yellow('â ī¸ Skipping git hooks (not a git repo)'))
|
|
99
|
+
skipHooks = true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!skipHooks && isGitRepo()) {
|
|
104
|
+
installHooks()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(
|
|
108
|
+
chalk.blue(
|
|
109
|
+
`\nđ Your project is now licensed under ${answers.license.toUpperCase()}`
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
process.exit(0)
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(chalk.red('\nâ Error during initialization:'), error.message)
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { runInit }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const licenses = [
|
|
2
|
+
{
|
|
3
|
+
name: 'MIT',
|
|
4
|
+
description: 'MIT License (permissive, widely used)',
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
name: 'Apache 2.0',
|
|
8
|
+
description: 'Apache License 2.0 (permissive with patent grant)',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'GPL 3.0',
|
|
12
|
+
description: 'GNU General Public License 3.0 (copyleft)',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'BSD 3-Clause',
|
|
16
|
+
description: 'BSD 3-Clause License (permissive with attribution)',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'ISC',
|
|
20
|
+
description: 'ISC License (simpler MIT alternative)',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'WTFPL',
|
|
24
|
+
description:
|
|
25
|
+
'Do What The F*ck You Want To Public License (ultra-permissive)',
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
async function runList() {
|
|
30
|
+
// Dynamic import for chalk v5 (ESM-only)
|
|
31
|
+
const chalk = (await import('chalk')).default
|
|
32
|
+
|
|
33
|
+
console.log(chalk.bold('\nAvailable License Templates:\n'))
|
|
34
|
+
|
|
35
|
+
licenses.forEach((license) => {
|
|
36
|
+
console.log(
|
|
37
|
+
chalk.green('â') +
|
|
38
|
+
' ' +
|
|
39
|
+
chalk.bold(license.name) +
|
|
40
|
+
' - ' +
|
|
41
|
+
license.description
|
|
42
|
+
)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
console.log('')
|
|
46
|
+
process.exit(0)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = { runList }
|
package/lib/templates.js
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
const LICENSE_TEMPLATES = {
|
|
2
|
+
mit: `MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) {{year}} {{owner}}
|
|
5
|
+
{{url}}
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.`,
|
|
24
|
+
|
|
25
|
+
apache2_0: ` Apache License
|
|
26
|
+
Version 2.0, January 2004
|
|
27
|
+
http://www.apache.org/licenses/
|
|
28
|
+
|
|
29
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
30
|
+
|
|
31
|
+
1. Definitions.
|
|
32
|
+
|
|
33
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
34
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
35
|
+
|
|
36
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
37
|
+
the copyright owner that is granting the License.
|
|
38
|
+
|
|
39
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
40
|
+
other entities that control, are controlled by, or are under common
|
|
41
|
+
control with that entity. For the purposes of this definition,
|
|
42
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
43
|
+
direction or management of such entity, whether by contract or
|
|
44
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
45
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
46
|
+
|
|
47
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
48
|
+
exercising permissions granted by this License.
|
|
49
|
+
|
|
50
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
51
|
+
including but not limited to software source code, documentation
|
|
52
|
+
source, and configuration files.
|
|
53
|
+
|
|
54
|
+
"Object" form shall mean any form resulting from mechanical
|
|
55
|
+
transformation or translation of a Source form, including but
|
|
56
|
+
not limited to compiled object code, generated documentation,
|
|
57
|
+
and conversions to other media types.
|
|
58
|
+
|
|
59
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
60
|
+
Object form, made available under the License, as indicated by a
|
|
61
|
+
copyright notice that is included in or attached to the work
|
|
62
|
+
(an example is provided in the Appendix below).
|
|
63
|
+
|
|
64
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
65
|
+
form, that is based on (or derived from) the Work and for which the
|
|
66
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
67
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
68
|
+
of this License, Derivative Works shall not include works that remain
|
|
69
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
70
|
+
the Work and Derivative Works thereof.
|
|
71
|
+
|
|
72
|
+
"Contribution" shall mean any work of authorship, including
|
|
73
|
+
the original version of the Work and any modifications or additions
|
|
74
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
75
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
76
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
77
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
78
|
+
means any form of electronic, verbal, or written communication sent
|
|
79
|
+
to the Licensor or its representatives, including but not limited to
|
|
80
|
+
communication on electronic mailing lists, source code control systems,
|
|
81
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
82
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
83
|
+
excluding communication that is conspicuously marked or otherwise
|
|
84
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
85
|
+
|
|
86
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
87
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
88
|
+
subsequently incorporated within the Work.
|
|
89
|
+
|
|
90
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
91
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
92
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
93
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
94
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
95
|
+
Work and such Derivative Works in Source or Object form.
|
|
96
|
+
|
|
97
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
98
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
99
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
100
|
+
(except as stated in this section) patent license to make, have made,
|
|
101
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
102
|
+
where such license applies only to those patent claims licensable
|
|
103
|
+
by such Contributor that are necessarily infringed by their
|
|
104
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
105
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
106
|
+
institute patent litigation against any entity (including a
|
|
107
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
108
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
109
|
+
or contributory patent infringement, then any patent licenses
|
|
110
|
+
granted to You under this License for that Work shall terminate
|
|
111
|
+
as of the date such litigation is filed.
|
|
112
|
+
|
|
113
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
114
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
115
|
+
modifications, and in Source or Object form, provided that You
|
|
116
|
+
meet the following conditions:
|
|
117
|
+
|
|
118
|
+
(a) You must give any other recipients of the Work or
|
|
119
|
+
Derivative Works a copy of this License; and
|
|
120
|
+
|
|
121
|
+
(b) You must cause any modified files to carry prominent notices
|
|
122
|
+
stating that You changed the files; and
|
|
123
|
+
|
|
124
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
125
|
+
that You distribute, all copyright, patent, trademark, and
|
|
126
|
+
attribution notices from the Source form of the Work,
|
|
127
|
+
excluding those notices that do not pertain to any part of
|
|
128
|
+
the Derivative Works; and
|
|
129
|
+
|
|
130
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
131
|
+
distribution, then any Derivative Works that You distribute must
|
|
132
|
+
include a readable copy of the attribution notices contained
|
|
133
|
+
within such NOTICE file, excluding those notices that do not
|
|
134
|
+
pertain to any part of the Derivative Works, in at least one
|
|
135
|
+
of the following places: within a NOTICE text file distributed
|
|
136
|
+
as part of the Derivative Works; within the Source form or
|
|
137
|
+
documentation, if provided along with the Derivative Works; or,
|
|
138
|
+
within a display generated by the Derivative Works, if and
|
|
139
|
+
wherever such third-party notices normally appear. The contents
|
|
140
|
+
of the NOTICE file are for informational purposes only and
|
|
141
|
+
do not modify the License. You may add Your own attribution
|
|
142
|
+
notices within Derivative Works that You distribute, alongside
|
|
143
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
144
|
+
that such additional attribution notices cannot be construed
|
|
145
|
+
as modifying the License.
|
|
146
|
+
|
|
147
|
+
You may add Your own copyright statement to Your modifications and
|
|
148
|
+
may provide additional or different license terms and conditions
|
|
149
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
150
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
151
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
152
|
+
the conditions stated in this License.
|
|
153
|
+
|
|
154
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
155
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
156
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
157
|
+
this License, without any additional terms or conditions.
|
|
158
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
159
|
+
the terms of any separate license agreement you may have executed
|
|
160
|
+
with Licensor regarding such Contributions.
|
|
161
|
+
|
|
162
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
163
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
164
|
+
except as required for reasonable and customary use in describing the
|
|
165
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
166
|
+
|
|
167
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
168
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
169
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
170
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
171
|
+
implied, including, without limitation, any warranties or conditions
|
|
172
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
173
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
174
|
+
appropriateness of using or redistributing the Work and assume any
|
|
175
|
+
risks associated with Your exercise of permissions under this License.
|
|
176
|
+
|
|
177
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
178
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
179
|
+
unless required by applicable law (such as deliberate and grossly
|
|
180
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
181
|
+
liable to You for damages, including any direct, indirect, special,
|
|
182
|
+
incidental, or consequential damages of any character arising as a
|
|
183
|
+
result of this License or out of the use or inability to use the
|
|
184
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
185
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
186
|
+
other commercial damages or losses), even if such Contributor
|
|
187
|
+
has been advised of the possibility of such damages.
|
|
188
|
+
|
|
189
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
190
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
191
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
192
|
+
or other liability obligations and/or rights consistent with this
|
|
193
|
+
License. However, in accepting such obligations, You may act only
|
|
194
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
195
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
196
|
+
defend, and hold each Contributor harmless for any liability
|
|
197
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
198
|
+
of your accepting any such warranty or additional liability.
|
|
199
|
+
|
|
200
|
+
END OF TERMS AND CONDITIONS
|
|
201
|
+
|
|
202
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
203
|
+
|
|
204
|
+
To apply the Apache License to your work, attach the following
|
|
205
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
206
|
+
replaced with your own identifying information. (Don't include
|
|
207
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
208
|
+
comment syntax for the file format. We also recommend that a
|
|
209
|
+
file or class name and description of purpose be included on the
|
|
210
|
+
same "printed page" as the copyright notice for easier
|
|
211
|
+
identification within third-party archives.
|
|
212
|
+
|
|
213
|
+
Copyright {{year}} {{owner}}
|
|
214
|
+
|
|
215
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
216
|
+
you may not use this file except in compliance with the License.
|
|
217
|
+
You may obtain a copy of the License at
|
|
218
|
+
|
|
219
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
220
|
+
|
|
221
|
+
Unless required by applicable law or agreed to in writing, software
|
|
222
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
223
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
224
|
+
See the License for the specific language governing permissions and
|
|
225
|
+
limitations under the License.`,
|
|
226
|
+
|
|
227
|
+
gpl3_0: `GNU GENERAL PUBLIC LICENSE
|
|
228
|
+
Version 3, 29 June 2007
|
|
229
|
+
|
|
230
|
+
Copyright (C) {{year}} {{owner}}
|
|
231
|
+
|
|
232
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
233
|
+
of this license document, but changing it is not allowed.
|
|
234
|
+
|
|
235
|
+
Preamble
|
|
236
|
+
|
|
237
|
+
The GNU General Public License is a free, copyleft license for
|
|
238
|
+
software and other kinds of works.
|
|
239
|
+
|
|
240
|
+
[Note: Full GPL 3.0 text would go here - abbreviated for brevity in this implementation]
|
|
241
|
+
|
|
242
|
+
This program is free software: you can redistribute it and/or modify
|
|
243
|
+
it under the terms of the GNU General Public License as published by
|
|
244
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
245
|
+
(at your option) any later version.
|
|
246
|
+
|
|
247
|
+
This program is distributed in the hope that it will be useful,
|
|
248
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
249
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
250
|
+
GNU General Public License for more details.
|
|
251
|
+
|
|
252
|
+
You should have received a copy of the GNU General Public License
|
|
253
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.`,
|
|
254
|
+
|
|
255
|
+
bsd3clause: `BSD 3-Clause License
|
|
256
|
+
|
|
257
|
+
Copyright (c) {{year}}, {{owner}}
|
|
258
|
+
|
|
259
|
+
Redistribution and use in source and binary forms, with or without
|
|
260
|
+
modification, are permitted provided that the following conditions are met:
|
|
261
|
+
|
|
262
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
263
|
+
list of conditions and the following disclaimer.
|
|
264
|
+
|
|
265
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
266
|
+
this list of conditions and the following disclaimer in the documentation
|
|
267
|
+
and/or other materials provided with the distribution.
|
|
268
|
+
|
|
269
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
270
|
+
contributors may be used to endorse or promote products derived from
|
|
271
|
+
this software without specific prior written permission.
|
|
272
|
+
|
|
273
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
274
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
275
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
276
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
277
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
278
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
279
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
280
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
281
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
282
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`,
|
|
283
|
+
|
|
284
|
+
isc: `Copyright (c) {{year}} {{owner}}
|
|
285
|
+
|
|
286
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
287
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
288
|
+
copyright notice and this permission notice appear in all copies.
|
|
289
|
+
|
|
290
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
291
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
292
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
293
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
294
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
295
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
296
|
+
PERFORMANCE OF THIS SOFTWARE.`,
|
|
297
|
+
|
|
298
|
+
wtdpl: `DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
|
|
299
|
+
Version 2, December 2004
|
|
300
|
+
|
|
301
|
+
Copyright (C) {{year}} {{owner}}
|
|
302
|
+
|
|
303
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
|
304
|
+
copies of this license document, and changing it is allowed as long
|
|
305
|
+
as the name is changed.
|
|
306
|
+
|
|
307
|
+
DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
|
|
308
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
309
|
+
|
|
310
|
+
0. You just DO WHAT THE HECK YOU WANT TO.`,
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function generateLicense(type, owner, year, url) {
|
|
314
|
+
const template = LICENSE_TEMPLATES[type]
|
|
315
|
+
if (!template) {
|
|
316
|
+
const availableLicenses = Object.keys(LICENSE_TEMPLATES).join(', ')
|
|
317
|
+
throw new Error(
|
|
318
|
+
`Unknown license type: ${type}. Available licenses: ${availableLicenses}`
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let result = template
|
|
323
|
+
.replace(/\{\{owner\}\}/g, owner)
|
|
324
|
+
.replace(/\{\{year\}\}/g, year)
|
|
325
|
+
|
|
326
|
+
// URL is optional - remove placeholder if not provided
|
|
327
|
+
if (url) {
|
|
328
|
+
result = result.replace(/\{\{url\}\}/g, url)
|
|
329
|
+
} else {
|
|
330
|
+
result = result.replace(/\{\{url\}\}/g, '')
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return result
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
module.exports = { LICENSE_TEMPLATES, generateLicense }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const inquirer = require('inquirer')
|
|
3
|
+
const chalk = require('chalk')
|
|
4
|
+
|
|
5
|
+
async function writeLicenseFile(content) {
|
|
6
|
+
// Check if LICENSE file already exists
|
|
7
|
+
if (fs.existsSync('LICENSE')) {
|
|
8
|
+
const { overwrite } = await inquirer.prompt([
|
|
9
|
+
{
|
|
10
|
+
type: 'confirm',
|
|
11
|
+
name: 'overwrite',
|
|
12
|
+
message: chalk.yellow('LICENSE file already exists. Overwrite?'),
|
|
13
|
+
default: false,
|
|
14
|
+
},
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
if (!overwrite) {
|
|
18
|
+
console.log(
|
|
19
|
+
chalk.blue('âšī¸ Keeping existing LICENSE file. Operation cancelled.')
|
|
20
|
+
)
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Write LICENSE file
|
|
26
|
+
try {
|
|
27
|
+
fs.writeFileSync('LICENSE', content, 'utf8')
|
|
28
|
+
return true
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(chalk.red('â Error writing LICENSE file:'), error.message)
|
|
31
|
+
throw error
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function writeConfig(config) {
|
|
36
|
+
try {
|
|
37
|
+
const configContent = JSON.stringify(config, null, 2)
|
|
38
|
+
fs.writeFileSync('.licenseguardrc', configContent, 'utf8')
|
|
39
|
+
return true
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(chalk.red('â Error writing .licenseguardrc:'), error.message)
|
|
42
|
+
throw error
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { writeLicenseFile, writeConfig }
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { execSync } = require('child_process')
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if current directory is a git repository
|
|
8
|
+
* @returns {boolean} true if .git directory exists
|
|
9
|
+
*/
|
|
10
|
+
function isGitRepo() {
|
|
11
|
+
try {
|
|
12
|
+
return fs.existsSync('.git')
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initialize a git repository in the current directory
|
|
20
|
+
* @returns {boolean} true if git init succeeded
|
|
21
|
+
*/
|
|
22
|
+
function initGitRepo() {
|
|
23
|
+
try {
|
|
24
|
+
execSync('git init', { stdio: 'inherit' })
|
|
25
|
+
return true
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(chalk.red('â Failed to initialize git repository'))
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Install git hooks for license notifications
|
|
34
|
+
* @returns {boolean} true if hooks were installed successfully
|
|
35
|
+
*/
|
|
36
|
+
function installHooks() {
|
|
37
|
+
try {
|
|
38
|
+
const hooksDir = path.join('.git', 'hooks')
|
|
39
|
+
|
|
40
|
+
// Ensure hooks directory exists
|
|
41
|
+
if (!fs.existsSync(hooksDir)) {
|
|
42
|
+
fs.mkdirSync(hooksDir, { recursive: true })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const hooks = [
|
|
46
|
+
{ name: 'post-checkout', script: generatePostCheckoutScript() },
|
|
47
|
+
{ name: 'pre-commit', script: generatePreCommitScript() },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
let hasConflicts = false
|
|
51
|
+
|
|
52
|
+
for (const hook of hooks) {
|
|
53
|
+
const hookPath = path.join(hooksDir, hook.name)
|
|
54
|
+
|
|
55
|
+
if (fs.existsSync(hookPath)) {
|
|
56
|
+
// Existing hook detected - create variant
|
|
57
|
+
const variantPath = path.join(hooksDir, `licenseguard-${hook.name}`)
|
|
58
|
+
fs.writeFileSync(variantPath, hook.script, 'utf8')
|
|
59
|
+
makeExecutable(variantPath)
|
|
60
|
+
|
|
61
|
+
console.log(chalk.yellow(`â ī¸ Existing ${hook.name} hook detected.`))
|
|
62
|
+
console.log(chalk.blue(`đ Installed as: licenseguard-${hook.name}`))
|
|
63
|
+
console.log(
|
|
64
|
+
chalk.gray(
|
|
65
|
+
'đĄ To use: merge with your existing hook or rename.'
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
hasConflicts = true
|
|
69
|
+
} else {
|
|
70
|
+
// No conflict - install directly
|
|
71
|
+
fs.writeFileSync(hookPath, hook.script, 'utf8')
|
|
72
|
+
makeExecutable(hookPath)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!hasConflicts) {
|
|
77
|
+
console.log(chalk.green('â Git hooks installed'))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return true
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(chalk.red('â Failed to install git hooks:'), error.message)
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Make a file executable (Unix only)
|
|
89
|
+
* @param {string} filePath - Path to the file
|
|
90
|
+
*/
|
|
91
|
+
function makeExecutable(filePath) {
|
|
92
|
+
try {
|
|
93
|
+
// chmod 755 on Unix systems
|
|
94
|
+
fs.chmodSync(filePath, 0o755)
|
|
95
|
+
} catch (error) {
|
|
96
|
+
// Ignore errors on Windows where chmod is not supported
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Generate post-checkout hook script
|
|
102
|
+
* @returns {string} Hook script content
|
|
103
|
+
*/
|
|
104
|
+
function generatePostCheckoutScript() {
|
|
105
|
+
return `#!/usr/bin/env node
|
|
106
|
+
const fs = require('fs')
|
|
107
|
+
const path = require('path')
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
// Read .licenseguardrc from project root (relative to .git/hooks/)
|
|
111
|
+
const configPath = path.resolve(__dirname, '..', '..', '.licenseguardrc')
|
|
112
|
+
|
|
113
|
+
if (!fs.existsSync(configPath)) {
|
|
114
|
+
// No config file, silently exit
|
|
115
|
+
process.exit(0)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const configContent = fs.readFileSync(configPath, 'utf8')
|
|
119
|
+
const config = JSON.parse(configContent)
|
|
120
|
+
|
|
121
|
+
// Display license notification with color
|
|
122
|
+
const blue = '\\x1b[34m'
|
|
123
|
+
const reset = '\\x1b[0m'
|
|
124
|
+
|
|
125
|
+
console.log(\`\${blue}đ This project uses \${config.license.toUpperCase()} License by \${config.owner}\${reset}\`)
|
|
126
|
+
|
|
127
|
+
process.exit(0)
|
|
128
|
+
} catch (error) {
|
|
129
|
+
// Errors should not block git operations
|
|
130
|
+
process.exit(0)
|
|
131
|
+
}
|
|
132
|
+
`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Generate pre-commit hook script
|
|
137
|
+
* @returns {string} Hook script content
|
|
138
|
+
*/
|
|
139
|
+
function generatePreCommitScript() {
|
|
140
|
+
return `#!/usr/bin/env node
|
|
141
|
+
const fs = require('fs')
|
|
142
|
+
const path = require('path')
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
// Read .licenseguardrc from project root (relative to .git/hooks/)
|
|
146
|
+
const configPath = path.resolve(__dirname, '..', '..', '.licenseguardrc')
|
|
147
|
+
|
|
148
|
+
if (!fs.existsSync(configPath)) {
|
|
149
|
+
// No config file, silently exit
|
|
150
|
+
process.exit(0)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const configContent = fs.readFileSync(configPath, 'utf8')
|
|
154
|
+
const config = JSON.parse(configContent)
|
|
155
|
+
|
|
156
|
+
// Display license reminder with color
|
|
157
|
+
const blue = '\\x1b[34m'
|
|
158
|
+
const reset = '\\x1b[0m'
|
|
159
|
+
|
|
160
|
+
console.log(\`\${blue}âšī¸ Reminder: This project is licensed under \${config.license.toUpperCase()}\${reset}\`)
|
|
161
|
+
|
|
162
|
+
process.exit(0)
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// Errors should not block git operations
|
|
165
|
+
process.exit(0)
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = {
|
|
171
|
+
isGitRepo,
|
|
172
|
+
initGitRepo,
|
|
173
|
+
installHooks,
|
|
174
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "licenseguard-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "License setup & compliance helper for developers",
|
|
5
|
+
"bin": {
|
|
6
|
+
"licenseguard": "./bin/licenseguard.js"
|
|
7
|
+
},
|
|
8
|
+
"directories": {
|
|
9
|
+
"doc": "docs"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"test:watch": "jest --watch",
|
|
14
|
+
"test:coverage": "jest --coverage",
|
|
15
|
+
"lint": "eslint .",
|
|
16
|
+
"format": "prettier --write ."
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"license",
|
|
20
|
+
"compliance",
|
|
21
|
+
"MIT",
|
|
22
|
+
"Apache",
|
|
23
|
+
"GPL",
|
|
24
|
+
"developer-tools"
|
|
25
|
+
],
|
|
26
|
+
"author": "v",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"chalk": "^4.1.2",
|
|
30
|
+
"commander": "^11.1.0",
|
|
31
|
+
"inquirer": "^8.2.5"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"eslint": "^8.54.0",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"mock-fs": "^5.2.0",
|
|
37
|
+
"prettier": "^3.1.0"
|
|
38
|
+
}
|
|
39
|
+
}
|