|
1 | 1 | const spawn = require("cross-spawn"); |
2 | 2 | const validate = require("validate-npm-package-name"); |
| 3 | +const serializePackage = require("./utils/serializePackage"); |
| 4 | +const serializeTSConfig = require("./utils/serializeTSConfig"); |
3 | 5 |
|
4 | 6 | module.exports = { |
5 | 7 | prompts: require("./prompts"), |
6 | 8 | templateData() { |
7 | 9 | const tsconfig = { |
8 | | - includes: ['\t\t"./src"'] |
| 10 | + compilerOptions: { |
| 11 | + outDir: "./lib", |
| 12 | + target: "esnext", |
| 13 | + moduleResolution: "node", |
| 14 | + module: "esnext", |
| 15 | + jsx: "react", |
| 16 | + skipLibCheck: true, |
| 17 | + lib: ["dom", "es6"], |
| 18 | + experimentalDecorators: true, |
| 19 | + declaration: true, |
| 20 | + sourceMap: true, |
| 21 | + removeComments: true, |
| 22 | + noImplicitAny: false, |
| 23 | + noImplicitThis: true, |
| 24 | + noImplicitReturns: true, |
| 25 | + noFallthroughCasesInSwitch: true, |
| 26 | + esModuleInterop: true, |
| 27 | + allowSyntheticDefaultImports: true |
| 28 | + }, |
| 29 | + exclude: ["node_modules"], |
| 30 | + includes: ["./src"] |
| 31 | + }; |
| 32 | + const package = { |
| 33 | + name: this.answers.name, |
| 34 | + description: this.answers.description, |
| 35 | + version: "0.0.1", |
| 36 | + main: "lib/index.js", |
| 37 | + module: "lib/index.es.js", |
| 38 | + types: "lib/index.d.ts", |
| 39 | + files: ["lib"], |
| 40 | + publishConfig: { access: "public" }, |
| 41 | + keywords: [], |
| 42 | + author: "", |
| 43 | + contributors: [], |
| 44 | + repository: "", |
| 45 | + license: "MIT", |
| 46 | + scripts: [ |
| 47 | + { build: "rm -rf ./lib/** && tsx" }, |
| 48 | + { watch: "tsc -- --watch" } |
| 49 | + ], |
| 50 | + dependencies: [], |
| 51 | + devDependencies: [ |
| 52 | + { "@babel/cli": "^7.2.3" }, |
| 53 | + { "@babel/core": "^7.3.4" }, |
| 54 | + { "@babel/plugin-proposal-class-properties": "^7.3.4" }, |
| 55 | + { "@babel/plugin-proposal-decorators": "^7.4.4" }, |
| 56 | + { "@babel/plugin-proposal-object-rest-spread": "^7.3.4" }, |
| 57 | + { "@babel/plugin-transform-typescript": "^7.3.2" }, |
| 58 | + { "@babel/preset-env": "^7.3.4" }, |
| 59 | + { "@babel/preset-typescript": "^7.3.3" }, |
| 60 | + { "@types/hoist-non-react-statics": "^3.3.1" }, |
| 61 | + { "@types/react": "^16.8.5" }, |
| 62 | + { "@types/react-dom": "^16.8.2" }, |
| 63 | + { lodash: "^4.17.15" }, |
| 64 | + { tslint: "^5.13.0" }, |
| 65 | + { "tslint-config-prettier": "^1.18.0" }, |
| 66 | + { "tslint-react": "^3.6.0" }, |
| 67 | + { typescript: "^3.3.3333" }, |
| 68 | + { react: "*" }, |
| 69 | + { "react-dom": "*" } |
| 70 | + ], |
| 71 | + peerDependencies: [{ react: "*" }, { "react-dom": "*" }] |
9 | 72 | }; |
10 | | - const scripts = [ |
11 | | - '\t\t"build": "rm -rf ./lib/** && tsc"', |
12 | | - '\t\t"watch": "tsc -- --watch"' |
13 | | - ]; |
14 | | - if (this.answers.tests) { |
15 | | - tsconfig.includes.push('\t\t"./__tests__"'); |
16 | | - scripts.push('\t\t"test": "jest"'); |
17 | | - } else { |
18 | | - scripts.push( |
19 | | - '\t\t"test": "echo \\"Warn: No test specified\\" && exit 0"' |
20 | | - ); |
21 | | - } |
22 | | - if (this.answers.semanticrelease) { |
23 | | - scripts.push( |
24 | | - '\t\t"semantic-release": "semantic-release"', |
25 | | - '\t\t"cz": "git-cz"' |
26 | | - ); |
27 | | - } |
28 | | - |
29 | | - if (this.answers.travis) { |
30 | | - scripts.push('\t\t"travis-deploy-once": "travis-deploy-once"'); |
31 | | - } |
32 | | - |
33 | | - const devDependencies = [ |
34 | | - '\t\t"@babel/cli": "^7.2.3"', |
35 | | - '\t\t"@babel/core": "^7.3.4"', |
36 | | - '\t\t"@babel/plugin-proposal-class-properties": "^7.3.4"', |
37 | | - '\t\t"@babel/plugin-proposal-decorators": "^7.4.4"', |
38 | | - '\t\t"@babel/plugin-proposal-object-rest-spread": "^7.3.4"', |
39 | | - '\t\t"@babel/plugin-transform-typescript": "^7.3.2"', |
40 | | - '\t\t"@babel/preset-env": "^7.3.4"', |
41 | | - '\t\t"@babel/preset-typescript": "^7.3.3"', |
42 | | - '\t\t"@types/hoist-non-react-statics": "^3.3.1"', |
43 | | - '\t\t"@types/react": "^16.8.5"', |
44 | | - '\t\t"@types/react-dom": "^16.8.2"', |
45 | | - '\t\t"lodash": "^4.17.15"', |
46 | | - '\t\t"tslint": "^5.13.0"', |
47 | | - '\t\t"tslint-config-prettier": "^1.18.0"', |
48 | | - '\t\t"tslint-react": "^3.6.0"', |
49 | | - '\t\t"typescript": "^3.3.3333"', |
50 | | - '\t\t"react": "*"', |
51 | | - '\t\t"react-dom": "*"' |
52 | | - ]; |
53 | | - |
54 | | - const peerDependencies = ['\t\t"react": "*"', '\t\t"react-dom": "*"']; |
55 | | - |
56 | | - const dependencies = []; |
57 | 73 |
|
58 | 74 | if (this.answers.tests) { |
59 | | - devDependencies.push( |
60 | | - '\t\t"@types/enzyme": "^3.10.3"', |
61 | | - '\t\t"@types/jest": "^24.0.9"', |
62 | | - '\t\t"@types/enzyme-adapter-react-16": "^1.0.5"', |
63 | | - '\t\t"react-test-renderer": "^16.8.6"', |
64 | | - '\t\t"jest": "^24.1.0"', |
65 | | - '\t\t"enzyme": "^3.10.0"', |
66 | | - '\t\t"enzyme-adapter-react-16": "^1.10.0"', |
67 | | - '\t\t"ts-jest": "^24.0.0"' |
| 75 | + tsconfig.includes.push("./__tests__"); |
| 76 | + package.scripts.push({ test: "jest" }); |
| 77 | + package.devDependencies.push( |
| 78 | + { "@types/enzyme": "^3.10.3" }, |
| 79 | + { "@types/jest": "^24.0.9" }, |
| 80 | + { "@types/enzyme-adapter-react-16": "^1.0.5" }, |
| 81 | + { "react-test-renderer": "^16.8.6" }, |
| 82 | + { jest: "^24.1.0" }, |
| 83 | + { enzyme: "^3.10.0" }, |
| 84 | + { "enzyme-adapter-react-16": "^1.10.0" }, |
| 85 | + { "ts-jest": "^24.0.0" } |
68 | 86 | ); |
| 87 | + } else { |
| 88 | + package.scripts.push({ |
| 89 | + test: 'echo \\"Warn: No test specified\\" && exit 0"' |
| 90 | + }); |
69 | 91 | } |
70 | 92 |
|
71 | 93 | if (this.answers.semanticrelease) { |
| 94 | + package.version = "0.0.0-semantically-released"; |
| 95 | + package.scripts.push({ |
| 96 | + "semantic-release": "semantic-release" |
| 97 | + }); |
| 98 | + package.scripts.push({ |
| 99 | + cz: "git-cz" |
| 100 | + }); |
72 | 101 | if (!this.answers.repository || !this.answers.repository.trim()) { |
73 | 102 | console.error( |
74 | 103 | this |
75 | 104 | .chalk`{red No repository url defined while semantic release is enabled}` |
76 | 105 | ); |
77 | 106 | process.exit(1); |
78 | 107 | } |
79 | | - devDependencies.push('\t\t"semantic-release": "^15.13.31"'); |
80 | | - devDependencies.push('\t\t"@semantic-release/changelog": "^3.0.6"'); |
81 | | - devDependencies.push('\t\t"@semantic-release/commit-analyzer": "^6.3.3"'); |
82 | | - devDependencies.push('\t\t"@semantic-release/git": "^7.0.18"'); |
83 | | - devDependencies.push( |
84 | | - '\t\t"@semantic-release/release-notes-generator": "^7.3.4"' |
85 | | - ); |
86 | | - devDependencies.push('\t\t"commitizen": "^4.0.3"'); |
| 108 | + package.devDependencies.push({ "semantic-release": "^15.13.31" }); |
| 109 | + package.devDependencies.push({ |
| 110 | + "@semantic-release/changelog": "^3.0.6" |
| 111 | + }); |
| 112 | + package.devDependencies.push({ |
| 113 | + "@semantic-release/commit-analyzer": "^6.3.3" |
| 114 | + }); |
| 115 | + package.devDependencies.push({ "@semantic-release/git": "^7.0.18" }); |
| 116 | + package.devDependencies.push({ |
| 117 | + "@semantic-release/release-notes-generator": "^7.3.4" |
| 118 | + }); |
| 119 | + package.devDependencies.push({ commitizen: "^4.0.3" }); |
| 120 | + } |
| 121 | + |
| 122 | + if (this.answers.travis) { |
| 123 | + if (!this.answers.repository || !this.answers.repository.trim()) { |
| 124 | + console.error( |
| 125 | + this.chalk`{red No repository url defined while travis ci is enabled}` |
| 126 | + ); |
| 127 | + process.exit(1); |
| 128 | + } |
| 129 | + |
| 130 | + package.scripts.push({ |
| 131 | + "travis-deploy-once": "travis-deploy-once" |
| 132 | + }); |
| 133 | + } |
| 134 | + |
| 135 | + if (this.answers.repository) { |
| 136 | + package.repository = { |
| 137 | + url: this.answers.repository |
| 138 | + }; |
87 | 139 | } |
88 | 140 |
|
89 | 141 | const pmRun = this.answers.pm === "yarn" ? "yarn" : "npm run"; |
90 | 142 |
|
91 | 143 | return { |
92 | | - tsconfig: { |
93 | | - includes: tsconfig.includes.join(",\n") |
94 | | - }, |
95 | | - scripts: scripts.join(",\n"), |
96 | | - devDependencies: devDependencies.join(",\n"), |
97 | | - peerDependencies: peerDependencies.join(",\n"), |
98 | | - dependencies: dependencies.join(",\n"), |
| 144 | + tsconfig: serializeTSConfig(tsconfig), |
| 145 | + package: serializePackage(package), |
99 | 146 | pmRun |
100 | 147 | }; |
101 | 148 | }, |
|
0 commit comments