Skip to content

Commit bb682cd

Browse files
committed
Remove example code from ftpm-module.js
Update example code in README.md Increase exceptions management Update package.json
1 parent 5cd3bc4 commit bb682cd

File tree

7 files changed

+97
-107
lines changed

7 files changed

+97
-107
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Porting of ftpm library can be used as a class within the nodejs.
66
### Example:
77

88
var ftpmModule = require('ftpm-module');
9-
ftpmModule.getCssFont('Magra', false, true, function(type, msg) {console.log(type + ': ' + msg);});
9+
ftpmModule.getCssFont('Magra', false, function(type, msg) {console.log(type + ': ' + msg);});
1010

1111
===========
1212
### Available methods:

ftpm-module.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,4 @@ var ftpmModule = {
3535
}
3636
};
3737

38-
module.exports = ftpmModule;
39-
40-
ftpmModule.getCssFont('Magra', false, true, function(type, msg) {console.log(type + ': ' + msg);});
38+
module.exports = ftpmModule;

lib/driver/cssfont.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,53 +40,51 @@ function getCSS( name , output, base64, cb , showContent ) {
4040
}
4141

4242
var fontData = new Provider( font.name , function(err) {
43+
if (err) {
44+
ftpm.emit( 'exitMessage' , 'error' , err );
45+
} else {
46+
var css = fontData.getFontStyle();
47+
ftpm.path.checkFontPath( output , function () {
4348

44-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
49+
if ( !base64 ) {
4550

46-
var css = fontData.getFontStyle();
51+
ftpm.emit( ( (!showContent) ? 'writeFile' : 'showCss' ) , fontFullPath , css , cb );
4752

53+
} else {
4854

49-
ftpm.path.checkFontPath( output , function () {
55+
var url = fontData.getFontFileUrl(),
56+
tmpFile = '__tmpFont' + Math.floor(Math.random()*1000);
57+
58+
if (url) {
59+
ftpm.file.getRemoteFile( url , tmpFile , function( err , data ) {
60+
if (err) {
61+
ftpm.emit( 'exitMessage' , 'error' , err );
62+
} else {
63+
ftpm.file.readFile( tmpFile , 'base64', function( err, content ) {
5064

51-
if ( !base64 ) {
65+
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
5266

53-
ftpm.emit( ( (!showContent) ? 'writeFile' : 'showCss' ) , fontFullPath , css , cb );
67+
content = cssTemplate({
68+
name: font.name,
69+
base64Code: content
70+
});
5471

55-
} else {
72+
ftpm.file.unlink( tmpFile , function(err) {
5673

57-
var url = fontData.getFontFileUrl(),
58-
tmpFile = '__tmpFont' + Math.floor(Math.random()*1000);
59-
60-
if (url) {
61-
ftpm.file.getRemoteFile( url , tmpFile , function( err , data ) {
74+
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
6275

63-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
76+
ftpm.emit( ( (!showContent) ? 'writeFile' : 'showCss' ) , fontFullPath , content , cb );
6477

65-
ftpm.file.readFile( tmpFile , 'base64', function( err, content ) {
66-
67-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
68-
69-
content = cssTemplate({
70-
name: font.name,
71-
base64Code: content
72-
});
73-
74-
ftpm.file.unlink( tmpFile , function(err) {
75-
76-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
77-
78-
ftpm.emit( ( (!showContent) ? 'writeFile' : 'showCss' ) , fontFullPath , content , cb );
79-
80-
});
78+
});
8179

80+
});
81+
}
8282
});
83-
84-
});
83+
}
8584
}
86-
}
87-
88-
});
8985

86+
});
87+
}
9088
}, true);
9189
}
9290

lib/driver/osfont.js

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,25 @@ function searchInstalledFont( name , cb ) {
2929

3030
ftpm.file.readdir( font.path , function( err , files ) {
3131

32-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
32+
if (err) {
33+
ftpm.emit( 'exitMessage' , 'error' , err );
34+
} else {
35+
if( _.isEmpty( files ) ) {
3336

34-
if( _.isEmpty( files ) ) {
37+
ftpm.emit( 'successCallback' , cb , files );
3538

36-
ftpm.emit( 'successCallback' , cb , files );
39+
} else {
3740

38-
} else {
41+
var matchedFonts = _.filter( files , function( file ) {
42+
if( file.match( font.name.removeSpaces() ) ) {
43+
return file;
44+
}
45+
});
3946

40-
var matchedFonts = _.filter( files , function( file ) {
41-
if( file.match( font.name.removeSpaces() ) ) {
42-
return file;
43-
}
44-
});
45-
46-
ftpm.emit( 'successCallback' , cb , matchedFonts );
47-
48-
}
47+
ftpm.emit( 'successCallback' , cb , matchedFonts );
4948

49+
}
50+
}
5051
});
5152

5253
}
@@ -62,24 +63,22 @@ var OsFont = {
6263

6364
searchInstalledFont( font , function( err , results ) {
6465

65-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
66-
67-
if( _.isEmpty( results ) ) {
68-
69-
var fontData = new Provider( font.name , function(err) {
70-
71-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
72-
73-
ftpm.emit('writeRemoteFile', fontData.getFontFileUrl() , fontFullPath , cb );
74-
75-
});
76-
77-
} else {
78-
79-
ftpm.emit('exitMessage', 'warn', font.name + ' Font is already installed');
80-
81-
}
82-
66+
if (err) {
67+
ftpm.emit( 'exitMessage' , 'error' , err );
68+
} else {
69+
if( _.isEmpty( results ) ) {
70+
71+
var fontData = new Provider( font.name , function(err) {
72+
if (err)
73+
ftpm.emit( 'exitMessage' , 'error' , err );
74+
else
75+
ftpm.emit('writeRemoteFile', fontData.getFontFileUrl() , fontFullPath , cb );
76+
});
77+
78+
} else {
79+
ftpm.emit('exitMessage', 'warn', font.name + ' Font is already installed');
80+
}
81+
}
8382
});
8483

8584
});
@@ -92,11 +91,12 @@ var OsFont = {
9291

9392
searchInstalledFont( name , function( err , files ) {
9493

95-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
96-
97-
files = files.join('').split('.ftpm.ttf').join('\n');
98-
ftpm.emit( 'successCallback' , cb , files );
99-
94+
if (err) {
95+
ftpm.emit( 'exitMessage' , 'error' , err );
96+
} else {
97+
files = files.join('').split('.ftpm.ttf').join('\n');
98+
ftpm.emit( 'successCallback' , cb , files );
99+
}
100100
});
101101

102102
},
@@ -107,19 +107,15 @@ var OsFont = {
107107
fontFullPath = font.path + font.file;
108108

109109
searchInstalledFont( font , function( err , results ) {
110-
111-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
112-
113-
if( !_.isEmpty( results ) && _.isEqual( results[0] , font.file ) ) {
114-
115-
ftpm.file.unlink( fontFullPath , cb );
116-
117-
} else {
118-
119-
ftpm.emit('exitMessage', 'error', font.name + ' Font is not installed');
120-
121-
}
122-
110+
if (err) {
111+
ftpm.emit( 'exitMessage' , 'error' , err );
112+
} else {
113+
if( !_.isEmpty( results ) && _.isEqual( results[0] , font.file ) ) {
114+
ftpm.file.unlink( fontFullPath , cb );
115+
} else {
116+
ftpm.emit('exitMessage', 'error', font.name + ' Font is not installed');
117+
}
118+
}
123119
});
124120
}
125121

lib/driver/webfont.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ function getWebFont( name , output, cb ) {
3434

3535
var fontData = new Provider( font.name , function(err) {
3636

37-
if (err) ftpm.emit( 'exitMessage' , 'error' , err );
38-
39-
ftpm.path.checkFontPath( output , function () {
40-
41-
ftpm.emit('writeRemoteFile', fontData.getFontFileUrl() , fontFullPath , cb );
42-
43-
});
44-
37+
if (err) {
38+
ftpm.emit( 'exitMessage' , 'error' , err );
39+
} else {
40+
ftpm.path.checkFontPath( output , function () {
41+
ftpm.emit('writeRemoteFile', fontData.getFontFileUrl() , fontFullPath , cb );
42+
});
43+
}
4544
}, true);
4645

4746
}

lib/ftpm.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ ftpm.on('osfont', function(action, fontName) {
6868

6969
ftpm.on('webfont', function(action, fontName) {
7070
fontDriver.download(fontName, ftpm.outputPath, function(err, output){
71-
if (err) ftpm.emit('exitMessage', 'error', err);
72-
ftpm.emit('exitMessage', 'success', 'new webfont: ' + output);
73-
});
74-
71+
if (err)
72+
ftpm.emit('exitMessage', 'error', err);
73+
else
74+
ftpm.emit('exitMessage', 'success', 'new webfont: ' + output);
75+
});
7576
});
7677

7778
ftpm.on('cssfont', function(action, fontName) {
@@ -100,11 +101,9 @@ ftpm.on('cssfont', function(action, fontName) {
100101

101102
});
102103

103-
ftpm.on('runDriver', function( driverName , action , fontName ) {
104-
105-
fontDriver = require( fontDriver + driverName );
106-
this.emit( driverName , action , fontName );
107-
104+
ftpm.on('runDriver', function(driverName, action, fontName) {
105+
fontDriver = require(fontDriver + driverName);
106+
this.emit(driverName,action, fontName);
108107
});
109108

110109
module.exports = ftpm;

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ftpm-module",
3-
"version": "0.0.3",
4-
"description": "Porting of ftpm library can be used as a class within the nodejs.",
3+
"version": "0.0.4",
4+
"description": "Porting of ftpm library can be used as a class within nodejs.",
55
"main": "ftpm-module.js",
66
"dependencies": {
77
"lodash": "^2.4.1",
@@ -39,6 +39,6 @@
3939
"url": "https://github.com/alanmastro/ftpm-module/issues"
4040
},
4141
"homepage": "https://github.com/alanmastro/ftpm-module",
42-
"_id": "ftpm-module@0.0.3",
43-
"_resolved": "https://github.com/alanmastro/ftpm-module/archive/0.0.3.tar.gz"
42+
"_id": "ftpm-module@0.0.4",
43+
"_resolved": "https://github.com/alanmastro/ftpm-module/archive/0.0.4.tar.gz"
4444
}

0 commit comments

Comments
 (0)