Compare commits

...

14 Commits

Author SHA1 Message Date
f1d89beb06 0.0.8 2015-12-03 20:48:38 +01:00
0c0449527d added capability to read a file to a vinyl file object 2015-12-03 20:48:32 +01:00
3a76e9b572 updated readme 2015-11-28 15:47:30 +01:00
3dddb80b43 0.0.7 2015-11-24 18:57:00 +01:00
2ba06f27dc now using fs-extra for josn 2015-11-24 18:56:53 +01:00
228f855a39 now can read yaml 2015-11-24 18:52:24 +01:00
55ac57a122 0.0.6 2015-11-03 20:29:27 +01:00
7da57901dd fix dep 2015-11-03 20:29:19 +01:00
12500a0900 0.0.5 2015-11-03 20:22:21 +01:00
36371d9469 updated test 2015-11-03 20:22:16 +01:00
4e9874a639 0.0.4 2015-11-03 20:19:52 +01:00
e55e30bdb3 updated test 2015-11-03 20:19:46 +01:00
44aed02dd3 0.0.3 2015-11-03 20:14:54 +01:00
8d8d7e7ff4 fix 2015-11-03 20:14:41 +01:00
13 changed files with 209 additions and 64 deletions

View File

@ -1,39 +1,6 @@
# gulp-bootstrap
works with gulp, but does nothing. Use it to bootstrap your own gulp plugin with TypeScript, Travis and npm.
### Buildstatus/Dependencies
[![Build Status](https://travis-ci.org/pushrocks/gulp-bootstrap.svg?branch=master)](https://travis-ci.org/pushrocks/gulp-bootstrap)
[![devDependency Status](https://david-dm.org/pushrocks/gulp-bootstrap/dev-status.svg)](https://david-dm.org/pushrocks/gulp-bootstrap#info=devDependencies)
### Usage
This npm package comes with everything you need to start your own gulp plugin.
Features:
* TypeScript: Code your plugin in TypeScript
* Use gulp to compile TypeScript without the global gulp CLI Tool.
* Use travis to deploy to npm
* Have a master branch for the latest dev version
* Have a release branch for the latest npm version
This package **doesn't require global gulp** (just local -> simply do npm install`) to compile TypeScript.
* to compile TypeScript do `npm test` (You should chain your own tests to this command later on)
* to setup release do `npm run setup`
* to release a patch do `npm run release`
We recommend using travis for npm releasing and test integration.
#### The structure
```
gulp-bootstrap/
|
|- ts/
| |- compile/
| | |- compile.js **** contains gulp task`
| |- index.ts **** Your main TypeScript file.
|
|- index.js **** the compiled module
```
# smartfile
make files easily accessible for processing in javascript.
## Supported file types:
* .yml .yaml
* .json

View File

@ -1,10 +1,78 @@
/// <reference path="typings/tsd.d.ts" />
var through = require("through2");
var path = require("path");
module.exports = function (jadeTemplate, mojo) {
if (mojo === void 0) { mojo = undefined; }
return through.obj(function (file, enc, cb) {
//run callback function to signal end of plugin process.
return cb(null, file);
});
};
/// <reference path="./index.ts" />
var SmartfilePlugins;
(function (SmartfilePlugins) {
SmartfilePlugins.init = function () {
var plugins = {
beautylog: require("beautylog")("os"),
fs: require("fs-extra"),
path: require("path"),
vinyl: require("vinyl"),
vinylFile: require("vinyl-file"),
yaml: require("js-yaml")
};
return plugins;
};
})(SmartfilePlugins || (SmartfilePlugins = {}));
/// <reference path="./index.ts" />
var SmartfileSimple;
(function (SmartfileSimple) {
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
var readFileToString = function (filePath) {
var fileString;
fileString = plugins.fs.readFileSync(filePath, "utf8");
return fileString;
};
var readFileToObject = function (filePath, fileTypeArg) {
if (fileTypeArg === void 0) { fileTypeArg = "undefined"; }
var fileType;
if (fileTypeArg == "undefined") {
fileType = plugins.path.extname(filePath);
}
else {
fileType = fileTypeArg;
}
fileType = fileType.replace(/\.([a-z]*)/, "$1"); //remove . form fileType
switch (fileType) {
case "yml":
case "yaml":
try {
return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8'));
}
catch (e) {
plugins.beautylog.error("check that " + filePath.blue + " points to a valid file");
}
break;
case "json":
return plugins.fs.readJsonSync(filePath, {});
break;
}
};
SmartfileSimple.init = function (objectArg) {
objectArg.readFileToString = readFileToString;
objectArg.readFileToObject = readFileToObject;
};
})(SmartfileSimple || (SmartfileSimple = {}));
/// <reference path="./index.ts" />
var SmartfileVinyl;
(function (SmartfileVinyl) {
var readFileToVinyl = function (filePathArg, options) {
if (options === void 0) { options = {}; }
return plugins.vinylFile.readSync(filePathArg, options);
};
SmartfileVinyl.init = function (objectArg) {
objectArg.readFileToVinyl = readFileToVinyl;
};
})(SmartfileVinyl || (SmartfileVinyl = {}));
/// <reference path="./typings/tsd.d.ts" />
/// <reference path="./smartfile.plugins.ts" />
/// <reference path="./smartfile.simple.ts" />
/// <reference path="./smartfile.vinyl.ts" />
var plugins = SmartfilePlugins.init();
var smartfile = {};
SmartfileSimple.init(smartfile);
SmartfileVinyl.init(smartfile);
module.exports = smartfile;

View File

@ -1,13 +1,14 @@
{
"name": "smartfile",
"version": "0.0.2",
"version": "0.0.8",
"description": "offers smart ways to work with files in nodejs",
"main": "index.js",
"scripts": {
"test": "(cd ts/compile && node compile.js)",
"test": "(cd ts/compile && node compile.js) && (node test.js)",
"reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master)"
"update": "(git checkout master && git pull origin master && npm install)",
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)"
},
"repository": {
"type": "git",
@ -24,10 +25,16 @@
},
"homepage": "https://github.com/pushrocks/smartfile",
"dependencies": {
"pushrocks": "^1.0.18"
"beautylog": "1.0.6",
"fs-extra": "0.26.2",
"install": "^0.4.0",
"js-yaml": "3.4.6",
"vinyl": "^1.1.0",
"vinyl-file": "^1.3.0"
},
"devDependencies": {
"gulp": "3.9.0",
"gulp-typescript": "2.9.2"
"gulp-typescript": "2.10.0",
"pushrocks": "1.0.23"
}
}

8
test.js Normal file
View File

@ -0,0 +1,8 @@
/// <reference path="typings/tsd.d.ts" />
var smartfile = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info(smartfile.readFileToString("./test/mytest.txt"));
console.log(smartfile.readFileToObject("./test/mytest.yaml"));
console.log(smartfile.readFileToObject("./test/mytest.json"));
console.log(smartfile.readFileToVinyl("./test/mytest.json"));
//var thisIsAnError = smartfile.readFileToObject("./test/mytestDoesNotExist.json");

8
test/mytest.json Normal file
View File

@ -0,0 +1,8 @@
{
"key1": "this works",
"key2": "this works too",
"key3": {
"nestedkey1": "hello"
}
}

1
test/mytest.txt Normal file
View File

@ -0,0 +1 @@
This is some test text stored in ./test/mytest.txt -> If this is displayed when running "npm test", then the test has succeeded.

4
test/mytest.yaml Normal file
View File

@ -0,0 +1,4 @@
key1: this works
key2: this works too
key3:
nestedkey1: hello

View File

@ -12,7 +12,16 @@ gulp.task('compileTS', function() {
return stream;
});
gulp.task('default',['compileTS'], function() {
gulp.task('compileTestTS', function() {
var stream = gulp.src('../test.ts')
.pipe(gulpTypescript({
out: "test.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
pr.beautylog.success('Typescript compiled');
});

View File

@ -1,12 +1,15 @@
/// <reference path="typings/tsd.d.ts" />
var through = require("through2");
var path = require("path");
/// <reference path="./typings/tsd.d.ts" />
/// <reference path="./smartfile.plugins.ts" />
/// <reference path="./smartfile.simple.ts" />
/// <reference path="./smartfile.vinyl.ts" />
var plugins = SmartfilePlugins.init();
module.exports = (jadeTemplate,mojo = undefined) => {
return through.obj((file, enc, cb) => {
//run callback function to signal end of plugin process.
return cb(null, file);
});
};
var smartfile:any = {};
SmartfileSimple.init(smartfile);
SmartfileVinyl.init(smartfile);
module.exports = smartfile;

14
ts/smartfile.plugins.ts Normal file
View File

@ -0,0 +1,14 @@
/// <reference path="./index.ts" />
module SmartfilePlugins {
export var init = function() {
var plugins = {
beautylog: require("beautylog")("os"),
fs: require("fs-extra"),
path: require("path"),
vinyl: require("vinyl"),
vinylFile: require("vinyl-file"),
yaml: require("js-yaml")
};
return plugins;
}
}

39
ts/smartfile.simple.ts Normal file
View File

@ -0,0 +1,39 @@
/// <reference path="./index.ts" />
module SmartfileSimple {
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
var readFileToString = function(filePath) {
var fileString;
fileString = plugins.fs.readFileSync(filePath, "utf8");
return fileString;
};
var readFileToObject = function(filePath,fileTypeArg = "undefined") {
var fileType;
if (fileTypeArg == "undefined") {
fileType = plugins.path.extname(filePath);
} else {
fileType = fileTypeArg;
}
fileType = fileType.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
switch (fileType) {
case "yml" :
case "yaml":
try {
return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8'));
} catch (e){
plugins.beautylog.error("check that " + filePath.blue + " points to a valid file");
}
break;
case "json":
return plugins.fs.readJsonSync(filePath,{});
break;
}
};
export var init = function(objectArg) {
objectArg.readFileToString = readFileToString;
objectArg.readFileToObject = readFileToObject;
};
}

9
ts/smartfile.vinyl.ts Normal file
View File

@ -0,0 +1,9 @@
/// <reference path="./index.ts" />
module SmartfileVinyl {
var readFileToVinyl = function(filePathArg,options = {}) {
return plugins.vinylFile.readSync(filePathArg,options);
};
export var init = function(objectArg) {
objectArg.readFileToVinyl = readFileToVinyl;
};
}

8
ts/test.ts Normal file
View File

@ -0,0 +1,8 @@
/// <reference path="typings/tsd.d.ts" />
var smartfile = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info(smartfile.readFileToString("./test/mytest.txt"));
console.log(smartfile.readFileToObject("./test/mytest.yaml"));
console.log(smartfile.readFileToObject("./test/mytest.json"));
console.log(smartfile.readFileToVinyl("./test/mytest.json"));
//var thisIsAnError = smartfile.readFileToObject("./test/mytestDoesNotExist.json");