Skip to content

Commit

Permalink
added support for name postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbloomnektan committed Jun 23, 2014
1 parent f5f35ec commit 7b6414f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ module.exports = function (grunt) {
name: "James D Bloom",
email: "[email protected]"
},
prefix: "prefix-",
name: "package_name",
postfix: "-postfix",
short_description: "the short description",
long_description: "the long description added to the debian package",
version: "2.0.0",
Expand Down
55 changes: 35 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ grunt.initConfig({
name: "James D Bloom",
email: "[email protected]"
},
prefix: "prefix-",
name: "package_name",
postfix: "-postfix",
short_description: "the short description",
long_description: "the long description added to the debian package",
version: "2.0.0",
Expand Down Expand Up @@ -110,18 +112,18 @@ grunt.initConfig({
});
```

This will result in a package being created called **package_name-2.0.0-1.deb**. The configuration above will result in the package containing all **\*.js**, **\*.css** and **\*.html** files in the **build** directory. These files will be installed into **/var/wwww/** when the package is installed. In addition the package will contain **/var/wwww/package_name.json** as a copy of the **config/package_name.json** file in the project. The config above will also add two soft-links and an empty directory into the package. Both the links and directories sections can use the following placeholders `${name}`, `${version}` and `${build_name}` to refer to the package name, version and build number respectively.
This will result in a package being created called **prefix-package_name-postfix-2.0.0-1.deb**. The configuration above will result in the package containing all **\*.js**, **\*.css** and **\*.html** files in the **build** directory. These files will be installed into **/var/wwww/** when the package is installed. In addition the package will contain **/var/wwww/package_name.json** as a copy of the **config/package_name.json** file in the project. The config above will also add two soft-links and an empty directory into the package. Both the links and directories sections can use the following placeholders `${name}`, `${version}` and `${build_name}` to refer to the package name, version and build number respectively.

Using the `dpkg -c package_name-2.0.0-1.deb` command it is possible to see the package contents:

```shell
dpkg -c package_name-2.0.0-1.deb
dpkg -c prefix-package_name-postfix-2.0.0-1.deb
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/doc/
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/doc/package_name/
-rw-r--r-- jenkins/jenkins 163 2014-04-27 15:08 ./usr/share/doc/package_name/changelog.Debian.gz
-rw-r--r-- jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/doc/package_name/copyright
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/doc/prefix-package_name-postfix/
-rw-r--r-- jenkins/jenkins 163 2014-04-27 15:08 ./usr/share/doc/prefix-package_name-postfix/changelog.Debian.gz
-rw-r--r-- jenkins/jenkins 0 2014-04-27 15:08 ./usr/share/doc/prefix-package_name-postfix/copyright
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./var/
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./var/app/
drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./var/app/package_name/
Expand All @@ -139,15 +141,15 @@ drwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./var/log/
lrwxr-xr-x jenkins/jenkins 0 2014-04-27 15:08 ./var/log/tomcat7 -> package_name
```

Using the `dpkg -I package_name-2.0.0-1.deb` command it is possible to see the package information:
Using the `dpkg -I prefix-package_name-postfix-2.0.0-1.deb` command it is possible to see the package information:

```shell
dpkg -I package_name-2.0.0-1.deb
dpkg -I prefix-package_name-postfix-2.0.0-1.deb
new debian package, version 2.0.
size 7300 bytes: control archive= 605 bytes.
226 bytes, 9 lines control
507 bytes, 7 lines md5sums
Package: package_name
Package: prefix-package_name-postfix
Version: 2.0.0-1
Architecture: i386
Maintainer: James D Bloom <[email protected]>
Expand All @@ -158,34 +160,34 @@ dpkg -I package_name-2.0.0-1.deb
the long description added to the debian package
```

To install the package use: `sudo dpkg -i package_name-2.0.0-1.deb`
To install the package use: `sudo dpkg -i prefix-package_name-postfix-2.0.0-1.deb`

```shell
sudo dpkg -i package_name-2.0.0-1.deb
Selecting previously unselected package package_name.
sudo dpkg -i prefix-package_name-postfix-2.0.0-1.deb
Selecting previously unselected package prefix-package_name-postfix.
(Reading database ... 39938 files and directories currently installed.)
Unpacking package_name (from package_name_2.0.0-1_i386.deb) ...
Setting up package_name (2.0.0-1) ...
Unpacking prefix-package_name-postfix (from package_name_2.0.0-1_i386.deb) ...
Setting up prefix-package_name-postfix (2.0.0-1) ...
Processing triggers for ureadahead ...
```

Once installed the `dpkg -l` command will list the package:

```shell
dpkg -l | grep package_name
package_name 2.0.0-1 the short description
dpkg -l | grep prefix-package_name-postfix
prefix-package_name-postfix 2.0.0-1 the short description
```

And `dpkg -L package_name` will list the installed files:
And `dpkg -L prefix-package_name-postfix` will list the installed files:

```shell
dpkg -L package_name
dpkg -L prefix-package_name-postfix
/.
/usr/share/
/usr/share/doc/
/usr/share/doc/package_name/
/usr/share/doc/package_name/changelog.Debian.gz
/usr/share/doc/package_name/copyright
/usr/share/doc/prefix-package_name-postfix/
/usr/share/doc/prefix-package_name-postfix/changelog.Debian.gz
/usr/share/doc/prefix-package_name-postfix/copyright
/var/
/var/app/
/var/app/package_name/
Expand Down Expand Up @@ -217,12 +219,24 @@ Default value: `process.env.DEBEMAIL`

This value specifies the maintainer's email for the debian package. The default value is taken from the standard debian environment variable `DEBEMAIL`.

#### options.prefix
Type: `String`
Default value: ''

This value specifies a prefix for the debian package name. This is useful is the package name is taken from the package.json but requires a prefix (i.e. for company name).

#### options.name
Type: `String`
Default value: **package.json** `name`

This value specifies the name of the debian package. The default value is taken from the package.json name value.

#### options.postfix
Type: `String`
Default value: ''

This value specifies a postfix for the debian package name. This is useful is the package name is taken from the package.json but requires a postfix (i.e. for git branch).

#### options.short_description
Type: `String`
Default value: **package.json** `description` first line only
Expand Down Expand Up @@ -320,6 +334,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
* 2014-03-05   v0.1.4   Added test framework and fixed bugs
* 2014-15-05   v0.1.5   Added support for dput
* 2014-16-05   v0.1.6   Fixed errors with package upload
* 2014-23-06   v0.1.7   Added support for postfix

---

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-debian-package",
"description": "Create debian package from grunt build",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "https://github.com/jamesdbloom/grunt-debian-package",
"author": {
"name": "James Bloom",
Expand Down
32 changes: 18 additions & 14 deletions tasks/debian_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@ module.exports = function (grunt) {
if (force) {
deleteFileOrDirectory(options.working_directory);
deleteFileOrDirectory(options.working_directory + packagingFilesDirectory);
deleteFileOrDirectory(packageName(options) + '*.tar.gz');
deleteFileOrDirectory(packageName(options) + '*.build');
deleteFileOrDirectory(packageName(options) + '*.changes');
deleteFileOrDirectory(packageName(options) + '*.deb');
deleteFileOrDirectory(packageLocation(options) + '*.tar.gz');
deleteFileOrDirectory(packageLocation(options) + '*.build');
deleteFileOrDirectory(packageLocation(options) + '*.changes');
deleteFileOrDirectory(packageLocation(options) + '*.deb');
} else if (!grunt.option('verbose')) {
deleteFileOrDirectory(options.working_directory + packagingFilesDirectory);
deleteFileOrDirectory(packageName(options) + '*.tar.gz');
deleteFileOrDirectory(packageName(options) + '*.build');
deleteFileOrDirectory(packageLocation(options) + '*.tar.gz');
deleteFileOrDirectory(packageLocation(options) + '*.build');
}
},
packageName = function (options) {
return options.working_directory + '/' + options.prefix + options.name;
return options.prefix + options.name + options.postfix;
},
packageLocation = function (options) {
return options.working_directory + '/' + packageName(options);
};

grunt.registerMultiTask('debian_package', 'Create debian package from grunt build', function () {
Expand All @@ -130,6 +133,7 @@ module.exports = function (grunt) {
},
name: pkg.name,
prefix: "",
postfix: "",
short_description: (pkg.description && pkg.description.split(/\r\n|\r|\n/g)[0]) || '',
long_description: (pkg.description && pkg.description.split(/\r\n|\r|\n/g).splice(1).join(' ')) || '',
version: pkg.version,
Expand Down Expand Up @@ -167,7 +171,7 @@ module.exports = function (grunt) {
findAndReplace([changelog, control], '\\$\\{maintainer.name\\}', options.maintainer.name);
findAndReplace([changelog, control], '\\$\\{maintainer.email\\}', options.maintainer.email);
findAndReplace([changelog], '\\$\\{date\\}', now);
findAndReplace([changelog, control, links, dirs], '\\$\\{name\\}', options.prefix + options.name);
findAndReplace([changelog, control, links, dirs], '\\$\\{name\\}', packageName(options));
findAndReplace([control], '\\$\\{short_description\\}', options.short_description);
findAndReplace([control], '\\$\\{long_description\\}', options.long_description);
findAndReplace([changelog, control, links, dirs], '\\$\\{version\\}', options.version);
Expand All @@ -184,19 +188,19 @@ module.exports = function (grunt) {
});
debuild.on('exit', function (code) {
if (code !== 0) {
var logFile = grunt.file.read(grunt.file.expand(packageName(options) + '*.build'));
var logFile = grunt.file.read(grunt.file.expand(packageLocation(options) + '*.build'));
grunt.log.subhead('\nerror running debuild!!');
if (logFile.search("Unmet\\sbuild\\sdependencies\\:\\sdebhelper")) {
grunt.log.warn('debhelper dependency not found try running \'sudo apt-get install debhelper\'');
}
done(false);
} else {
cleanUp(options);
grunt.log.ok('Created package: ' + grunt.file.expand(packageName(options) + '*.deb'));
grunt.log.ok('Created package: ' + grunt.file.expand(packageLocation(options) + '*.deb'));
if (options.respository) {
grunt.verbose.writeln('Running \'dput ' + options.respository + ' ' + grunt.file.expand(packageName(options) + '*.changes') + '\'');
require('fs').chmodSync("" + grunt.file.expand(packageName(options) + '*.changes'), "744");
var dputArguments = [options.respository, grunt.file.expand(packageName(options) + '*.changes')];
grunt.verbose.writeln('Running \'dput ' + options.respository + ' ' + grunt.file.expand(packageLocation(options) + '*.changes') + '\'');
require('fs').chmodSync("" + grunt.file.expand(packageLocation(options) + '*.changes'), "744");
var dputArguments = [options.respository, grunt.file.expand(packageLocation(options) + '*.changes')];
if (grunt.option('verbose')) {
dputArguments.unshift('-d');
}
Expand All @@ -207,7 +211,7 @@ module.exports = function (grunt) {
if (code !== 0) {
grunt.log.subhead('\nerror uploading package using dput!!');
} else {
grunt.log.ok('Uploaded package: ' + grunt.file.expand(packageName(options) + '*.deb'));
grunt.log.ok('Uploaded package: ' + grunt.file.expand(packageLocation(options) + '*.deb'));
}
done(true);
});
Expand Down

0 comments on commit 7b6414f

Please sign in to comment.