Skip to content

Commit 0960015

Browse files
authored
Merge pull request #5 from epranka/refactor#saofile
Refactor
2 parents 83eb72f + 40feb8a commit 0960015

20 files changed

+10149
-146
lines changed

.releaserc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
{
1717
"type": "style",
1818
"release": "patch"
19-
},
20-
{
21-
"type": "improvement",
22-
"release": "patch"
2319
}
2420
],
2521
"parserOpts": {

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
2+
os: linux
23

34
node_js:
45
- 12.3.1
@@ -7,11 +8,9 @@ jobs:
78
include:
89
# Define the release stage that runs semantic-release
910
- stage: release
11+
name: "Releasing"
1012
node_js: lts/*
11-
# Advanced: optionally overwrite your default `script` step to skip the tests
12-
# script: skip
1313
deploy:
1414
provider: script
15-
skip_cleanup: true
16-
script:
17-
- npx semantic-release
15+
cleanup: false
16+
script: npx semantic-release

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"bin": "./cli.js",
1414
"scripts": {
1515
"test": "exit 0",
16+
"build": "exit 0",
1617
"travis-deploy-once": "travis-deploy-once",
1718
"semantic-release": "semantic-release",
1819
"cz": "git-cz"

saofile.js

Lines changed: 119 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,148 @@
11
const spawn = require("cross-spawn");
22
const validate = require("validate-npm-package-name");
3+
const serializePackage = require("./utils/serializePackage");
4+
const serializeTSConfig = require("./utils/serializeTSConfig");
35

46
module.exports = {
57
prompts: require("./prompts"),
68
templateData() {
79
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": "*" }]
972
};
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 = [];
5773

5874
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" }
6886
);
87+
} else {
88+
package.scripts.push({
89+
test: 'echo \\"Warn: No test specified\\" && exit 0"'
90+
});
6991
}
7092

7193
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+
});
72101
if (!this.answers.repository || !this.answers.repository.trim()) {
73102
console.error(
74103
this
75104
.chalk`{red No repository url defined while semantic release is enabled}`
76105
);
77106
process.exit(1);
78107
}
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+
};
87139
}
88140

89141
const pmRun = this.answers.pm === "yarn" ? "yarn" : "npm run";
90142

91143
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),
99146
pmRun
100147
};
101148
},

templates/_package_json

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1 @@
1-
{
2-
"name": "<%= name %>",
3-
"description": "<%= description %>",
4-
"version": "0.0.1",
5-
"scripts": {
6-
<%- scripts %>
7-
},
8-
"main": "lib/index.js",
9-
"module": "lib/index.es.js",
10-
"types": "lib/index.d.ts",
11-
"files": [
12-
"lib"
13-
],
14-
"publishConfig": {
15-
"access": "public"
16-
},
17-
"keywords": [],
18-
"author": "",
19-
"contributors": [],
20-
"repository": {
21-
"url": "<%- repository %>"
22-
},
23-
"devDependencies": {
24-
<%- devDependencies %>
25-
},
26-
"peerDependencies": {
27-
<%- peerDependencies %>
28-
},
29-
"license": "MIT",
30-
"dependencies": {
31-
<% - dependencies %>
32-
}
33-
}
1+
<%- package %>

templates/_tsconfig_json

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1 @@
1-
{
2-
"compilerOptions": {
3-
"outDir": "./lib",
4-
"target": "esnext",
5-
"moduleResolution": "node",
6-
"module": "esnext",
7-
"jsx": "react",
8-
"skipLibCheck": true,
9-
"lib": ["dom", "es6"],
10-
"experimentalDecorators": true,
11-
"declaration": true,
12-
"sourceMap": true,
13-
"removeComments": true,
14-
"noImplicitAny": false,
15-
"noImplicitThis": true,
16-
"noImplicitReturns": true,
17-
"noFallthroughCasesInSwitch": true,
18-
"esModuleInterop": true,
19-
"allowSyntheticDefaultImports": true
20-
},
21-
"exclude": [
22-
"node_modules",
23-
],
24-
"include": [
25-
<%- tsconfig.includes %>
26-
]
27-
}
1+
<%- tsconfig %>

templates/travis_yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
language: node_js
2+
os: linux
23

34
jobs:
45
include:
56
# Define the release stage that runs semantic-release
67
- stage: release
8+
name: "Releasing"
79
node_js: lts/*
8-
# Advanced: optionally overwrite your default `script` step to skip the tests
9-
# script: skip
1010
deploy:
1111
provider: script
12-
skip_cleanup: true
13-
script:
14-
- npx semantic-release
12+
cleanup: false
13+
script: npx semantic-release

test/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
"@babel/typescript",
4+
"@babel/env"
5+
],
6+
"plugins": [
7+
["@babel/plugin-proposal-decorators", {"legacy": true}],
8+
"@babel/proposal-class-properties",
9+
"@babel/proposal-object-rest-spread",
10+
"@babel/plugin-transform-typescript"
11+
]
12+
}

test/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# node.js
2+
#
3+
node_modules/
4+
npm-debug.log
5+
yarn-error.log
6+
7+
# visual studio code
8+
.vscode
9+
10+
# lib
11+
lib

0 commit comments

Comments
 (0)