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

Automate copyright notice #77

Merged
merged 9 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Update the version in typopo.js before committing
gulp updateTypopoJsCopyrightBanner

# Add updated files to the commit
git add src/typopo.js

# run build
pnpm build

# Add dist folder to the commit
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### 🔨 Maintenance
- Add a build automation
- Automate copyright notice updates in source and dist files



Expand Down
5 changes: 5 additions & 0 deletions dist/typopo.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/typopo_dist.min.js

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const replace = require('gulp-replace');
const header = require('gulp-header');
const packageJson = require('./package.json');

const currentYear = new Date().getFullYear();

var paths = {
dev: {
Expand All @@ -23,12 +28,31 @@ var paths = {
src: 'src/typopo.js',
name: 'typopo_dist.min.js',
dest: 'dist/'
},
root: {
src: 'src/typopo.js',
dest: 'src/'
}
};

/*
* Define our tasks using plain functions
// Copyright banner for the minified files
const copyrightBanner = `/*!
* Typopo v${packageJson.version} (https://typopo.org)
* Copyright 2015–${currentYear} Braňo Šandala (https://brano.me)
* Licensed under MIT (https://github.com/surfinzap/typopo/blob/main/LICENSE.txt)
*/
`;

// Update version in typopo.js
function updateTypopoJsCopyrightBanner() {

const bannerRegex = /\/\*\![\s\S]*?\*\/\s*/;

return gulp.src(paths.root.src)
.pipe(replace(bannerRegex, ''))
.pipe(header(copyrightBanner))
.pipe(gulp.dest(paths.root.dest));
}

function devBrowserBuild() {
return browserify({entries: paths.browser.src, debug: true})
Expand All @@ -39,17 +63,17 @@ function devBrowserBuild() {
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(paths.dev.dest))
}

}

function browserBuild() {
return browserify({ entries: paths.browser.src, debug: false })
.transform(babelify)
.bundle()
.pipe(source(paths.browser.name))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.browser.dest));
.transform(babelify)
.bundle()
.pipe(source(paths.browser.name))
.pipe(buffer())
.pipe(uglify())
.pipe(header(copyrightBanner)) // Add the header
.pipe(gulp.dest(paths.browser.dest));
}

function npmBuild() {
Expand All @@ -59,7 +83,8 @@ function npmBuild() {
.pipe(source(paths.npm.name))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.npm.dest))
.pipe(header(copyrightBanner)) // Add the header
.pipe(gulp.dest(paths.npm.dest));
}

function copyHtmlToDest() {
Expand Down Expand Up @@ -103,6 +128,7 @@ const build = gulp.parallel(npmBuild, browserBuild, copyHtmlToDest);

exports.watch = watch;
exports.build = build;
exports.updateTypopoJsCopyrightBanner = updateTypopoJsCopyrightBanner;
/*
* Define default task that can be called by just running `gulp` from cli
*/
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"author": {
"name": "Braňo Šandala",
"email": "[email protected]"
"email": "[email protected]"
},
"scripts": {
"dev": "gulp watch",
Expand Down Expand Up @@ -53,6 +53,8 @@
"gulp-babel": "^8.0.0",
"gulp-cli": "^3.0.0",
"gulp-concat": "^2.6.1",
"gulp-header": "^2.0.9",
"gulp-replace": "^1.1.4",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify": "^3.0.2",
"husky": "^9.1.6",
Expand Down
96 changes: 96 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/typopo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/*!
* Typopo 2.5.5
*
* Copyright 2015–24 Braňo Šandala
* Released under the MIT license
*
* Date: 2023-08-27
* Typopo v2.5.7 (https://typopo.org)
* Copyright 2015–2024 Braňo Šandala (https://brano.me)
* Licensed under MIT (https://github.com/surfinzap/typopo/blob/main/LICENSE.txt)
*/

import Locale from "./locale/locale";
import {removeEmptyLines} from "./lib/whitespace/lines";
import {fixNbsp} from "./lib/whitespace/nbsp";
Expand Down
Loading