create-skweb 1.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.
Files changed (74) hide show
  1. package/.turbo/turbo-build.log +17 -0
  2. package/.turbo/turbo-check.log +4 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/.turbo/turbo-test.log +65 -0
  5. package/CHANGELOG.md +7 -0
  6. package/dist/cli.d.ts +3 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +199 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/index.cjs +115 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +12 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +102 -0
  15. package/dist/index.js.map +1 -0
  16. package/package.json +54 -0
  17. package/rollup.config.mjs +71 -0
  18. package/src/cli.ts +118 -0
  19. package/src/index.ts +122 -0
  20. package/templates/cjs/ecosystem.config.js +32 -0
  21. package/templates/cjs/eslint.config.js +25 -0
  22. package/templates/cjs/package.json +46 -0
  23. package/templates/cjs/src/app.js +91 -0
  24. package/templates/cjs/src/commands/migrate.js +35 -0
  25. package/templates/cjs/src/commands/seed.js +58 -0
  26. package/templates/cjs/src/controllers/hello.js +33 -0
  27. package/templates/cjs/src/controllers/user.js +101 -0
  28. package/templates/cjs/src/cronActions/cleanup.js +12 -0
  29. package/templates/cjs/src/cronWorker.js +85 -0
  30. package/templates/cjs/src/index.js +7 -0
  31. package/templates/cjs/src/models/SysUser.js +38 -0
  32. package/templates/cjs/src/seeds/SysUser.json +1 -0
  33. package/templates/cjs/src/services/database.js +15 -0
  34. package/templates/cjs/src/utils/config.js +65 -0
  35. package/templates/cjs/src/utils/logger.js +53 -0
  36. package/templates/cjs/test/index.js +13 -0
  37. package/templates/mjs/ecosystem.config.js +32 -0
  38. package/templates/mjs/eslint.config.js +25 -0
  39. package/templates/mjs/package.json +46 -0
  40. package/templates/mjs/src/app.js +97 -0
  41. package/templates/mjs/src/commands/migrate.js +38 -0
  42. package/templates/mjs/src/commands/seed.js +63 -0
  43. package/templates/mjs/src/controllers/hello.js +33 -0
  44. package/templates/mjs/src/controllers/user.js +101 -0
  45. package/templates/mjs/src/cronActions/cleanup.js +9 -0
  46. package/templates/mjs/src/cronWorker.js +91 -0
  47. package/templates/mjs/src/index.js +8 -0
  48. package/templates/mjs/src/models/SysUser.js +40 -0
  49. package/templates/mjs/src/seeds/SysUser.json +1 -0
  50. package/templates/mjs/src/services/database.js +16 -0
  51. package/templates/mjs/src/utils/config.js +63 -0
  52. package/templates/mjs/src/utils/logger.js +52 -0
  53. package/templates/mjs/test/index.mjs +13 -0
  54. package/templates/ts/ecosystem.config.js +36 -0
  55. package/templates/ts/eslint.config.js +17 -0
  56. package/templates/ts/package.json +57 -0
  57. package/templates/ts/rollup.config.mjs +39 -0
  58. package/templates/ts/src/app.ts +96 -0
  59. package/templates/ts/src/commands/migrate.ts +38 -0
  60. package/templates/ts/src/commands/seed.ts +63 -0
  61. package/templates/ts/src/controllers/hello.ts +33 -0
  62. package/templates/ts/src/controllers/user.ts +101 -0
  63. package/templates/ts/src/cronActions/cleanup.ts +10 -0
  64. package/templates/ts/src/cronWorker.ts +90 -0
  65. package/templates/ts/src/index.ts +8 -0
  66. package/templates/ts/src/models/SysUser.ts +49 -0
  67. package/templates/ts/src/seeds/SysUser.json +1 -0
  68. package/templates/ts/src/services/database.ts +16 -0
  69. package/templates/ts/src/utils/config.ts +68 -0
  70. package/templates/ts/src/utils/logger.ts +63 -0
  71. package/templates/ts/test/index.mjs +13 -0
  72. package/templates/ts/tsconfig.json +20 -0
  73. package/test/index.mjs +137 -0
  74. package/tsconfig.json +22 -0
