Socket
Socket
Sign inDemoInstall

broccoli-file-creator

Package Overview
Dependencies
25
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 1.0.0

46

index.js
var fs = require('fs');
var path = require('path');
var Writer = require('broccoli-writer');
var Promise = require('rsvp').Promise
var Plugin = require('broccoli-plugin');
var symlinkOrCopySync = require('symlink-or-copy').sync;
var mkdirp = require('mkdirp');
Creator.prototype = Object.create(Writer.prototype);
module.exports = Creator;
Creator.prototype = Object.create(Plugin.prototype);
Creator.prototype.constructor = Creator;
function Creator (filename, content, options) {
function Creator (filename, content, _options) {
if (!(this instanceof Creator)) return new Creator(filename, content, options);
var options = _options || { encoding: 'utf8' };
this.content = content;
this.filename = filename;
this.fileOptions = options || { encoding: 'utf8' };
Plugin.call(this, [/* no inputTrees */], {
annotation: options.annotation || this.constructor.name + ' ' + filename
});
delete options.annotation;
this.content = content;
this.filename = filename;
this.fileOptions = options;
};
Creator.prototype.write = function (readTree, destDir) {
var _this = this
Creator.prototype.build = function () {
var cacheFilePath = path.join(this.cachePath, this.filename);
var outputFilePath = path.join(this.outputPath, this.filename);
return Promise.resolve().then(function() {
fs.writeFileSync(path.join(destDir, _this.filename), _this.content, _this.fileOptions);
});
writeToCache(cacheFilePath, this.content, this.fileOptions);
linkFromCache(cacheFilePath, outputFilePath);
};
module.exports = Creator;
function writeToCache(cacheFilePath, content, options) {
if (fs.existsSync(cacheFilePath)) { return; }
mkdirp.sync(path.dirname(cacheFilePath));
fs.writeFileSync(cacheFilePath, content, options);
}
function linkFromCache(from, to) {
mkdirp.sync(path.dirname(to.outputFile));
symlinkOrCopySync(from, to);
}
{
"name": "broccoli-file-creator",
"version": "0.1.0",
"version": "1.0.0",
"description": "Broccoli plugin to create a file.",

@@ -13,3 +13,4 @@ "main": "index.js",

"scripts": {
"test": "mocha tests/"
"test": "mocha tests/",
"test:debug": "mocha debug tests/"
},

@@ -21,12 +22,15 @@ "keywords": [

"dependencies": {
"broccoli-kitchen-sink-helpers": "~0.2.0",
"broccoli-plugin": "^1.1.0",
"broccoli-writer": "~0.1.1",
"broccoli-kitchen-sink-helpers": "~0.2.0",
"rsvp": "~3.0.6"
"mkdirp": "^0.5.1",
"rsvp": "~3.0.6",
"symlink-or-copy": "^1.0.1"
},
"devDependencies": {
"mocha": "~1.18.2",
"rimraf": "~2.2.6",
"broccoli": "~0.9.0",
"expect.js": "~0.3.1"
"broccoli": "^0.16.7",
"chai": "^3.2.0",
"mocha": "^2.2.5",
"rimraf": "~2.2.6"
}
}
# Broccoli's File Creator
[![Build Status](https://travis-ci.org/rjackson/broccoli-file-creator.svg?branch=master)](https://travis-ci.org/rjackson/broccoli-file-creator)
## Usage

@@ -4,0 +6,0 @@

'use strict';
var writeFile = require('../index');
var expect = require('expect.js');
var chai = require('chai');
var expect = chai.expect;
var rimraf = require('rimraf');

@@ -13,2 +14,22 @@ var root = process.cwd();

chai.Assertion.addMethod('sameStatAs', function(otherStat) {
this.assert(
this._obj.mode === otherStat.mode,
'expected mode ' + this._obj.mode + ' to be same as ' + otherStat.mode,
'expected mode ' + this._obj.mode + ' to not the same as ' + otherStat.mode
);
this.assert(
this._obj.size === otherStat.size,
'expected size ' + this._obj.size + ' to be same as ' + otherStat.size,
'expected size ' + this._obj.size + ' to not the same as ' + otherStat.size
);
this.assert(
this._obj.mtime.getTime() === otherStat.mtime.getTime(),
'expected mtime ' + this._obj.mtime.getTime() + ' to be same as ' + otherStat.mtime.getTime(),
'expected mtime ' + this._obj.mtime.getTime() + ' to not the same as ' + otherStat.mtime.getTime()
);
});
describe('broccoli-file-creator', function(){

@@ -26,6 +47,26 @@ afterEach(function() {

builder = new broccoli.Builder(tree);
return builder.build().then(function(dir) {
expect(fs.readFileSync(dir + '/something.js', {encoding: 'utf8'})).to.eql(content);
return builder.build().then(function(result) {
expect(fs.readFileSync(result.directory + '/something.js', {encoding: 'utf8'})).to.eql(content);
});
})
});
it('correctly caches', function(){
var content = 'ZOMG, ZOMG, HOLY MOLY!!!';
var tree = writeFile('/something.js', content);
builder = new broccoli.Builder(tree);
var stat;
return builder.build().then(function(result) {
stat = fs.lstatSync(result.directory + '/something.js');
debugger;
return builder.build();
}).then(function(result){
stat;
var newStat = fs.lstatSync(result.directory + '/something.js');
expect(newStat).to.be.sameStatAs(stat);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc