Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 59 - Improve app build + deploy process + removed old files #61

Merged
merged 23 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c6b7afa
Added version prompt to app build process
nwittwer Sep 23, 2018
e2b97c3
Updated app version to 0.3.0
nwittwer Sep 23, 2018
5367260
Added fallback if version is not input (use existing version)
nwittwer Sep 23, 2018
388ca06
Updated wording of version input question
nwittwer Sep 23, 2018
0fcc5ee
Added draft of changelog + Github release draft
nwittwer Sep 23, 2018
116bc33
Updated package.json info
nwittwer Sep 23, 2018
270cacc
Added empty env file
nwittwer Sep 23, 2018
66db34c
Added env to gitignore
nwittwer Sep 23, 2018
4142c67
Stopped track .env
nwittwer Sep 23, 2018
91e92ef
Added dotenv for environment variables
nwittwer Sep 23, 2018
80377ed
Removed old files
nwittwer Sep 23, 2018
b025699
Uppercase changelog var
nwittwer Sep 23, 2018
6a214c0
Removed WebPack eslinting
nwittwer Sep 23, 2018
c624714
Build --> App --> Zip --> Github works, but .app contents are broken …
nwittwer Sep 23, 2018
3536a78
Removed Windows from builds
nwittwer Sep 23, 2018
c29a0e2
Added new packages
nwittwer Sep 24, 2018
499692f
Callback renaming and new var for ZIP path
nwittwer Sep 24, 2018
2c33c40
Updated ZIP task
nwittwer Sep 24, 2018
1ef2022
Updated draft-release task
nwittwer Sep 24, 2018
90ae10e
Added task to open releases in browser
nwittwer Sep 24, 2018
5748943
Fixed changelog; working properly now
nwittwer Sep 24, 2018
2fd7cb4
Added callback to end browser opening task
nwittwer Sep 24, 2018
aca532e
Fixed potential issue with ZIP path not being updated correctly
nwittwer Sep 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eclintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
dist/
ship/
src/*.app/
Expand All @@ -7,4 +8,4 @@ src/**/*.css.map
src/build/
src/cache/
node_modules/
package-lock.json
package-lock.json
154 changes: 152 additions & 2 deletions gulp/tasks/build-app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,92 @@
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const NwBuilder = require('nw-builder');
const replace = require('gulp-replace');
const inquirer = require('inquirer');
const merge = require('merge-stream');
const exec = require('child_process').exec;
const chalk = require('chalk');
const release = require('gulp-github-release');
const zip = require('gulp-zip');
const notify = require("gulp-notify");
const archiver = require('archiver');
const opn = require('opn');

// Update process.env based on .env file (in root directory)
require('dotenv').config();

// Import configuration settings
const CONFIG = require('../config.js');

// Get current app version
const CURRENT_APP_VERSION = require('../../src/package.json').version;
let NEXT_APP_VERSION;

// Changelog variable
let CHANGELOG;
let PATH_TO_ZIP;

// The overall task
gulp.task('build-app', gulp.series('build-app:main'));
gulp.task('build-app', gulp.series(
'build-app:prompt',
'build-app:version',
'build-app:changelog',
'build-app:main',
'build-app:zip-app',
'build-app:draft-release',
'build-app:open-release-in-browser'
));

// Confirm version number
gulp.task('build-app:prompt', function (done) {
inquirer.prompt([{
type: 'input',
name: 'version',
message: 'What version is this? (Currently ' + CURRENT_APP_VERSION + ' ):'
}])
.then(function (res) {
if (res.version) {
NEXT_APP_VERSION = res.version;
} else {
NEXT_APP_VERSION = CURRENT_APP_VERSION;
}

// Update the final ZIP path with the version
PATH_TO_ZIP = 'ship/Shift-v' + NEXT_APP_VERSION + '.zip';

done();
});
});

