Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Add publish task
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Jul 18, 2016
1 parent 7a1b2d9 commit b367b1c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ TODO: finish README

Online [here](http://microsoft.github.io/TypeSearch).

To update:
* `gulp build`
* Move `public` out
* `git checkout gh-pages`
* Remove old contents and move contents of `public` in
* `git add --all; git commit -m "message"; git push`
* `git checkout master`
### Run locally

Run `gulp`, then see [localhost](http://localhost).

### Publish

`gulp publish`
3 changes: 3 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
interface String {
includes(substring: string): boolean;
}

declare module "http-server" {
function createServer(options: { root: string }): { listen: (port: number) => void };
Expand Down
63 changes: 63 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/// <reference path="./declarations.d.ts"/>
/// <reference types="es6-promise" />

import {execSync} from "child_process";
import del = require("del");
import * as fse from "fs-extra";
import * as gulp from "gulp";
import {createServer} from "http-server";
//const httpServer = require("http-server");
import * as path from "path";
import * as tmp from "tmp";
import ts = require("gulp-typescript");

const out = "public";
Expand Down Expand Up @@ -38,3 +42,62 @@ gulp.task("serve", () => {
gulp.task("watch", ["build", "serve"], () => gulp.watch("assets/**", ["build"]));

gulp.task("default", ["watch"]);

gulp.task("publish", ["build"], () => {
function exec(cmd: string): string {
return execSync(cmd, { encoding: "utf8" });
}

if (!(exec("git status").includes("nothing to commit"))) {
throw new Error("Commit all changes first!")
}

if (exec("git rev-parse --abbrev-ref HEAD").trim() !== "master") {
throw new Error("You are not on master branch.");
}

const tmpObj = tmp.dirSync();
console.log(`Temporaries are stored at ${tmpObj.name}`);
function tmpDir(dir: string): string {
return path.join(tmpObj.name, dir);
}

const toMove = ["node_modules", "public"];
// Move files away temporarily.
const moved = Promise.all(toMove.map(dir => mvPromise(dir, tmpDir(dir))));

moved.then(() => {
exec("git checkout gh-pages");
// Clean out the old
const oldFiles = fse.readdirSync(".").filter(f => f !== ".git");
oldFiles.forEach(fse.removeSync);
// Move in the new
fse.copySync(tmpDir("public"), ".");

// And commit it
exec("git add --all");
exec("git commit -m \"Update from master\"");
exec("git push");

exec("git checkout master");
// Move files back.
return Promise.all(toMove.map(dir => mvPromise(tmpDir(dir), dir)));
}).catch(console.error);
});

declare module "fs-extra" {
function move(src: string, dest: string, cb: (err: Error | undefined) => void): void;
}

function mvPromise(src: string, dest: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
fse.move(src, dest, err => {
if (err) {
reject(err);
}
else {
resolve();
}
})
});
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/es6-promise": "0.0.28",
"@types/fs-extra": "0.0.28",
"@types/tmp": "0.0.27",
"fs-extra": "^0.30.0",
"jquery": "^2.2.2",
"tmp": "0.0.28",
"typeahead.js": "^0.11.1"
},
"devDependencies": {
Expand Down

0 comments on commit b367b1c

Please sign in to comment.