Skip to content

Commit

Permalink
Release it (#23)
Browse files Browse the repository at this point in the history
* πŸ“ Changelog >> Adding changelog file.

* πŸ“ Changelog >> Updating date.

* βž• App >> Adding release-it package for automatic releasing.

* πŸ‘· Build >> Adding release-it in build script.
  • Loading branch information
borsTiHD authored Jun 13, 2021
1 parent 7a3a9ae commit 8225872
Show file tree
Hide file tree
Showing 5 changed files with 783 additions and 74 deletions.
14 changes: 14 additions & 0 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
git: {
commitMessage: 'chore: πŸš€ release v${version}',
requireBranch: 'main', // Stopps if your current branch not match
tag: true,
tagName: 'v${version}',
tagAnnotation: 'Release v${version}',
},
github: {
release: true,
releaseName: 'v${version}',
assets: ['build/*.tar.gz']
}
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.0.1] - 2021-06-13
### Added
- First official release of pi-control πŸ₯³

[Unreleased]: https://github.com/borsTiHD/pi-control/compare/v0.0.1...HEAD
[0.0.1]: https://github.com/borsTiHD/pi-control/releases/tag/v0.0.1
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pi-control",
"productName": "Pi-Control πŸ±β€πŸ‘€",
"version": "0.0.1-beta.1",
"version": "0.0.1",
"description": "Pi-Control helps with gathering information, as well as to simplify controlling your raspberry pi.",
"author": "borsTiHD",
"license": "MIT",
Expand All @@ -16,8 +16,8 @@
"dev": "cross-env NODE_ENV=development concurrently \"yarn dev:api\" \"yarn dev:nuxt\"",
"build:nuxt": "nuxt generate src/client",
"build:api": "webpack",
"build:upload": "cross-env NODE_ENV=production node ./src/build.js --upload=true",
"build": "cross-env NODE_ENV=production node ./src/build.js --upload=false",
"build:release": "cross-env NODE_ENV=production node ./src/build.js --release=true",
"build": "cross-env NODE_ENV=production node ./src/build.js",
"start": "node ./dist/server/app.cjs",
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint": "yarn lint:js"
Expand Down Expand Up @@ -54,6 +54,7 @@
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"release-it": "^14.9.0",
"vue-toastification": "^1.7.11",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.0",
Expand Down
99 changes: 77 additions & 22 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import fs from 'fs-extra'
import archiver from 'archiver'
import webpack from 'webpack'
import NuxtApp from 'nuxt'
import dotenv from 'dotenv'
import release from 'release-it'
import minimist from 'minimist'
import webpackConfig from '../webpack.config.js'
import releaseItConfig from '../.release-it.js'
import nuxtConfig from './client/nuxt.config.js'
import colors from './colors.js'

// Loading '.env' for 'GITHUB_TOKEN'
dotenv.config()

// we need to change up how __dirname is used for ES6 purposes
const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down Expand Up @@ -40,19 +46,49 @@ init()

// Controlls building
async function init() {
logState('(β„Ή) BUILDING CLIENT')
await buildNuxt()
const loader = createLoader()
try {
logState('(β„Ή) DELETING OLD FILES')
await deleteOldFiles()

logState('(β„Ή) BUILDING CLIENT')
await buildNuxt()

logState('(β„Ή) BUILDING BACKEND')
await buildWebpack()

logState('(β„Ή) BUILDING BACKEND')
await buildWebpack()
logState('(β„Ή) ARCHIVING APP')
await archiveProject()

logState('(β„Ή) ARCHIVING APP')
await archiveProject()
logState('(β„Ή) RELEASE HELPER')
await releaseHelper()

logState('(β„Ή) UPLOAD HELPER')
await uploadHelper()
logState('(β„Ή) FINISHED BUILDING APP')
clearInterval(loader)
return true
} catch (error) {
clearInterval(loader)
console.error(`${colors.FgRed}%s${colors.Reset}`, '(❌) ERROR IN BUILD PROCESS')
console.error(`${colors.FgRed}%s${colors.Reset}`, '(❌) STOP EXECUTION OF CODE')
return false
}
}