// Bumps the version number
// `src/package.json` and `dist/package.json`
gulp.task('build-app:version', function () {
const src = gulp.src(CONFIG.SRC + 'package.json')
.pipe(replace(CURRENT_APP_VERSION, NEXT_APP_VERSION))
.pipe(gulp.dest(CONFIG.SRC));

const dist = gulp.src(CONFIG.DIST + 'package.json')
.pipe(replace(CURRENT_APP_VERSION, NEXT_APP_VERSION))
.pipe(gulp.dest(CONFIG.DIST));

return merge(src, dist);
});

// Creates a changelog from Git log
// Compares the commits from branch A that are not in branch B
// Then stores it to a variable that can later be used for a
// git log origin/branch-a..origin/branch-b --abbrev-commit --pretty=oneline
gulp.task('build-app:changelog', function (cb) {
exec('git log master.. --abbrev-commit --pretty=oneline', function (err, stdout, stderr) {
CHANGELOG = stdout;
console.log(chalk.yellow('Changelog:\n' + CHANGELOG));
cb(err);
});
});

// Build the app into a Mac/Windows executable format
// The final distributable is put into the `ship` folder
gulp.task('build-app:main', function () {
var nw = new NwBuilder({
version: '0.33.1', // the NWJS version to use
Expand All @@ -17,7 +96,7 @@ gulp.task('build-app:main', function () {
cacheDir: CONFIG.SHIP, // cached NWJS versions (/dist/cache)
macCredits: CONFIG.SRC + 'credits.html',
macIcns: CONFIG.SRC + 'icon.icns',
platforms: ['osx64', 'win32']
platforms: ['osx64'] // win32
})

// Log build progress
Expand All @@ -30,4 +109,75 @@ gulp.task('build-app:main', function () {
.catch(function (err) {
gutil.log('nw-builder', err);
})
});

// Create a ZIP of executable file
gulp.task('build-app:zip-app', function (done) {
// create a file to stream archive data to.
var output = fs.createWriteStream(PATH_TO_ZIP);
var archive = archiver('zip', {
zlib: {
level: 9 // Sets the compression level.
}
});

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function () {
console.log(chalk.yellow('ZIP size: ' + archive.pointer() + ' total bytes'));
done();
});

// Catch warnings
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
// log warning
} else {
// throw error
throw err;
}
});

// Catch error
archive.on('error', function (err) {
throw err;
});

// Pipe archive data to the file
archive.pipe(output);

// Path to the app, app name
archive.directory('ship/Shift/osx64/Shift.app/', 'Shift.app');

// Finish the ZIP
archive.finalize();
});

// Creates a draft release on Github
// 1. Open the file: `.env` (root directory of this project)
// 2. You can create a Github token here: https://github.com/settings/tokens
// 3. Add: `GITHUB_TOKEN=replace_with_your_token`
// 4. Save the file
gulp.task('build-app:draft-release', function () {
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || "";
return gulp.src(PATH_TO_ZIP)
.pipe(release({
owner: 'nwittwer',
token: GITHUB_TOKEN, // Did you set already add your Github token?
tag: 'v' + NEXT_APP_VERSION, // i.e. v0.3.0 (format: v + 0.0.0)
draft: true, // draft or public
prerelease: false,
manifest: require('../../package.json'), // package.json from which default values will be extracted if they're missing
notes: CHANGELOG
}))
.pipe(notify({
title: "🎉 Shift v" + NEXT_APP_VERSION + " release draft created!",
message: "Opening in browser..."
}))
});

// Opens the Github Releases page
gulp.task('build-app:open-release-in-browser', function (done) {
opn('https://github.com/nwittwer/shift/releases');
done();
});
1 change: 0 additions & 1 deletion gulp/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const gulp = require('gulp');
const rimraf = require('rimraf');

const CONFIG = require('../config.js');

// Erases the dist folder
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/create-package-json-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const resolve = (to) => {
};

