Skip to content

Commit 602609f

Browse files
committed
pulling in changes from CatturaGreg (PR #30).
1 parent aa721e6 commit 602609f

File tree

6 files changed

+214
-60
lines changed

6 files changed

+214
-60
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ node_modules/
88
*.yml
99
Gulpfile.js
1010
json2yaml.js
11+
jic.js
1112
demo_0.1-2_i386.json
1213
package-0.1.5.json

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
### gulp-debian
22
> :tropical_drink: Gulp plug-in to create a Debian package.
33
4-
<!-- We need new CI
4+
<!-- We need new CI
55
[![Build Status](https://travis-ci.org/stpettersens/gulp-debian.png?branch=master)](https://travis-ci.org/stpettersens/gulp-debian)
66
-->
77
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
88
[![npm version](https://badge.fury.io/js/gulp-debian.svg)](http://npmjs.com/package/gulp-debian)
9-
<!-- David DM seems to be gone
9+
<!-- David DM seems to be gone
1010
[![Dependency Status](https://david-dm.org/stpettersens/gulp-debian.png?theme=shields.io)](https://david-dm.org/stpettersens/gulp-debian) [![Development Dependency Status](https://david-dm.org/stpettersens/gulp-debian/dev-status.png?theme=shields.io)](https://david-dm.org/stpettersens/gulp-debian?type=dev)
1111
-->
1212

@@ -133,6 +133,7 @@ gulp.task('default', function (done) {
133133
* [Alexey Lukomsky](https://github.com/lucomsky)
134134
* [haslinghuis](https://github.com/haslinghuis)
135135
* [Dominic Clifton](https://github.com/hydra)
136+
* [Gregory Marco](https://github.com/CatturaGreg)
136137

137138
##### License
138139

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ module.exports = function (pkg) {
156156
installScript('postinst', pkg.postinst, out, cb)
157157
installScript('prerm', pkg.prerm, out, cb)
158158
installScript('postrm', pkg.postrm, out, cb)
159-
installScript('triggers', pkg.triggers, out, cb)
160159
installCopyright(pkg.package, pkg._copyright, out, cb)
161160
installConffiles(pkg.conffiles, out, cb)
162161
ctrl = ctrl.filter(function (line) {

jic.js

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
'use strict'
2+
3+
const gutil = require('gulp-util')
4+
const through = require('through2')
5+
const titleCase = require('title-case')
6+
const fs = require('fs-extra')
7+
const find = require('find')
8+
const _exec = require('child_process').exec
9+
10+
const P = 'gulp-debian'
11+
const dirMode = 755 /* chmod param for directory */
12+
const fileMode = 644 /* chmod param for ordinary file */
13+
14+
function deb (files, pkg, cb) {
15+
let ctrl = []
16+
for (let key in pkg) {
17+
ctrl.push(`${titleCase(key)}: ${pkg[key]}`)
18+
}
19+
ctrl.push(' ')
20+
return cb(null, ctrl)
21+
}
22+
23+
function changelog (pkg) {
24+
let log = []
25+
for (let i = 0; i < pkg.changelog.length; i++) {
26+
let header = `${pkg.package} (${pkg.changelog[i].version}) `
27+
header += `${pkg.changelog[i].distribution}; urgency=${pkg.changelog[i].urgency}`
28+
log.push(header + '\n')
29+
for (let x = 0; x < pkg.changelog[i].changes.length; x++) {
30+
log.push(` * ${pkg.changelog[i].changes[x]}`)
31+
}
32+
const ts = Date.parse(pkg.changelog[i].date)
33+
var d = new Date(ts)
34+
d = d.toString().replace(/([a-zA-Z]*) ([a-zA-Z]*) ([0-9]*) ([0-9]*) ([0-9:]*) GMT(.....) .*/, '$1, $3 $2 $4 $5 $6')
35+
log.push(`\n -- ${pkg.maintainer} ${d}\n`)
36+
}
37+
log.push('')
38+
return log
39+
}
40+
41+
function writeChangelog (pkg, out, cb) {
42+
const logf = changelog(pkg)
43+
if (logf.length > 0) {
44+
const logp = `${out}/usr/share/doc/${pkg.package}`
45+
const logo = `${logp}/changelog.Debian`
46+
fs.mkdirpSync(logp)
47+
fs.outputFile(logo, logf.join('\n'),
48+
function (err) {
49+
if (err) {
50+
cb(new gutil.PluginError(P, err))
51+
return
52+
}
53+
_exec(`gzip -fn9 ${logo}; chmod ${fileMode} ${logo}.gz`,
54+
function (err, stdout, stderr) {
55+
if (stderr) {
56+
gutil.log(gutil.colors.red(stderr.trim()))
57+
cb(err)
58+
}
59+
})
60+
})
61+
}
62+
}
63+
64+
function installScript (fn, script, out, cb) {
65+
if (script !== undefined && script.length > 0) {
66+
const o = `${out}/DEBIAN/${fn}`
67+
if (typeof script === 'string') {
68+
if (fs.existsSync(script)) {
69+
fs.copySync(script, o)
70+
fs.chmodSync(o, parseInt('0755', 8))
71+
} else {
72+
cb(new gutil.PluginError(P, `File ${script} not exist!`))
73+
// return
74+
}
75+
} else {
76+
script.push('')
77+
fs.outputFile(o, script.join('\n'), function (err) {
78+
if (err) {
79+
cb(new gutil.PluginError(P, err))
80+
// return
81+
}
82+
fs.chmodSync(o, parseInt('0755', 8))
83+
})
84+
}
85+
}
86+
}
87+
88+
function installCopyright (pn, path, out, cb) {
89+
if (fs.existsSync(path)) {
90+
const o = `${out}/usr/share/doc/${pn}/copyright`
91+
fs.copySync(path, o)
92+
fs.chmodSync(o, parseInt('0644', 8))
93+
} else {
94+
gutil.log(gutil.colors.red(`Error reading copyright file!`))
95+
}
96+
}
97+
98+
function installConffiles (path, out, cb) {
99+
var conffiles = []
100+
var files = find.fileSync(path)
101+
path = path.replace(/\/$/, '')
102+
files.forEach(function (item) {
103+
let pathDest = item.split('/').slice(path.split('/').length)
104+
fs.copySync(item, `${out}/${pathDest.join('/')}`)
105+
fs.chmodSync(`${out}/${pathDest.join('/')}`, parseInt(`0${fileMode}`, 8))
106+
pathDest = '/' + pathDest.join('/')
107+
conffiles.push(pathDest)
108+
})
109+
conffiles.push('')
110+
fs.outputFileSync(`${out}/DEBIAN/conffiles`, conffiles.join('\n'))
111+
fs.chmodSync(`${out}/DEBIAN/conffiles`, parseInt(`0${fileMode}`, 8))
112+
}
113+
114+
function chmodRegularFile (path, cb) {
115+
if (fs.statSync(path).isFile()) {
116+
fs.chmodSync(path, parseInt(`0${fileMode}`, 8))
117+
} else {
118+
fs.readdirSync(path).forEach(file => {
119+
chmodRegularFile(`${path}/${file}`, cb)
120+
})
121+
}
122+
}
123+
124+
module.exports = function (pkg) {
125+
let files = []
126+
return through.obj(function (file, enc, cb) {
127+
if (file.isStream()) {
128+
cb(new gutil.PluginError(P, 'Streaming not supported.'))
129+
// return
130+
}
131+
files.push(file)
132+
cb(null)
133+
}, function (cb) {
134+
if (typeof pkg === 'string') {
135+
pkg = fs.readJSONSync(pkg)
136+
}
137+
deb(files, pkg, function (err, ctrl) {
138+
if (pkg._verbose === undefined) {
139+
pkg._verbose = true
140+
}
141+
if (pkg._target === undefined || pkg._out === undefined) {
142+
cb(new gutil.PluginError(P, '_target and/or _out undefined.'))
143+
// return
144+
}
145+
if (pkg._copyright === undefined) {
146+
gutil.log(gutil.colors.cyan('_copyright may be omitted, but it is highly recommended to define.'))
147+
// cb(new gutil.PluginError(P, '_copyright undefined!'))
148+
// return
149+
}
150+
if (err) {
151+
cb(new gutil.PluginError(P, err, {filename: files[0].path}))
152+
// return
153+
}
154+
let out = `${pkg._out}/${pkg.package}_${pkg.version}_${pkg.architecture}`
155+
installScript('preinst', pkg.preinst, out, cb)
156+
installScript('postinst', pkg.postinst, out, cb)
157+
installScript('prerm', pkg.prerm, out, cb)
158+
installScript('postrm', pkg.postrm, out, cb)
159+
installScript('triggers', pkg.triggers, out, cb)
160+
installCopyright(pkg.package, pkg._copyright, out, cb)
161+
installConffiles(pkg.conffiles, out, cb)
162+
ctrl = ctrl.filter(function (line) {
163+
if (!/Out|Target|Verbose|Changelog|Preinst|Postinst|Prerm|Postrm|Clean|Copyright|Conffiles/.test(line)) {
164+
return line
165+
}
166+
})
167+
168+
writeChangelog(pkg, out, cb)
169+
170+
fs.mkdir(`${out}/DEBIAN`, '0775', function (err) {
171+
if (err) {
172+
cb(new gutil.PluginError(P, err))
173+
// return
174+
}
175+
176+
files.map(function (f) {
177+
let t = f.path.split('/')
178+
t = t[t.length - 1]
179+
fs.copySync(f.path, `${out}/${pkg._target}/${t}`)
180+
chmodRegularFile(`${out}/${pkg._target}/${t}`)
181+
})
182+
_exec(`chmod ${dirMode} $(find ${pkg._out} -type d)`)
183+
_exec(`dpkg-deb -Zxz --build ${pkg._out}/${pkg.package}_${pkg.version}_${pkg.architecture}`,
184+
function (err, stdout, stderr) {
185+
if (pkg._clean) {
186+
fs.removeSync(`${pkg._out}/${pkg.package}_${pkg.version}_${pkg.architecture}`)
187+
}
188+
if (pkg._verbose && stdout.length > 1) {
189+
gutil.log(stdout.trim() + '\n')
190+
}
191+
if (stderr) {
192+
gutil.log(gutil.colors.red(stderr.trim()))
193+
}
194+
const ctrlf = ctrl.join('\n')
195+
fs.outputFile(`${out}/DEBIAN/control`, ctrlf.substr(0, ctrlf.length - 1),
196+
function (err) {
197+
if (err) {
198+
cb(new gutil.PluginError(P, err))
199+
// return
200+
}})
201+
})
202+
})
203+
})
204+
})
205+
}

package-0.1.5.json

Lines changed: 0 additions & 56 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-debian",
3-
"version": "0.2.0",
3+
"version": "0.3.1",
44
"description": "Gulp plug-in to create a Debian package",
55
"main": "index.js",
66
"scripts": {
@@ -43,6 +43,10 @@
4343
{
4444
"name": "Dominic Clifton",
4545
"url": "https://github.com/hydra"
46+
},
47+
{
48+
"name": "Gregory Marco",
49+
"url": "https://github.com/CatturaGreg"
4650
}
4751
],
4852
"license": "MIT",

0 commit comments

Comments
 (0)