Skip to content

Commit 63d9b4d

Browse files
committed
Implemented action to publish to npm
- minor fix on node version used in actions - fix on code format a
1 parent 4911ff9 commit 63d9b4d

File tree

6 files changed

+118
-75
lines changed

6 files changed

+118
-75
lines changed

.github/workflows/publish-github-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v2
1717
with:
18-
node-version: '18'
18+
node-version: '16'
1919
registry-url: 'https://npm.pkg.github.com'
2020

2121
- name: Install dependencies
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Use Node.js
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: '16'
18+
registry-url: 'https://registry.npmjs.org'
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Build
24+
run: npm run build
25+
26+
- name: Publish
27+
run: npm publish
28+
env:
29+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
husky
3+
dist

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": false,
3+
"trailingComma": "none",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"bracketSpacing": true,
9+
"endOfLine": "lf"
10+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@marchintosh94/create-node-ts",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NodeJS TypeScript projects generator by @marchintosh",
55
"main": "dist/index.js",
66
"files": [

src/index.ts

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#!/usr/bin/env node
12
import { input, select } from '@inquirer/prompts'
23
import * as logo from 'asciiart-logo'
34
import { getPackageJson } from './packageJson'
45
import { tsconfigJson } from './tsconfigJson'
5-
import * as fs from 'fs'
6+
import * as fs from 'fs'
67
import { execSync } from 'child_process'
78

89
const wantsCreateNewFolder = async () =>
@@ -26,94 +27,94 @@ const getProjectName = async () =>
2627
default: 'typescript-nodejs-project'
2728
})
2829

29-
const getFullLogo = () => logo({
30-
name: 'TypeScript NodeJS',
31-
font: 'ANSI Shadow',
32-
borderColor: 'grey',
33-
logoColor: 'bold-cyan',
34-
textColor: 'cyan'
35-
})
36-
.emptyLine()
37-
.center('Create a Typescript NodeJS project')
38-
.emptyLine()
39-
.emptyLine()
40-
.right('version 1.0.0')
41-
.right('Author: @marchintosh')
30+
const getFullLogo = () =>
31+
logo({
32+
name: 'TypeScript NodeJS',
33+
font: 'ANSI Shadow',
34+
borderColor: 'grey',
35+
logoColor: 'bold-cyan',
36+
textColor: 'cyan'
37+
})
38+
.emptyLine()
39+
.center('Create a Typescript NodeJS project')
40+
.emptyLine()
41+
.emptyLine()
42+
.right('version 1.0.0')
43+
.right('Author: @marchintosh')
4244