gulp.task('create-package-json:dev', function(done) {
var nwjsConfig = JSON.parse(fs.readFileSync(resolve(`${CONFIG.SRC}/nwjs.json`)).toString());
var nwjsConfig = JSON.parse(fs.readFileSync(resolve(`${CONFIG.SRC}/package.json`)).toString());
nwjsConfig['node-remote'] = nwjsConfig.main = `http://localhost:${CONFIG.SERVER.PORT}/${nwjsConfig.main}`;
fs.writeFile(resolve(`${resolve(CONFIG.DIST)}/package.json`), jsonFormat(nwjsConfig), (err) => err && console.log(err));
done();
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/create-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const resolve = (to) => {
};

gulp.task('create-package-json:main', function(done) {
var nwjsConfig = JSON.parse(fs.readFileSync(resolve(`${CONFIG.SRC}/nwjs.json`)).toString());
var nwjsConfig = JSON.parse(fs.readFileSync(resolve(`${CONFIG.SRC}/package.json`)).toString());
fs.writeFile(resolve(`${resolve(CONFIG.DIST)}/package.json`), jsonFormat(nwjsConfig), (err) => err && console.log(err));
done();
});
21 changes: 0 additions & 21 deletions gulp/tasks/javascript.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
const path = require('path');
const gulp = require('gulp');
const concat = require('gulp-concat');
// var named = require('vinyl-named');
const sourcemaps = require('gulp-sourcemaps');

const webpackStream = require('webpack-stream');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const ExtractTextPlugin = require('extract-text-webpack-plugin');

// const extractCssPlugin = new ExtractTextPlugin('css/[name].[hash].css');
// const cssLoader = extractCssPlugin.extract(['css-loader','autoprefixer-loader']);
// const sassLoader = extractCssPlugin.extract(['css-loader','autoprefixer-loader', 'sass-loader']);

var utils = require('../utils.js');
var CONFIG = require('../config.js');

const resolve = (to) => {
Expand Down Expand Up @@ -48,18 +39,6 @@ gulp.task('javascript:webpack', function() {
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
use: [
{
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
}
],
exclude: /node_modules/
}, {
test: /\.js$/,
use: [
{
Expand Down
20 changes: 0 additions & 20 deletions gulp/utils.js

This file was deleted.

23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"name": "tunnelframe-builder",
"author": "Nick Wittwer",
"version": "1.0.0",
"description": "Builds screens app",
"description": "A tool for previewing responsive sites.",
"main": "index.js",
"repository": {
"type": "git",
"url": "git@github.com:nwittwer/shift.git"
},
"homepage": "https://shift.nickwittwer.com",
"scripts": {
"start": "kill -9 $(lsof -i TCP:8000 | grep LISTEN | awk '{print $2}') & gulp & nw dist",
"build": "gulp app"
},
"repository": {
"type": "git"
"bugs": {
"url": "https://github.com/nwittwer/shift/issues"
},
"devDependencies": {
"autoprefixer": "^7.1.1",
Expand All @@ -23,6 +29,7 @@
"babel-register": "^6.24.1",
"chalk": "^1.1.3",
"css-loader": "^0.28.1",
"dotenv": "^6.0.0",
"eslint": "^3.19.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
Expand All @@ -41,14 +48,20 @@
"gulp-compile-handlebars": "^0.6.1",
"gulp-concat": "^2.6.1",
"gulp-declare": "^0.3.0",
"gulp-exec": "^3.0.2",
"gulp-github-release": "^1.2.1",
"gulp-handlebars": "^5.0.2",
"gulp-notify": "^3.2.0",
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"gulp-util": "^3.0.8",
"gulp-wrap": "^0.14.0",
"gulp-zip": "^4.2.0",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.30.1",
"inquirer": "^6.2.0",
"ip": "^1.1.5",
"json-format": "^1.0.1",
"json-loader": "^0.5.4",
Expand All @@ -57,6 +70,7 @@
"merge-stream": "^1.0.1",
"node-sass": "^4.5.3",
"nw": "^0.33.1-sdk",
"opn": "^5.4.0",
"ora": "^1.2.0",
"proxy-middleware": "^0.15.0",
"q": "^1.5.0",
Expand All @@ -74,5 +88,8 @@
"webpack-hot-middleware": "^2.18.0",
"webpack-merge": "^4.1.0",
"webpack-stream": "^5.1.1"
},
"dependencies": {
"archiver": "^3.0.0"
}
}
Loading