Skip to content

Commit

Permalink
Merge pull request prose#1142 from babbitt/modernize
Browse files Browse the repository at this point in the history
Modernize for deployment via actions
  • Loading branch information
babbitt authored Jan 14, 2024
2 parents 2298495 + e078dd0 commit 336f4a3
Show file tree
Hide file tree
Showing 5 changed files with 14,886 additions and 1,902 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build with Gulp and Deploy static resources

on:
push:
branches: ["master"]

workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Build
run: |
npm install
npm run build
- name: Move Static files
run: |
mkdir ./deploy-static
cp -a img dist fonts translations index.html style-rtl.css locale.js oauth.json CNAME ./deploy-static
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "deploy-static"


deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
137 changes: 74 additions & 63 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var shell = require('gulp-shell');
var browserify = require('browserify');
var rename = require('gulp-rename');
var del = require('del');
var watch = require('gulp-watch');
var gulpif = require('gulp-if');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var merge2 = require('merge2');
var mkdirp = require('mkdirp');
var postcss = require('gulp-postcss');
var nodeJS = process.execPath;
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const shell = require('gulp-shell');
const browserify = require('browserify');
const rename = require('gulp-rename');
const del = require('del');
const watch = require('gulp-watch');
const gulpif = require('gulp-if');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const merge2 = require('merge2');
const mkdirp = require('mkdirp');
const postcss = require('gulp-postcss');
const { exec } = require('child_process');
const nodeJS = process.execPath;

// Scripts paths.
var paths = {
const paths = {
vendorScripts: [
'vendor/liquid.js'
],
Expand All @@ -39,16 +40,17 @@ function isProd () {
return process.env.PROSE_ENV === 'production';
}

gulp.task('setProductionEnv', function () {
return process.env.PROSE_ENV = 'production';
gulp.task('setProductionEnv', function (done) {
process.env.PROSE_ENV = 'production';
done();
});

var dist = './dist';
var dev = './';
const dist = './dist';
const dev = './';

// Removes `dist` folder.
gulp.task('clean', function (cb) {
return del([dist], cb);
gulp.task('clean', async function (cb) {
await del([dist], cb);
});

// Translations.
Expand All @@ -65,13 +67,21 @@ gulp.task('clean', function (cb) {
//
gulp.task('translations', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
nodeJS + ' translations/update_locales',
nodeJS + ' build'
])
);
return new Promise((res, rej) => {
exec('"' + nodeJS + '"' + ' translations/update_locales', (error, stdout, stderr) => {
if (error) {
console.error(`exec error (updating translation locales): ${error}`);
return rej(error);
}
exec('"' + nodeJS + '"' + ' build', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return rej(error);
}
res();
});
})
});
});

// Parse stylesheet
Expand All @@ -90,29 +100,35 @@ gulp.task('css', function () {
// Build templates.
gulp.task('templates', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
"\"" + nodeJS + "\"" + ' build'
])
);
return new Promise((res, rej) => {
exec('"' + nodeJS + '"' + ' build', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return rej(error);
}
res();
});
});
});

// Creates `dist` directory if not created and
// creates `oauth.json`.
gulp.task('oauth', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
'[ -f oauth.json ] && echo "Using existing oauth.json." || curl "https://raw.githubusercontent.com/prose/prose/gh-pages/oauth.json" > oauth.json'
])
);
return new Promise((res, rej) => {
exec('[ -f oauth.json ] && echo "Using existing oauth.json." || curl "https://raw.githubusercontent.com/prose/prose/gh-pages/oauth.json" > oauth.json', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return rej(error);
}
res();
});
});
});

// Build tests, then concatenate with vendor scripts
gulp.task('build-tests', ['templates', 'oauth'], function() {
var tests = browserify({
gulp.task('build-tests', gulp.series('templates', 'oauth', function() {
const tests = browserify({
debug: true,
noParse: [require.resolve('handsontable/dist/handsontable.full')]
})
Expand All @@ -125,11 +141,11 @@ gulp.task('build-tests', ['templates', 'oauth'], function() {
return merge2(gulp.src(paths.vendorScripts), tests)
.pipe(concat('index.js'))
.pipe(gulp.dest('./test/lib'));
});
}));

// Browserify app scripts, then concatenate with vendor scripts into `prose.js`.
gulp.task('build-app', ['templates', 'oauth'], function() {
var app = browserify({
gulp.task('build-app', gulp.series('templates', 'oauth', function() {
const app = browserify({
noParse: [require.resolve('handsontable/dist/handsontable.full')]
})
.add('./app/boot.js')
Expand All @@ -141,31 +157,26 @@ gulp.task('build-app', ['templates', 'oauth'], function() {
.pipe(concat('prose.js'))
.pipe(gulpif(isProd(), uglify()))
.pipe(gulp.dest(dist));
});
}));

// Watch for changes in `app` scripts.
gulp.task('watch', ['build-app', 'build-tests', 'css'], function() {
gulp.task('watch', gulp.series('build-app', 'build-tests', 'css', function() {
// Watch any `.js` file under `app` folder.
gulp.watch(paths.app, ['build-app', 'build-tests']);
gulp.watch(paths.test, ['build-tests']);
gulp.watch(paths.templates, ['build-app']);
gulp.watch(paths.css, ['css']);
});
gulp.watch(paths.app, gulp.series('build-app', 'build-tests'));
gulp.watch(paths.test, gulp.series('build-tests'));
gulp.watch(paths.templates, gulp.series('build-app'));
return gulp.watch(paths.css, gulp.series('css'));
}));

var testTask = shell.task([
const testTask = shell.task([
'./node_modules/mocha-phantomjs/bin/mocha-phantomjs test/index.html'
]);

gulp.task('test', ['build-tests'], testTask);

// Run tests in command line on app, test, or template change
gulp.task('test-ci', ['test'], function() {
gulp.watch([paths.app, paths.test, paths.templates], ['test'])
});
gulp.task('test', gulp.series('build-tests', testTask));

// Build site, tests
gulp.task('build', ['build-tests', 'build-app', 'css']);
gulp.task('default', ['build']);
gulp.task('build', gulp.series('build-tests', 'build-app', 'css'));
gulp.task('default', gulp.series('build'));

// Minify build
gulp.task('production', ['setProductionEnv', 'build']);
gulp.task('production', gulp.series('setProductionEnv', 'build'));
Loading

0 comments on commit 336f4a3

Please sign in to comment.