@marcuth/create-package 0.1.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 +21 -0
- package/bin/index.js +451 -0
- package/package.json +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcuth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import { spawnSync } from "child_process"
|
|
6
|
+
|
|
7
|
+
function getInputName() {
|
|
8
|
+
return process.argv[2] || "my-package"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parsePackageName(inputName) {
|
|
12
|
+
if (inputName.startsWith("@")) {
|
|
13
|
+
if (!inputName.includes("/")) {
|
|
14
|
+
console.error("❌ Invalid scope. Use @scope/name")
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const [, name] = inputName.split("/")
|
|
19
|
+
return {
|
|
20
|
+
packageName: inputName,
|
|
21
|
+
projectDir: name
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
packageName: inputName,
|
|
27
|
+
projectDir: inputName
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createDirectories(root) {
|
|
32
|
+
fs.mkdirSync(root, { recursive: true })
|
|
33
|
+
fs.mkdirSync(path.join(root, "src"))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function writePackageJson(root, packageName) {
|
|
37
|
+
const content = {
|
|
38
|
+
name: packageName,
|
|
39
|
+
version: "0.1.0",
|
|
40
|
+
type: "commonjs",
|
|
41
|
+
main: "./dist/index.js",
|
|
42
|
+
module: "./dist/index.js",
|
|
43
|
+
types: "./dist/index.d.ts",
|
|
44
|
+
files: [
|
|
45
|
+
"dist/*",
|
|
46
|
+
"!/**/__tests__"
|
|
47
|
+
],
|
|
48
|
+
scripts: {
|
|
49
|
+
build: "tsc",
|
|
50
|
+
dev: "ts-node ./src/index.ts"
|
|
51
|
+
},
|
|
52
|
+
keywords: [
|
|
53
|
+
"marcuth"
|
|
54
|
+
],
|
|
55
|
+
author: "Marcuth",
|
|
56
|
+
license: "MIT"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fs.writeFileSync(
|
|
60
|
+
path.join(root, "package.json"),
|
|
61
|
+
JSON.stringify(content, null, 2)
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function writeTsConfig(root) {
|
|
66
|
+
const content = {
|
|
67
|
+
"compilerOptions": {
|
|
68
|
+
"target": "es2019",
|
|
69
|
+
"lib": ["ES2015"],
|
|
70
|
+
"module": "NodeNext",
|
|
71
|
+
"esModuleInterop": true,
|
|
72
|
+
"forceConsistentCasingInFileNames": true,
|
|
73
|
+
"strict": true,
|
|
74
|
+
"skipLibCheck": true,
|
|
75
|
+
"outDir": "./dist",
|
|
76
|
+
"rootDir": "./src",
|
|
77
|
+
"declaration": true,
|
|
78
|
+
"declarationMap": false,
|
|
79
|
+
},
|
|
80
|
+
"include": ["src"],
|
|
81
|
+
"exclude": ["node_modules", "dist"]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
fs.writeFileSync(
|
|
86
|
+
path.join(root, "tsconfig.json"),
|
|
87
|
+
JSON.stringify(content, null, 2)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function writeSourceFile(root, projectDir) {
|
|
92
|
+
const content = `export function hello() {
|
|
93
|
+
return "Hello from ${projectDir}"
|
|
94
|
+
}
|
|
95
|
+
`
|
|
96
|
+
|
|
97
|
+
fs.writeFileSync(
|
|
98
|
+
path.join(root, "src/index.ts"),
|
|
99
|
+
content
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function writeLicenseFile(root) {
|
|
104
|
+
const currentYear = new Date().getFullYear()
|
|
105
|
+
|
|
106
|
+
const content = `MIT License
|
|
107
|
+
|
|
108
|
+
Copyright (c) ${currentYear} Marcuth
|
|
109
|
+
|
|
110
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
111
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
112
|
+
in the Software without restriction, including without limitation the rights
|
|
113
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
114
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
115
|
+
furnished to do so, subject to the following conditions:
|
|
116
|
+
|
|
117
|
+
The above copyright notice and this permission notice shall be included in all
|
|
118
|
+
copies or substantial portions of the Software.
|
|
119
|
+
|
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
121
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
122
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
123
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
124
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
125
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
126
|
+
SOFTWARE.`
|
|
127
|
+
|
|
128
|
+
fs.writeFileSync(
|
|
129
|
+
path.join(root, "LICENSE"),
|
|
130
|
+
content
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function writeGitignoreFile(root) {
|
|
135
|
+
const content = `# Created by https://www.toptal.com/developers/gitignore/api/node
|
|
136
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
|
137
|
+
|
|
138
|
+
### Node ###
|
|
139
|
+
# Logs
|
|
140
|
+
dist/
|
|
141
|
+
logs
|
|
142
|
+
*.log
|
|
143
|
+
npm-debug.log*
|
|
144
|
+
yarn-debug.log*
|
|
145
|
+
yarn-error.log*
|
|
146
|
+
lerna-debug.log*
|
|
147
|
+
.pnpm-debug.log*
|
|
148
|
+
|
|
149
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
150
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
151
|
+
|
|
152
|
+
# Runtime data
|
|
153
|
+
pids
|
|
154
|
+
*.pid
|
|
155
|
+
*.seed
|
|
156
|
+
*.pid.lock
|
|
157
|
+
|
|
158
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
159
|
+
lib-cov
|
|
160
|
+
|
|
161
|
+
# Coverage directory used by tools like istanbul
|
|
162
|
+
coverage
|
|
163
|
+
*.lcov
|
|
164
|
+
|
|
165
|
+
# nyc test coverage
|
|
166
|
+
.nyc_output
|
|
167
|
+
|
|
168
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
169
|
+
.grunt
|
|
170
|
+
|
|
171
|
+
# Bower dependency directory (https://bower.io/)
|
|
172
|
+
bower_components
|
|
173
|
+
|
|
174
|
+
# node-waf configuration
|
|
175
|
+
.lock-wscript
|
|
176
|
+
|
|
177
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
178
|
+
build/Release
|
|
179
|
+
|
|
180
|
+
# Dependency directories
|
|
181
|
+
node_modules/
|
|
182
|
+
jspm_packages/
|
|
183
|
+
|
|
184
|
+
# Snowpack dependency directory (https://snowpack.dev/)
|
|
185
|
+
web_modules/
|
|
186
|
+
|
|
187
|
+
# TypeScript cache
|
|
188
|
+
*.tsbuildinfo
|
|
189
|
+
|
|
190
|
+
# Optional npm cache directory
|
|
191
|
+
.npm
|
|
192
|
+
|
|
193
|
+
# Optional eslint cache
|
|
194
|
+
.eslintcache
|
|
195
|
+
|
|
196
|
+
# Optional stylelint cache
|
|
197
|
+
.stylelintcache
|
|
198
|
+
|
|
199
|
+
# Microbundle cache
|
|
200
|
+
.rpt2_cache/
|
|
201
|
+
.rts2_cache_cjs/
|
|
202
|
+
.rts2_cache_es/
|
|
203
|
+
.rts2_cache_umd/
|
|
204
|
+
|
|
205
|
+
# Optional REPL history
|
|
206
|
+
.node_repl_history
|
|
207
|
+
|
|
208
|
+
# Output of 'npm pack'
|
|
209
|
+
*.tgz
|
|
210
|
+
|
|
211
|
+
# Yarn Integrity file
|
|
212
|
+
.yarn-integrity
|
|
213
|
+
|
|
214
|
+
# dotenv environment variable files
|
|
215
|
+
.env
|
|
216
|
+
.env.development.local
|
|
217
|
+
.env.test.local
|
|
218
|
+
.env.production.local
|
|
219
|
+
.env.local
|
|
220
|
+
|
|
221
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
222
|
+
.cache
|
|
223
|
+
.parcel-cache
|
|
224
|
+
|
|
225
|
+
# Next.js build output
|
|
226
|
+
.next
|
|
227
|
+
out
|
|
228
|
+
|
|
229
|
+
# Nuxt.js build / generate output
|
|
230
|
+
.nuxt
|
|
231
|
+
dist
|
|
232
|
+
|
|
233
|
+
# Gatsby files
|
|
234
|
+
.cache/
|
|
235
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
236
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
237
|
+
# public
|
|
238
|
+
|
|
239
|
+
# vuepress build output
|
|
240
|
+
.vuepress/dist
|
|
241
|
+
|
|
242
|
+
# vuepress v2.x temp and cache directory
|
|
243
|
+
.temp
|
|
244
|
+
|
|
245
|
+
# Docusaurus cache and generated files
|
|
246
|
+
.docusaurus
|
|
247
|
+
|
|
248
|
+
# Serverless directories
|
|
249
|
+
.serverless/
|
|
250
|
+
|
|
251
|
+
# FuseBox cache
|
|
252
|
+
.fusebox/
|
|
253
|
+
|
|
254
|
+
# DynamoDB Local files
|
|
255
|
+
.dynamodb/
|
|
256
|
+
|
|
257
|
+
# TernJS port file
|
|
258
|
+
.tern-port
|
|
259
|
+
|
|
260
|
+
# Stores VSCode versions used for testing VSCode extensions
|
|
261
|
+
.vscode-test
|
|
262
|
+
|
|
263
|
+
# yarn v2
|
|
264
|
+
.yarn/cache
|
|
265
|
+
.yarn/unplugged
|
|
266
|
+
.yarn/build-state.yml
|
|
267
|
+
.yarn/install-state.gz
|
|
268
|
+
.pnp.*
|
|
269
|
+
|
|
270
|
+
### Node Patch ###
|
|
271
|
+
# Serverless Webpack directories
|
|
272
|
+
.webpack/
|
|
273
|
+
|
|
274
|
+
# Optional stylelint cache
|
|
275
|
+
|
|
276
|
+
# SvelteKit build / generate output
|
|
277
|
+
.svelte-kit
|
|
278
|
+
|
|
279
|
+
# End of https://www.toptal.com/developers/gitignore/api/node`
|
|
280
|
+
|
|
281
|
+
fs.writeFileSync(
|
|
282
|
+
path.join(root, ".gitignore"),
|
|
283
|
+
content
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function createNpmIgnore(root) {
|
|
288
|
+
const content = `src/
|
|
289
|
+
tsconfig.json`
|
|
290
|
+
|
|
291
|
+
fs.writeFileSync(
|
|
292
|
+
path.join(root, ".npmignore"),
|
|
293
|
+
content
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function createReadme(root, packageName) {
|
|
298
|
+
const content = `# ${packageName}`
|
|
299
|
+
|
|
300
|
+
fs.writeFileSync(
|
|
301
|
+
path.join(root, "README.md"),
|
|
302
|
+
content
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function createEsLintRcConfig(root) {
|
|
307
|
+
const content = {
|
|
308
|
+
"extends": [
|
|
309
|
+
"plugin:prettier/recommended"
|
|
310
|
+
],
|
|
311
|
+
"plugins": [
|
|
312
|
+
"prettier"
|
|
313
|
+
],
|
|
314
|
+
"rules": {
|
|
315
|
+
"prettier/prettier": "error"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
fs.writeFileSync(
|
|
320
|
+
path.join(root, ".eslintrc.json"),
|
|
321
|
+
JSON.stringify(content, null, 4)
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function createPrettierConfig(root) {
|
|
326
|
+
const content = `module.exports = {
|
|
327
|
+
"semi": false,
|
|
328
|
+
"singleQuote": false,
|
|
329
|
+
"tabWidth": 4,
|
|
330
|
+
"useTabs": false,
|
|
331
|
+
"importTypeOrder": ["NPMPackages", "localImports"],
|
|
332
|
+
"newlineBetweenTypes": true,
|
|
333
|
+
"sortingMethod": "lineLength",
|
|
334
|
+
"plugins": ["./node_modules/prettier-plugin-sort-imports/dist/index.js"],
|
|
335
|
+
"endOfLine": "auto",
|
|
336
|
+
"printWidth": 120
|
|
337
|
+
}`
|
|
338
|
+
|
|
339
|
+
fs.writeFileSync(
|
|
340
|
+
path.join(root, ".prettierrc.js"),
|
|
341
|
+
content
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function detectPackageManager() {
|
|
346
|
+
const userAgent = process.env.npm_config_user_agent || ""
|
|
347
|
+
|
|
348
|
+
if (userAgent.includes("pnpm")) return "pnpm"
|
|
349
|
+
if (userAgent.includes("yarn")) return "yarn"
|
|
350
|
+
|
|
351
|
+
return "npm"
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function installDevDependencies(root, deps) {
|
|
355
|
+
const pm = detectPackageManager()
|
|
356
|
+
|
|
357
|
+
const commands = {
|
|
358
|
+
npm: ["install", "--save-dev", ...deps],
|
|
359
|
+
pnpm: ["add", "-D", ...deps],
|
|
360
|
+
yarn: ["add", "-D", ...deps]
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
console.log("📦 Installing dev dependencies using", pm)
|
|
364
|
+
|
|
365
|
+
const result = spawnSync(
|
|
366
|
+
pm,
|
|
367
|
+
commands[pm],
|
|
368
|
+
{
|
|
369
|
+
cwd: root,
|
|
370
|
+
stdio: "inherit"
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
if (result.status !== 0) {
|
|
375
|
+
console.error("❌ Failed to install dev dependencies")
|
|
376
|
+
process.exit(1)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function hasGit() {
|
|
381
|
+
const result = spawnSync("git", ["--version"], { stdio: "ignore" })
|
|
382
|
+
return result.status === 0
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function initGitRepo(root) {
|
|
386
|
+
if (!hasGit()) {
|
|
387
|
+
console.log("⚠️ Git not found, skipping git init")
|
|
388
|
+
return
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
console.log("🌱 Initializing git repository")
|
|
392
|
+
|
|
393
|
+
const result = spawnSync(
|
|
394
|
+
"git",
|
|
395
|
+
["init"],
|
|
396
|
+
{
|
|
397
|
+
cwd: root,
|
|
398
|
+
stdio: "inherit"
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
if (result.status !== 0) {
|
|
403
|
+
console.error("❌ Falha ao inicializar git")
|
|
404
|
+
process.exit(1)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function createInitialCommit(root) {
|
|
409
|
+
console.log("📸 Creating initial commit")
|
|
410
|
+
|
|
411
|
+
spawnSync("git", ["add", "."], {
|
|
412
|
+
cwd: root,
|
|
413
|
+
stdio: "inherit"
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
spawnSync(
|
|
417
|
+
"git",
|
|
418
|
+
["commit", "-m", "chore: initial commit"],
|
|
419
|
+
{
|
|
420
|
+
cwd: root,
|
|
421
|
+
stdio: "inherit"
|
|
422
|
+
}
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function main() {
|
|
427
|
+
const inputName = getInputName()
|
|
428
|
+
const { packageName, projectDir } = parsePackageName(inputName)
|
|
429
|
+
const root = path.resolve(process.cwd(), projectDir)
|
|
430
|
+
const devDependencies = ["@types/node", "ts-node", "typescript", "prettier", "prettier-plugin-sort-imports", "eslint", "eslint-config-prettier", "eslint-plugin-prettier"]
|
|
431
|
+
|
|
432
|
+
createDirectories(root)
|
|
433
|
+
writePackageJson(root, packageName)
|
|
434
|
+
writeTsConfig(root)
|
|
435
|
+
writeSourceFile(root, projectDir)
|
|
436
|
+
writeLicenseFile(root)
|
|
437
|
+
writeGitignoreFile(root)
|
|
438
|
+
installDevDependencies(devDependencies)
|
|
439
|
+
initGitRepo(root)
|
|
440
|
+
createNpmIgnore(root)
|
|
441
|
+
createReadme(root, packageName)
|
|
442
|
+
createEsLintRcConfig(root)
|
|
443
|
+
createPrettierConfig(root)
|
|
444
|
+
createInitialCommit(root)
|
|
445
|
+
|
|
446
|
+
console.log("✅ Creeated project")
|
|
447
|
+
console.log("📦 Package:", packageName)
|
|
448
|
+
console.log("📁 Folder:", projectDir)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
main()
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@marcuth/create-package",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new package",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-package": "./bin/index.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": ["package generator"],
|
|
11
|
+
"author": "Marcuth",
|
|
12
|
+
"license": "MIT"
|
|
13
|
+
}
|