package/test/index.mjs ADDED
@@ -0,0 +1,137 @@
1
+ import { expect } from 'chai'
2
+ import path from 'path'
3
+ import fs from 'fs-extra'
4
+ import os from 'os'
5
+ import { fileURLToPath } from 'url'
6
+ import { createProject, printBanner, printSuccess } from '../dist/index.js'
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = path.dirname(__filename)
10
+
11
+ describe('create-skweb', () => {
12
+ describe('createProject()', () => {
13
+ let tmpDir
14
+
15
+ beforeEach(() => {
16
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'create-skweb-test-'))
17
+ })
18
+
19
+ afterEach(() => {
20
+ fs.removeSync(tmpDir)
21
+ })
22
+
23
+ it('should create TypeScript project from template', async () => {
24
+ await createProject({
25
+ name: 'my-app',
26
+ template: 'ts',
27
+ dest: tmpDir
28
+ })
29
+
30
+ expect(fs.existsSync(path.join(tmpDir, 'package.json'))).to.be.true
31
+ expect(fs.existsSync(path.join(tmpDir, 'src', 'app.ts'))).to.be.true
32
+ expect(fs.existsSync(path.join(tmpDir, 'src', 'utils', 'logger.ts'))).to.be.true
33
+ })
34
+
35
+ it('should create MJS project from template', async () => {
36
+ await createProject({
37
+ name: 'my-app',
38
+ template: 'mjs',
39
+ dest: tmpDir
40
+ })
41
+
42
+ expect(fs.existsSync(path.join(tmpDir, 'package.json'))).to.be.true
43
+ expect(fs.existsSync(path.join(tmpDir, 'src', 'app.js'))).to.be.true
44
+ })
45
+
46
+ it('should create CJS project from template', async () => {
47
+ await createProject({
48
+ name: 'my-app',
49
+ template: 'cjs',
50
+ dest: tmpDir
51
+ })
52
+
53
+ expect(fs.existsSync(path.join(tmpDir, 'package.json'))).to.be.true
54
+ expect(fs.existsSync(path.join(tmpDir, 'src', 'app.js'))).to.be.true
55
+ })
56
+
57
+ it('should reject non-empty destination directory', async () => {
58
+ // 在 tmpDir 中创建一个文件
59
+ fs.writeFileSync(path.join(tmpDir, 'existing.txt'), 'x')
60
+
61
+ try {
62
+ await createProject({
63
+ name: 'my-app',
64
+ template: 'ts',
65
+ dest: tmpDir
66
+ })
67
+ expect.fail('should have thrown')
68
+ } catch (err) {
69
+ expect(err.message).to.match(/不为空/)
70
+ }
71
+ })
72
+
73
+ it('should include winston in all templates', async () => {
74
+ for (const template of ['ts', 'mjs', 'cjs']) {
75
+ fs.removeSync(tmpDir)
76
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'create-skweb-test-'))
77
+ await createProject({
78
+ name: 'my-app',
79
+ template,
80
+ dest: tmpDir
81
+ })
82
+ const pkg = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'))
83
+ expect(pkg.dependencies.winston, `${template} should have winston dep`).to.exist
84
+ }
85
+ })
86
+
87
+ it('should include @dotenvx/dotenvx in all templates', async () => {
88
+ for (const template of ['ts', 'mjs', 'cjs']) {
89
+ fs.removeSync(tmpDir)
90
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'create-skweb-test-'))
91
+ await createProject({
92
+ name: 'my-app',
93
+ template,
94
+ dest: tmpDir
95
+ })
96
+ const pkg = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'))
97
+ expect(pkg.dependencies['@dotenvx/dotenvx'], `${template} should have dotenvx`).to.exist
98
+ }
99
+ })
100
+
101
+ it('should include pm2 ecosystem in all templates', async () => {
102
+ for (const template of ['ts', 'mjs', 'cjs']) {
103
+ fs.removeSync(tmpDir)
104
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'create-skweb-test-'))
105
+ await createProject({
106
+ name: 'my-app',
107
+ template,
108
+ dest: tmpDir
109
+ })
110
+ expect(fs.existsSync(path.join(tmpDir, 'ecosystem.config.js')), `${template} should have pm2 ecosystem`).to.be.true
111
+ }
112
+ })
113
+
114
+ it('should replace {{name}} placeholder in package.json', async () => {
115
+ await createProject({
116
+ name: 'my-custom-app',
117
+ template: 'ts',
118
+ dest: tmpDir
119
+ })
120
+ const pkg = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'))
121
+ expect(pkg.name).to.equal('my-custom-app')
122
+ expect(pkg.name).to.not.match(/\{\{name\}\}/)
123
+ })
124
+ })
125
+
126
+ describe('printBanner()', () => {
127
+ it('should not throw', () => {
128
+ expect(() => printBanner()).to.not.throw()
129
+ })
130
+ })
131
+
132
+ describe('printSuccess()', () => {
133
+ it('should not throw', () => {
134
+ expect(() => printSuccess('my-app', '/tmp/my-app')).to.not.throw()
135
+ })
136
+ })
137
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ES2020"],
6
+ "moduleResolution": "Node",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "resolveJsonModule": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "rootDir": "src",
16
+ "outDir": "dist",
17
+ "baseUrl": ".",
18
+ "types": ["node"]
19
+ },
20
+ "include": ["src/**/*.ts"],
21
+ "exclude": ["node_modules", "dist", "test", "templates"]
22
+ }