first commit

This commit is contained in:
armansansd
2023-07-12 16:31:19 +01:00
commit 3424b1927b
23306 changed files with 2217776 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 Shinnosuke Watanabe
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+109
View File
@@ -0,0 +1,109 @@
# output-file-sync
[![Build Status](https://travis-ci.org/shinnn/output-file-sync.svg?branch=master)](https://travis-ci.org/shinnn/output-file-sync)
[![Build status](https://ci.appveyor.com/api/projects/status/3qjn5ktuqb6w2cae?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/output-file-sync)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/output-file-sync.svg)](https://coveralls.io/r/shinnn/output-file-sync)
[![Dependency Status](https://david-dm.org/shinnn/output-file-sync.svg)](https://david-dm.org/shinnn/output-file-sync)
[![devDependency Status](https://david-dm.org/shinnn/output-file-sync/dev-status.svg)](https://david-dm.org/shinnn/output-file-sync#info=devDependencies)
Synchronously write a file and create its ancestor directories if needed
```javascript
var fs = require('fs');
var outputFileSync = require('output-file-sync');
outputFileSync('foo/bar/baz.txt', 'Hi!');
fs.readFileSync('foo/bar/baz.txt').toString(); //=> 'Hi!'
```
## Difference from fs.outputFileSync
This module is very similar to [fs-extra](https://github.com/jprichardson/node-fs-extra)'s [`fs.outputFileSync`](https://github.com/jprichardson/node-fs-extra#outputfilefile-data-callback) but they are different in the following points:
1. *output-file-sync* returns the path of the directory created first. [See the API document for more details.](#outputfilesyncpath-data--options)
2. *output-file-sync* accepts [mkdirp] options.
```javascript
var fs = require('fs');
var outputFileSync = require('output-file-sync');
outputFileSync('foo/bar', 'content', {mode: 33260});
fs.statSync('foo').mode; //=> 33260
```
## Installation
[![NPM version](https://badge.fury.io/js/output-file-sync.svg)](https://www.npmjs.org/package/output-file-sync)
[Use npm.](https://www.npmjs.org/doc/cli/npm-install.html)
```sh
npm install output-file-sync
```
## API
```javascript
var outputFileSync = require('output-file-sync');
```
### outputFileSync(*path*, *data* [, *options*])
*path*: `String`
*data*: `String` or [`Buffer`](http://nodejs.org/api/buffer.html#buffer_class_buffer)
*options*: `Object` or `String` (options for [fs.writeFile] and [mkdirp])
Return: `String` if it creates more than one directories, otherwise `null`
It writes the data to a file synchronously. If ancestor directories of the file don't exist, it creates the directories before writing the file.
```javascript
var fs = require('fs');
var outputFileSync = require('output-file-sync');
// When the directory `foo/bar` exists
outputFileSync('foo/bar/baz/qux.txt', 'Hello', 'utf-8');
fs.statSync('foo/bar/baz').isDirectory(); //=> true
fs.statSync('foo/bar/baz/qux.txt').isFile(); //=> true
```
It returns the directory path just like [mkdirp.sync](https://github.com/substack/node-mkdirp#mkdirpsyncdir-opts):
> Returns the first directory that had to be created, if any.
```javascript
var dir = outputFileSync('foo/bar/baz.txt', 'Hello');
dir; //=> Same value as `path.resolve('foo')`
```
#### options
All options for [fs.writeFile] and [mkdirp] are available.
Additionally, you can use [`fileMode`](#optionsfilemode) option and [`dirMode`](#optionsdirmode) option to set different permission between the file and directories.
##### options.fileMode
Set modes of a file, overriding `mode` option.
##### options.dirMode
Set modes of a directories, overriding `mode` option.
```javascript
outputFileSync('dir/file', 'content', {dirMode: '0745', fileMode: '0644'});
fs.statSync('dir').mode.toString(8); //=> '40745'
fs.statSync('dir/file').mode.toString(8); //=> '100644'
```
## Related project
* [output-file](https://github.com/shinnn/output-file) (asynchronous version)
## License
Copyright (c) 2014 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).
[fs.writeFile]: http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback
[mkdirp]: https://github.com/substack/node-mkdirp
+37
View File
@@ -0,0 +1,37 @@
/*!
* output-file-sync | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/output-file-sync
*/
'use strict';
var dirname = require('path').dirname;
var writeFileSync = require('fs').writeFileSync;
var xtend = require('xtend');
var mkdirpSync = require('mkdirp').sync;
module.exports = function outputFileSync(filePath, data, options) {
options = options || {};
var mkdirpOptions;
if (typeof options === 'string') {
mkdirpOptions = null;
} else {
if (options.dirMode) {
mkdirpOptions = xtend(options, {mode: options.dirMode});
} else {
mkdirpOptions = options;
}
}
var writeFileOptions;
if (options.fileMode) {
writeFileOptions = xtend(options, {mode: options.fileMode});
} else {
writeFileOptions = options;
}
var createdDirPath = mkdirpSync(dirname(filePath), mkdirpOptions);
writeFileSync(filePath, data, writeFileOptions);
return createdDirPath;
};
+85
View File
@@ -0,0 +1,85 @@
{
"_from": "output-file-sync@1.1.0",
"_id": "output-file-sync@1.1.0",
"_inBundle": false,
"_integrity": "sha1-sQ3GCJP4PeheXVU6djJwWSlf+NY=",
"_location": "/output-file-sync",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "output-file-sync@1.1.0",
"name": "output-file-sync",
"escapedName": "output-file-sync",
"rawSpec": "1.1.0",
"saveSpec": null,
"fetchSpec": "1.1.0"
},
"_requiredBy": [
"/6to5-core"
],
"_resolved": "https://registry.npmjs.org/output-file-sync/-/output-file-sync-1.1.0.tgz",
"_shasum": "b10dc60893f83de85e5d553a76327059295ff8d6",
"_spec": "output-file-sync@1.1.0",
"_where": "/srv/http/mmap_sarrebourg/user/themes/basic/node_modules/6to5-core",
"author": {
"name": "Shinnosuke Watanabe",
"url": "https://github.com/shinnn"
},
"bugs": {
"url": "https://github.com/shinnn/output-file-sync/issues"
},
"bundleDependencies": false,
"dependencies": {
"mkdirp": "^0.5.0",
"xtend": "^4.0.0"
},
"deprecated": false,
"description": "Synchronously write a file and create its ancestor directories if needed",
"devDependencies": {
"eslint": "^0.10.0",
"istanbul": "^0.3.2",
"istanbul-coveralls": "^1.0.1",
"jscs": "^1.8.0",
"read-remove-file": "^1.0.0",
"tap-spec": "^2.1.0",
"tape": "^3.0.3"
},
"files": [
"index.js",
"LICENSE"
],
"homepage": "https://github.com/shinnn/output-file-sync#readme",
"jscsConfig": {
"preset": "google",
"maximumLineLength": 98
},
"keywords": [
"fs",
"write",
"sync",
"synchronous",
"output",
"file",
"mkdir",
"mkdirp"
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/shinnn/output-file-sync/blob/master/LICENSE"
}
],
"name": "output-file-sync",
"repository": {
"type": "git",
"url": "git+https://github.com/shinnn/output-file-sync.git"
},
"scripts": {
"coverage": "istanbul cover test.js; ${npm_package_scripts_clean}",
"coveralls": "istanbul cover test.js && istanbul-coveralls",
"pretest": "eslint *.js & jscs *.js",
"test": "node test.js | tap-spec;"
},
"version": "1.1.0"
}