4345
const main = async () => {
4446
/* available fonts:
4547
Big Money-ne
4648
Broadway
4749
DOS Rebel
4850
*/
49-
const asciiLogo = getFullLogo();
50-
console.log(asciiLogo.render());
51-
console.log("Welcome to Typescript NodeJS project creator");
52-
const projectName = await getProjectName();
53-
const wantsCreateFolder = await wantsCreateNewFolder();
51+
const asciiLogo = getFullLogo()
52+
console.log(asciiLogo.render())
53+
console.log('Welcome to Typescript NodeJS project creator')
54+
const projectName = await getProjectName()
55+
const wantsCreateFolder = await wantsCreateNewFolder()
5456

55-
if (wantsCreateFolder === "yes") {
56-
fs.mkdirSync(projectName);
57-
process.chdir(projectName);
58-
console.log(`✅ Folder ${projectName} created`);
57+
if (wantsCreateFolder === 'yes') {
58+
fs.mkdirSync(projectName)
59+
process.chdir(projectName)
60+
console.log(`✅ Folder ${projectName} created`)
5961
}
6062

61-
const packageJson = getPackageJson(projectName);
62-
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
63-
console.log("✅ package.json created");
64-
const tsconfig = tsconfigJson;
65-
fs.writeFileSync("tsconfig.json", JSON.stringify(tsconfig, null, 2));
66-
console.log("✅ tsconfig.json created");
67-
fs.mkdirSync("src");
68-
console.log("✅ src folder created");
69-
fs.writeFileSync("src/index.ts", "");
70-
console.log("✅ src/index.ts created");
71-
63+
const packageJson = getPackageJson(projectName)
64+
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2))
65+
console.log('✅ package.json created')
66+
const tsconfig = tsconfigJson
67+
fs.writeFileSync('tsconfig.json', JSON.stringify(tsconfig, null, 2))
68+
console.log('✅ tsconfig.json created')
69+
fs.mkdirSync('src')
70+
console.log('✅ src folder created')
71+
fs.writeFileSync('src/index.ts', '')
72+
console.log('✅ src/index.ts created')
73+
7274
//install dev dependencies
73-
console.log("Installing dev dependencies...");
74-
execSync("npm install --save-dev typescript", { stdio: "inherit" });
75-
console.log("✅ typescript installed");
76-
execSync("npm install --save-dev ts-node", { stdio: "inherit" });
77-
console.log("✅ ts-node installed");
78-
execSync("npm install --save-dev jest", { stdio: "inherit" });
79-
console.log("✅ jest installed");
80-
execSync("npm install --save-dev @types/jest", { stdio: "inherit" });
81-
console.log("✅ @types/jest installed");
82-
execSync("npm install --save-dev @types/node", { stdio: "inherit" });
83-
console.log("✅ @types/node installed");
84-
execSync("npm install --save-dev ts-jest", { stdio: "inherit" });
85-
console.log("✅ ts-jest installed");
86-
execSync("npm install --save-dev husky", { stdio: "inherit" });
87-
console.log("✅ husky installed");
88-
execSync("npm install --save-dev lint-staged", { stdio: "inherit" });
89-
console.log("✅ lint-staged installed");
90-
console.log("✅ All dev dependencies installed");
91-
75+
console.log('Installing dev dependencies...')
76+
execSync('npm install --save-dev typescript', { stdio: 'inherit' })
77+
console.log('✅ typescript installed')
78+
execSync('npm install --save-dev ts-node', { stdio: 'inherit' })
79+
console.log('✅ ts-node installed')
80+
execSync('npm install --save-dev jest', { stdio: 'inherit' })
81+
console.log('✅ jest installed')
82+
execSync('npm install --save-dev @types/jest', { stdio: 'inherit' })
83+
console.log('✅ @types/jest installed')
84+
execSync('npm install --save-dev @types/node', { stdio: 'inherit' })
85+
console.log('✅ @types/node installed')
86+
execSync('npm install --save-dev ts-jest', { stdio: 'inherit' })
87+
console.log('✅ ts-jest installed')
88+
execSync('npm install --save-dev husky', { stdio: 'inherit' })
89+
console.log('✅ husky installed')
90+
execSync('npm install --save-dev lint-staged', { stdio: 'inherit' })
91+
console.log('✅ lint-staged installed')
92+
console.log('✅ All dev dependencies installed')
93+
9294
//copy all configuration files from template folder
93-
console.log("Copying configuration files...");
94-
fs.copyFileSync("../template/jest.config.ts", "jest.config.ts");
95-
console.log("✅ jest.config.ts copied");
96-
fs.copyFileSync("../template/.gitignore", ".gitignore");
97-
console.log("✅ .gitignore copied");
98-
fs.copyFileSync("../template/.prettierrc", ".prettierrc");
99-
console.log("✅ .prettierrc copied");
100-
fs.copyFileSync("../template/.prettierignore", ".prettierignore");
101-
console.log("✅ .prettierignore copied");
95+
console.log('Copying configuration files...')
96+
fs.copyFileSync('../template/jest.config.ts', 'jest.config.ts')
97+
console.log('✅ jest.config.ts copied')
98+
fs.copyFileSync('../template/.gitignore', '.gitignore')
99+
console.log('✅ .gitignore copied')
100+
fs.copyFileSync('../template/.prettierrc', '.prettierrc')
101+
console.log('✅ .prettierrc copied')
102+
fs.copyFileSync('../template/.prettierignore', '.prettierignore')
103+
console.log('✅ .prettierignore copied')
102104

103105
//init and config husky and lint-staged
104-
console.log("Configuring husky...");
105-
execSync("npx husky init", { stdio: "inherit" });
106-
execSync("echo 'npm test' >> .husky/pre-commit", { stdio: "inherit" });
107-
execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: "inherit" });
108-
console.log("✅ husky configured");
106+
console.log('Configuring husky...')
107+
execSync('npx husky init', { stdio: 'inherit' })
108+
execSync("echo 'npm test' >> .husky/pre-commit", { stdio: 'inherit' })
109+
execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: 'inherit' })
110+
console.log('✅ husky configured')
109111

110112
//init git
111-
console.log("Initializing git...");
112-
execSync("git init -b main", { stdio: "inherit" });
113+
console.log('Initializing git...')
114+
execSync('git init -b main', { stdio: 'inherit' })
113115

114-
console.log("✅ All done!");
115-
console.log("Happy coding! 🚀");
116+
console.log('✅ All done!')
117+
console.log('Happy coding! 🚀')
116118
}
117119

118-
119-
main()
120+
main()

0 commit comments

Comments
 (0)