diff options
| author | Mathias Biilmann Christensen <info@mathias-biilmann.net> | 2017-02-21 17:33:52 -0800 |
|---|---|---|
| committer | Mathias Biilmann Christensen <info@mathias-biilmann.net> | 2017-02-21 17:33:52 -0800 |
| commit | 1f36a552a056908da916d814dd9e7ac2f1daf150 (patch) | |
| tree | d0da9e4948771f0d4a74faded0d71c07a8403562 /gulpfile.babel.js | |
| parent | d846af8dc76cd69759d96090a57882caa2d749d2 (diff) | |
Set repository from env variable or git remote
Diffstat (limited to 'gulpfile.babel.js')
| -rw-r--r-- | gulpfile.babel.js | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index f297fdb..3d214b8 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -10,8 +10,8 @@ import webpackConfig from "./webpack.conf"; import svgstore from "gulp-svgstore"; import svgmin from "gulp-svgmin"; import inject from "gulp-inject"; +import replace from "gulp-replace"; import cssnano from "cssnano"; -import uncss from "postcss-uncss"; const browserSync = BrowserSync.create(); const hugoBin = `./bin/hugo.${process.platform === "windows" ? "exe" : process.platform}`; @@ -20,7 +20,19 @@ const defaultArgs = ["-d", "../dist", "-s", "site"]; gulp.task("hugo", (cb) => buildSite(cb)); gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"])); -gulp.task("build", ["css", "js", "hugo"]); +gulp.task("cms", () => { + const match = process.env.REPOSITORY_URL ? process.env.REPOSITORY_URL : cp.execSync("git remote -v", {encoding: "utf-8"}); + let repo = null; + match.replace(/github.com:(.+?)\.git/, (_, m) => { + repo = m; + }); + gulp.src("./src/cms/*") + .pipe(replace("<% GITHUB_REPOSITORY %>", repo)) + .pipe(gulp.dest("./dist/admin")) + .pipe(browserSync.stream()); +}); + +gulp.task("build", ["css", "js", "hugo", "cms"]); gulp.task("build-preview", ["css", "js", "hugo-preview"]); gulp.task("css", () => ( @@ -29,7 +41,6 @@ gulp.task("css", () => ( cssImport({from: "./src/css/main.css"}), cssnext(), cssnano(), - // uncss({ html: ['./site/**/*.html']}) ])) .pipe(gulp.dest("./dist/css")) .pipe(browserSync.stream()) @@ -49,24 +60,23 @@ gulp.task("js", (cb) => { }); }); -gulp.task('svg', () => { - const svgs = gulp - .src('site/static/img/icons/*.svg') - .pipe(svgmin()) - .pipe(svgstore({ inlineSvg: true })); +gulp.task("svg", () => { + const svgs = gulp + .src("site/static/img/icons/*.svg") + .pipe(svgmin()) + .pipe(svgstore({inlineSvg: true})); - function fileContents(filePath, file) { - return file.contents.toString(); - } + function fileContents(filePath, file) { + return file.contents.toString(); + } - return gulp - .src('site/layouts/partials/svg.html') - .pipe(inject(svgs, { transform: fileContents })) - .pipe(gulp.dest('site/layouts/partials/')); - browserSync.reload(); + return gulp + .src("site/layouts/partials/svg.html") + .pipe(inject(svgs, {transform: fileContents})) + .pipe(gulp.dest("site/layouts/partials/")); }); -gulp.task("server", ["hugo", "css", "js", "svg"], () => { +gulp.task("server", ["hugo", "css", "js", "svg", "cms"], () => { browserSync.init({ server: { baseDir: "./dist" @@ -74,6 +84,7 @@ gulp.task("server", ["hugo", "css", "js", "svg"], () => { }); gulp.watch("./src/js/**/*.js", ["js"]); gulp.watch("./src/css/**/*.css", ["css"]); + gulp.watch("./src/cms/*", ["cms"]); gulp.watch("./site/static/img/icons/*.svg", ["svg"]); gulp.watch("./site/**/*", ["hugo"]); }); |
