@marcuth/create-package 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marcuth/create-package",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Create a new package",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",
@@ -19,4 +19,4 @@
19
19
  ],
20
20
  "author": "Marcuth",
21
21
  "license": "MIT"
22
- }
22
+ }
package/src/index.js CHANGED
@@ -12,7 +12,8 @@ import {
12
12
  createNpmIgnore,
13
13
  createReadme,
14
14
  createEsLintRcConfig,
15
- createPrettierConfig
15
+ createPrettierConfig,
16
+ writeTestFile
16
17
  } from "./writers.js"
17
18
  import { installDevDependencies, initGitRepo, createInitialCommit } from "./system.js"
18
19
 
@@ -39,7 +40,9 @@ export async function main() {
39
40
  "eslint",
40
41
  "eslint-config-prettier",
41
42
  "eslint-plugin-prettier",
42
- "eslint-plugin-unused-imports"
43
+ "eslint-plugin-unused-imports",
44
+ "vitest",
45
+ "@vitest/coverage-v8"
43
46
  ]
44
47
 
45
48
  createDirectories(root)
@@ -55,6 +58,7 @@ export async function main() {
55
58
  createReadme(root, packageName)
56
59
  createEsLintRcConfig(root)
57
60
  createPrettierConfig(root)
61
+ writeTestFile(root)
58
62
  createInitialCommit(root)
59
63
 
60
64
  console.log("✅ Creeated project")
package/src/writers.js CHANGED
@@ -4,6 +4,7 @@ import path from "node:path"
4
4
  export function createDirectories(root) {
5
5
  fs.mkdirSync(root, { recursive: true })
6
6
  fs.mkdirSync(path.join(root, "src"))
7
+ fs.mkdirSync(path.join(root, "__tests__"))
7
8
  }
8
9
 
9
10
  export function writePackageJson(root, packageName, repoUrl = "") {
@@ -42,7 +43,9 @@ export function writePackageJson(root, packageName, repoUrl = "") {
42
43
  build: "tsc",
43
44
  dev: "ts-node ./src/index.ts",
44
45
  format: "prettier --write \"src/**/*.ts\"",
45
- lint: "eslint \"src/**/*.ts\" --fix"
46
+ lint: "eslint \"src/**/*.ts\" --fix",
47
+ test: "vitest",
48
+ "test:cov": "vitest run --coverage"
46
49
  },
47
50
  publishConfig: {
48
51
  access: "public"
@@ -86,7 +89,7 @@ export function writeTsConfig(root) {
86
89
  }
87
90
 
88
91
  export function writeSourceFile(root, projectDir) {
89
- const content = `function main() {
92
+ const content = `export function main() {
90
93
  console.log("Hello from ${projectDir}")
91
94
  }
92
95
 
@@ -99,6 +102,21 @@ main()
99
102
  )
100
103
  }
101
104
 
105
+ export function writeTestFile(root) {
106
+ const content = `import { expect, test } from "vitest"
107
+ import { main } from "../src/index"
108
+
109
+ test("main should be a function", () => {
110
+ expect(typeof main).toBe("function")
111
+ })
112
+ `
113
+
114
+ fs.writeFileSync(
115
+ path.join(root, "__tests__/index.test.ts"),
116
+ content
117
+ )
118
+ }
119
+
102
120
  export function writeLicenseFile(root) {
103
121
  const currentYear = new Date().getFullYear()
104
122