Skip to content

Commit

Permalink
Implemented action to publish to npm
Browse files Browse the repository at this point in the history
- minor fix on node version used in actions
- fix on code format a
  • Loading branch information
marchintosh94 committed Apr 24, 2024
1 parent 4911ff9 commit 63d9b4d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-github-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '16'
registry-url: 'https://npm.pkg.github.com'

- name: Install dependencies
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/publish-npm-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish to npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
husky
dist
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": false,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"endOfLine": "lf"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marchintosh94/create-node-ts",
"version": "1.0.0",
"version": "1.0.1",
"description": "NodeJS TypeScript projects generator by @marchintosh",
"main": "dist/index.js",
"files": [
Expand Down
147 changes: 74 additions & 73 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node
import { input, select } from '@inquirer/prompts'
import * as logo from 'asciiart-logo'
import { getPackageJson } from './packageJson'
import { tsconfigJson } from './tsconfigJson'
import * as fs from 'fs'
import * as fs from 'fs'
import { execSync } from 'child_process'

const wantsCreateNewFolder = async () =>
Expand All @@ -26,94 +27,94 @@ const getProjectName = async () =>
default: 'typescript-nodejs-project'
})

const getFullLogo = () => logo({
name: 'TypeScript NodeJS',
font: 'ANSI Shadow',
borderColor: 'grey',
logoColor: 'bold-cyan',
textColor: 'cyan'
})
.emptyLine()
.center('Create a Typescript NodeJS project')
.emptyLine()
.emptyLine()
.right('version 1.0.0')
.right('Author: @marchintosh')
const getFullLogo = () =>
logo({
name: 'TypeScript NodeJS',
font: 'ANSI Shadow',
borderColor: 'grey',
logoColor: 'bold-cyan',
textColor: 'cyan'
})
.emptyLine()
.center('Create a Typescript NodeJS project')
.emptyLine()
.emptyLine()
.right('version 1.0.0')
.right('Author: @marchintosh')

const main = async () => {
/* available fonts:
Big Money-ne
Broadway
DOS Rebel
*/
const asciiLogo = getFullLogo();
console.log(asciiLogo.render());
console.log("Welcome to Typescript NodeJS project creator");
const projectName = await getProjectName();
const wantsCreateFolder = await wantsCreateNewFolder();
const asciiLogo = getFullLogo()
console.log(asciiLogo.render())
console.log('Welcome to Typescript NodeJS project creator')
const projectName = await getProjectName()
const wantsCreateFolder = await wantsCreateNewFolder()

if (wantsCreateFolder === "yes") {
fs.mkdirSync(projectName);
process.chdir(projectName);
console.log(`✅ Folder ${projectName} created`);
if (wantsCreateFolder === 'yes') {
fs.mkdirSync(projectName)
process.chdir(projectName)
console.log(`✅ Folder ${projectName} created`)
}

const packageJson = getPackageJson(projectName);
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
console.log("✅ package.json created");
const tsconfig = tsconfigJson;
fs.writeFileSync("tsconfig.json", JSON.stringify(tsconfig, null, 2));
console.log("✅ tsconfig.json created");
fs.mkdirSync("src");
console.log("✅ src folder created");
fs.writeFileSync("src/index.ts", "");
console.log("✅ src/index.ts created");
const packageJson = getPackageJson(projectName)
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2))
console.log('✅ package.json created')
const tsconfig = tsconfigJson
fs.writeFileSync('tsconfig.json', JSON.stringify(tsconfig, null, 2))
console.log('✅ tsconfig.json created')
fs.mkdirSync('src')
console.log('✅ src folder created')
fs.writeFileSync('src/index.ts', '')
console.log('✅ src/index.ts created')

//install dev dependencies
console.log("Installing dev dependencies...");
execSync("npm install --save-dev typescript", { stdio: "inherit" });
console.log("✅ typescript installed");
execSync("npm install --save-dev ts-node", { stdio: "inherit" });
console.log("✅ ts-node installed");
execSync("npm install --save-dev jest", { stdio: "inherit" });
console.log("✅ jest installed");
execSync("npm install --save-dev @types/jest", { stdio: "inherit" });
console.log("✅ @types/jest installed");
execSync("npm install --save-dev @types/node", { stdio: "inherit" });
console.log("✅ @types/node installed");
execSync("npm install --save-dev ts-jest", { stdio: "inherit" });
console.log("✅ ts-jest installed");
execSync("npm install --save-dev husky", { stdio: "inherit" });
console.log("✅ husky installed");
execSync("npm install --save-dev lint-staged", { stdio: "inherit" });
console.log("✅ lint-staged installed");
console.log("✅ All dev dependencies installed");
console.log('Installing dev dependencies...')
execSync('npm install --save-dev typescript', { stdio: 'inherit' })
console.log('✅ typescript installed')
execSync('npm install --save-dev ts-node', { stdio: 'inherit' })
console.log('✅ ts-node installed')
execSync('npm install --save-dev jest', { stdio: 'inherit' })
console.log('✅ jest installed')
execSync('npm install --save-dev @types/jest', { stdio: 'inherit' })
console.log('✅ @types/jest installed')
execSync('npm install --save-dev @types/node', { stdio: 'inherit' })
console.log('✅ @types/node installed')
execSync('npm install --save-dev ts-jest', { stdio: 'inherit' })
console.log('✅ ts-jest installed')
execSync('npm install --save-dev husky', { stdio: 'inherit' })
console.log('✅ husky installed')
execSync('npm install --save-dev lint-staged', { stdio: 'inherit' })
console.log('✅ lint-staged installed')
console.log('✅ All dev dependencies installed')

//copy all configuration files from template folder
console.log("Copying configuration files...");
fs.copyFileSync("../template/jest.config.ts", "jest.config.ts");
console.log("✅ jest.config.ts copied");
fs.copyFileSync("../template/.gitignore", ".gitignore");
console.log("✅ .gitignore copied");
fs.copyFileSync("../template/.prettierrc", ".prettierrc");
console.log("✅ .prettierrc copied");
fs.copyFileSync("../template/.prettierignore", ".prettierignore");
console.log("✅ .prettierignore copied");
console.log('Copying configuration files...')
fs.copyFileSync('../template/jest.config.ts', 'jest.config.ts')
console.log('✅ jest.config.ts copied')
fs.copyFileSync('../template/.gitignore', '.gitignore')
console.log('✅ .gitignore copied')
fs.copyFileSync('../template/.prettierrc', '.prettierrc')
console.log('✅ .prettierrc copied')
fs.copyFileSync('../template/.prettierignore', '.prettierignore')
console.log('✅ .prettierignore copied')

//init and config husky and lint-staged
console.log("Configuring husky...");
execSync("npx husky init", { stdio: "inherit" });
execSync("echo 'npm test' >> .husky/pre-commit", { stdio: "inherit" });
execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: "inherit" });
console.log("✅ husky configured");
console.log('Configuring husky...')
execSync('npx husky init', { stdio: 'inherit' })
execSync("echo 'npm test' >> .husky/pre-commit", { stdio: 'inherit' })
execSync("echo 'npx lint-staged' >> .husky/pre-commit", { stdio: 'inherit' })
console.log('✅ husky configured')

//init git
console.log("Initializing git...");
execSync("git init -b main", { stdio: "inherit" });
console.log('Initializing git...')
execSync('git init -b main', { stdio: 'inherit' })

console.log("✅ All done!");
console.log("Happy coding! 🚀");
console.log('✅ All done!')
console.log('Happy coding! 🚀')
}


main()
main()

0 comments on commit 63d9b4d

Please sign in to comment.