logState('(β„Ή) FINISHED BUILDING APP')
// Deleting old files
async function deleteOldFiles() {
// Deletes old dist
await fs.rm(DIST_DIR, { recursive: true }).catch((err) => {
console.error(`${colors.FgRed}%s${colors.Reset}`, '(❌) COULDNT DELETE OLD DIST FOLDER')
console.error(err)
throw new Error('Couldnt delete old dist folder')
})
// Deletes old builds
await fs.rm(BUILD_DIR, { recursive: true }).catch((err) => {
console.error(`${colors.FgRed}%s${colors.Reset}`, '(❌) COULDNT DELETE OLD BUILD FOLDER')
console.error(err)
throw new Error('Couldnt delete old build folder')
})
console.log(`${colors.FgGreen}%s${colors.Reset}`, '(βœ”) OLD FILES DELETED')
return true
}

Expand All @@ -73,7 +109,7 @@ async function buildNuxt() {
else throw new Error('Error occurred while generating pages')
}).catch((err) => {
console.error(err)
return Error(err.message)
throw new Error(err.message)
})
console.log(`${colors.FgGreen}%s${colors.Reset}`, '(βœ”) CLIENT FINISHED')
}
Expand Down Expand Up @@ -104,8 +140,12 @@ async function buildWebpack() {

// Archives our files
async function archiveProject() {
// Creates directory, if not exists
await fs.mkdir(BUILD_DIR, { recursive: true })
// Creates 'build' directory
await fs.mkdir(BUILD_DIR, { recursive: true }).catch((err) => {
console.error(`${colors.FgRed}%s${colors.Reset}`, '(❌) COULDNT CREATE BUILD FOLDER')
console.error(err)
throw new Error('Couldnt create build folder')
})

const type = 'tar' // Type for packaged file
const archive = archiver(type, { gzip: true })
Expand All @@ -120,6 +160,7 @@ async function archiveProject() {
.append(fs.createReadStream(PKG_FILE), { name: 'package.json' }) // Package.json
.append(fs.createReadStream(path.join(PROJECT_ROOT, 'ecosystem.json')), { name: 'ecosystem.json' }) // pm2 script
.append(fs.createReadStream(path.join(PROJECT_ROOT, 'README.md')), { name: 'README.md' }) // Readme
.append(fs.createReadStream(path.join(PROJECT_ROOT, 'CHANGELOG.md')), { name: 'CHANGELOG.md' }) // Changelog

// Archive events
archive.on('error', (err) => reject(err))
Expand All @@ -132,17 +173,31 @@ async function archiveProject() {
})
}

// Uploading to GitHub
async function uploadHelper() {
if ('upload' in argv && argv.upload === 'false') {
// If no upload has been specified, don't attempt to upload
console.log(`${colors.FgRed}%s${colors.Reset}`, '(⚠) UPLOADING WAS TURNED OFF')
return true
} else if ('upload' in argv && argv.upload === 'true') {
// If no upload has been specified, don't attempt to upload
console.log(`${colors.FgGreen}%s${colors.Reset}`, '(βœ”) UPLOADING BUILD')
return true
// Releasing to GitHub
async function releaseHelper() {
if ('release' in argv && argv.release === 'true') {
// Releasing build
console.log(`${colors.FgGreen}%s${colors.Reset}`, '(βœ”) RELEASING NEW VERSION')
const options = releaseItConfig
return release(options).then((output) => {
console.log(output) // { version, latestVersion, name, changelog }
})
}

// If no release has been specified, don't attempt to upload
console.log(`${colors.FgYellow}%s${colors.Reset}`, '(⚠) WITHOUT RELEASING')
return true
}

// Creating loading animation
// https://stackoverflow.com/a/62111632/7625095
function createLoader() {
const P = ['\\', '|', '/', '-']
let x = 0
return setInterval(() => {
process.stdout.write(`\r${P[x++]}`)
x %= P.length
}, 100)
}

// Logging current state to console
Expand Down
Loading

0 comments on commit 8225872

Please sign in to comment.