Skip to content

Commit 25aa9a5

Browse files
authored
Merge pull request #19 from alioguzhan/alioguzhan/issue18
Alioguzhan/issue18
2 parents 3c90042 + 8deb43f commit 25aa9a5

12 files changed

+2342
-1826
lines changed

.commitlintrc.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/release-please.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
name: release-please
6+
jobs:
7+
release-please:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: google-github-actions/release-please-action@v3
11+
with:
12+
release-type: node
13+
package-name: --libraryname--

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
./node_modules/.bin/lint-staged
4+
yarn lint-staged

.versionrc.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ A template to create a react component / library with Typescript.
1212
- Css Modules
1313
- Jest with code coverage report
1414
- `Typedoc` for API documentation
15-
- `standard-version` ready
1615
- `commitlint` for conventional-commits
1716
- `Prettier` and `ESLint` integration with git hooks
1817
- Optional `example app` generation for testing
1918
- `Github Pages` integration
19+
- Release-Please workflow
2020

2121
## Install
2222

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

package.json

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,60 +31,60 @@
3131
"prepare": "husky install"
3232
},
3333
"engines": {
34-
"node": ">=10",
35-
"npm": ">=6"
34+
"node": ">=12"
3635
},
3736
"peerDependencies": {
3837
"react": ">=17",
3938
"react-dom": ">=17"
4039
},
4140
"devDependencies": {
42-
"@commitlint/cli": "^13.2.0",
43-
"@testing-library/jest-dom": "^5.14.1",
44-
"@testing-library/react": "^12.1.2",
45-
"@types/jest": "^27.0.2",
46-
"@types/node": "^16.10.3",
47-
"@types/react": "^17.0.27",
48-
"@types/react-dom": "^17.0.9",
49-
"@typescript-eslint/eslint-plugin": "^4.33.0",
50-
"@typescript-eslint/parser": "^4.33.0",
41+
"@commitlint/cli": "^17.1.2",
42+
"@commitlint/config-conventional": "^17.1.0",
43+
"@rollup/plugin-commonjs": "^22.0.2",
44+
"@rollup/plugin-json": "^4.1.0",
45+
"@rollup/plugin-node-resolve": "^13.3.0",
46+
"@testing-library/jest-dom": "^5.16.5",
47+
"@testing-library/react": "^13.4.0",
48+
"@types/jest": "^29.0.0",
49+
"@types/node": "^18.7.15",
50+
"@types/react": "^18.0.18",
51+
"@types/react-dom": "^18.0.6",
52+
"@typescript-eslint/eslint-plugin": "^5.36.1",
53+
"@typescript-eslint/parser": "^5.36.1",
5154
"colors": "^1.4.0",
5255
"cross-env": "^7.0.3",
53-
"eslint": "^7.32.0",
54-
"eslint-config-prettier": "^8.3.0",
55-
"eslint-config-standard": "^16.0.3",
56-
"eslint-plugin-import": "^2.24.2",
57-
"eslint-plugin-node": "^11.1.0",
58-
"eslint-plugin-prettier": "^4.0.0",
59-
"eslint-plugin-promise": "^5.1.0",
60-
"eslint-plugin-react": "^7.26.1",
61-
"eslint-plugin-react-hooks": "^4.2.0",
56+
"eslint": "^8.23.0",
57+
"eslint-config-prettier": "^8.5.0",
58+
"eslint-config-standard": "^17.0.0",
59+
"eslint-plugin-import": "^2.26.0",
60+
"eslint-plugin-n": "^15.2.5",
61+
"eslint-plugin-prettier": "^4.2.1",
62+
"eslint-plugin-promise": "^6.0.1",
63+
"eslint-plugin-react": "^7.31.6",
64+
"eslint-plugin-react-hooks": "^4.6.0",
6265
"eslint-plugin-standard": "^5.0.0",
63-
"gh-pages": "^3.2.3",
64-
"husky": "^7.0.2",
66+
"gh-pages": "^4.0.0",
67+
"husky": "^8.0.1",
6568
"identity-obj-proxy": "^3.0.0",
66-
"jest": "^27.2.4",
67-
"lint-staged": "^11.2.0",
68-
"postcss": "^8.3.9",
69-
"prettier": "^2.4.1",
70-
"prompt": "^1.2.0",
71-
"react": "^17.0.2",
72-
"react-dom": "^17.0.1",
73-
"replace-in-file": "^6.2.0",
74-
"rollup": "^2.58.0",
75-
"rollup-plugin-commonjs": "^10.1.0",
76-
"rollup-plugin-json": "^4.0.0",
77-
"rollup-plugin-node-resolve": "^5.2.0",
69+
"jest": "^29.0.2",
70+
"jest-environment-jsdom": "^29.0.2",
71+
"lint-staged": "^13.0.3",
72+
"postcss": "^8.4.16",
73+
"prettier": "^2.7.1",
74+
"prompt": "^1.3.0",
75+
"react": "^18.2.0",
76+
"react-dom": "^18.2.0",
77+
"replace-in-file": "^6.3.5",
78+
"rollup": "^2.79.0",
7879
"rollup-plugin-peer-deps-external": "^2.2.4",
79-
"rollup-plugin-postcss": "^4.0.1",
80+
"rollup-plugin-postcss": "^4.0.2",
8081
"rollup-plugin-sourcemaps": "^0.6.3",
8182
"rollup-plugin-terser": "^7.0.2",
82-
"rollup-plugin-typescript2": "^0.30.0",
83-
"shelljs": "^0.8.5",
84-
"ts-jest": "^27.0.5",
85-
"ts-node": "^10.2.1",
86-
"typedoc": "^0.22.5",
87-
"typescript": "^4.4.3"
83+
"rollup-plugin-typescript2": "^0.33.0",
84+
"ts-jest": "^28.0.8",
85+
"ts-node": "^10.9.1",
86+
"typedoc": "^0.23.14",
87+
"typescript": "^4.8.2"
8888
},
8989
"lint-staged": {
9090
"src/**/*.{ts,tsx}": [

rollup.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import commonjs from 'rollup-plugin-commonjs';
2-
import json from 'rollup-plugin-json';
3-
import resolve from 'rollup-plugin-node-resolve';
4-
import postcss from 'rollup-plugin-postcss';
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import json from '@rollup/plugin-json';
3+
import resolve from '@rollup/plugin-node-resolve';
54
import external from 'rollup-plugin-peer-deps-external';
5+
import postcss from 'rollup-plugin-postcss';
66
import sourceMaps from 'rollup-plugin-sourcemaps';
77
import { terser } from 'rollup-plugin-terser';
88
import typescript from 'rollup-plugin-typescript2';
@@ -45,7 +45,6 @@ export default {
4545
// Compile TypeScript files
4646
typescript({
4747
useTsconfigDeclarationDir: true,
48-
rollupCommonJSResolveHack: true,
4948
exclude: ['**/__tests__/**', '*.spec.*', '*.test.*'],
5049
clean: true,
5150
}),

shell.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
with import (fetchTarball https://github.com/NixOS/nixpkgs/archive/22.05.tar.gz) { };
2+
3+
stdenv.mkDerivation {
4+
name = "--libraryname--";
5+
6+
buildInputs = with pkgs; [
7+
git
8+
nodejs
9+
yarn
10+
];
11+
}

src/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { useEffect } from 'react';
22
import styles from './styles.module.css';
33

4-
interface Props {
4+
/**
5+
* Main Component Props
6+
*/
7+
export interface Props {
58
message?: string;
69
}
710
/**

tools/init.ts

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
* I just made some modifications and added some new functions.
1010
* **/
1111

12+
const { execSync } = require('child_process');
13+
const {
14+
rmdirSync,
15+
rmSync,
16+
existsSync,
17+
lstatSync,
18+
readdirSync,
19+
unlinkSync,
20+
} = require('fs');
21+
1222
/* eslint-disable @typescript-eslint/no-var-requires */
1323
/* eslint-disable @typescript-eslint/no-explicit-any */
1424

@@ -23,7 +33,23 @@ const replace = require('replace-in-file');
2333
const { readFileSync, writeFileSync } = require('fs');
2434
const { cyan, green, red, underline, yellow } = require('colors');
2535
const _prompt = require('prompt');
26-
const { mv, rm, which, exec } = require('shelljs');
36+
37+
function deleteFolderRecursive(path: any) {
38+
if (existsSync(path)) {
39+
const files = readdirSync(path);
40+
files.forEach(function (file: any) {
41+
const curPath = path + '/' + file;
42+
if (lstatSync(curPath).isDirectory()) {
43+
// recurse
44+
deleteFolderRecursive(curPath);
45+
} else {
46+
// delete file
47+
unlinkSync(curPath);
48+
}
49+
});
50+
rmdirSync(path);
51+
}
52+
}
2753

2854
// Note: These should all be relative to the project root directory
2955
const rmDirs = ['.git', 'tools'];
@@ -33,6 +59,8 @@ const modifyFiles = [
3359
'package.json',
3460
'README.md',
3561
'CODE_OF_CONDUCT.md',
62+
'shell.nix',
63+
'.github/workflows/release-please.yml',
3664
];
3765

3866
/**
@@ -44,12 +72,11 @@ function removeItems() {
4472
// The directories and files are combined here, to simplify the function,
4573
// as the 'rm' command checks the item type before attempting to remove it
4674
const rmItems = rmDirs.concat(rmFiles);
47-
rm(
48-
'-rf',
49-
rmItems.map((f) => resolve(__dirname, '..', f))
50-
);
51-
console.log(red(rmItems.join('\n')));
5275

76+
rmItems
77+
.map((f) => resolve(__dirname, '..', f))
78+
.forEach((p) => deleteFolderRecursive(p));
79+
console.log(red(rmItems.join('\n')));
5380
console.log('\n');
5481
}
5582

@@ -102,9 +129,10 @@ function finalize() {
102129
console.log(underline.white('Finalizing'));
103130

104131
// Recreate Git folder
105-
const gitInitOutput = exec('git init "' + resolve(__dirname, '..') + '"', {
106-
silent: true,
107-
}).stdout;
132+
const gitInitOutput = execSync(
133+
'git init "' + resolve(__dirname, '..') + '"',
134+
{}
135+
).toString();
108136
console.log(green(gitInitOutput.replace(/(\n|\r)+/g, '')));
109137

110138
// Remove post-install command
@@ -115,20 +143,19 @@ function finalize() {
115143
delete pkg.scripts.postinstall;
116144

117145
// remove the dependencies that are required for the bootstrapping.
118-
['colors', 'prompt', 'replace-in-file', 'shelljs', 'ts-node'].forEach(
119-
(dep) => {
120-
delete pkg.devDependencies[dep];
121-
}
122-
);
146+
['colors', 'prompt', 'replace-in-file', 'ts-node'].forEach((dep) => {
147+
delete pkg.devDependencies[dep];
148+
});
123149

124150
writeFileSync(jsonPackage, JSON.stringify(pkg, null, 2));
125151
console.log(green('Postinstall script has been removed'));
126152

127153
console.log(yellow('Removing yarn.lock and performing a clean install...'));
128-
rm('yarn.lock');
129-
exec('yarn install');
130-
exec('yarn build');
131-
exec("git add . && git commit -am 'chore: init' --no-verify");
154+
rmSync('yarn.lock');
155+
deleteFolderRecursive('node_modules');
156+
execSync('yarn install');
157+
execSync('yarn build');
158+
execSync("git add . && git commit -am 'chore: init' --no-verify");
132159
console.log('\n');
133160
}
134161
/**
@@ -144,23 +171,23 @@ function setupLibrary(libraryName: string, generateExample = false) {
144171
);
145172

146173
// Get the Git username and email before the .git directory is removed
147-
const username = exec('git config user.name').stdout.trim();
148-
const usermail = exec('git config user.email').stdout.trim();
174+
const username = execSync('git config user.name').toString().trim();
175+
const usermail = execSync('git config user.email').toString().trim();
149176

150177
if (generateExample) {
151178
yellow('Installing the test application into example/ directory...');
152-
exec('npx create-react-app example');
153-
exec('echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env');
179+
execSync('npx create-react-app example');
180+
execSync('echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env');
154181
}
155-
mv('tools/README.md', 'README.md');
182+
execSync('mv tools/README.md README.md');
156183
removeItems();
157184

158185
modifyGitignoreFile();
159186
modifyContents(libraryName, username, usermail);
160187

161188
if (generateExample) {
162189
console.log(yellow('Linking packages to the example app...'));
163-
exec(
190+
execSync(
164191
'cd example && yarn add link:.. link:../node_modules/react link:../node_modules/react-dom && cd ..'
165192
);
166193
}
@@ -295,7 +322,9 @@ _prompt.message = '';
295322
// Clear console
296323
process.stdout.write('\x1B[2J\x1B[0f');
297324

298-
if (!which('git')) {
325+
try {
326+
execSync('git --version');
327+
} catch {
299328
console.log(red('Sorry, this script requires git'));
300329
removeItems();
301330
process.exit(1);

0 commit comments

Comments
 (0)