Git Product home page Git Product logo

node-touch's Introduction

node-touch

For all your node touching needs.

Installing

npm install touch

CLI Usage:

See man touch

This package exports a binary called nodetouch that works mostly like the unix builtin touch(1).

API Usage:

var touch = require("touch")

Gives you the following functions:

  • touch(filename, options, cb)
  • touch.sync(filename, options)
  • touch.ftouch(fd, options, cb)
  • touch.ftouchSync(fd, options)

All the options objects are optional.

All the async functions return a Promise. If a callback function is provided, then it's attached to the Promise.

Options

  • force like touch -f Boolean
  • time like touch -t <date> Can be a Date object, or any parseable Date string, or epoch ms number.
  • atime like touch -a Can be either a Boolean, or a Date.
  • mtime like touch -m Can be either a Boolean, or a Date.
  • ref like touch -r <file> Must be path to a file.
  • nocreate like touch -c Boolean

If neither atime nor mtime are set, then both values are set. If one of them is set, then the other is not.

cli

This package creates a nodetouch command line executable that works very much like the unix builtin touch(1)

node-touch's People

Contributors

isaacs avatar sanemat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-touch's Issues

v3 rewrite

  • Create two classes, Touch and TouchSync. Override just the fs-calling bits to swap out the sync-ness. (Pattern established in minipass, minizlib, and tar.)
  • Async method returns a promise, attaches the cb to it if provided.
  • handle directories (or at least, error properly)
  • Don't use nopt in the bin
  • bin takes a timestamp like touch(1)
  • tap --100 test coverage

node-touch is noisy

Another dependency installed node-touch in my node modules so now I can't call the unix version from my package.json scripts and am stuck with it. The only real difference is that node-touch error logs the returned fs.stat object. Can this not be the default behavior?

Error when touching directories

$ touch node_modules/
bad touch!
/Users/mstade/dev/websdk/nap/node_modules/touch/bin/touch.js:28
      throw er
      ^

Error: EISDIR: illegal operation on a directory, open 'node_modules/'
    at Error (native)

Quite possibly out of scope for the module, but figured I'd report it either way.


I don't use this module myself, but ran into a problem with builds suddenly failing because of it. The reason is during the build, the $PATH variable is prepended with node_modules/.bin, so local executables can be conveniently used in the Makefile. Because it's prepended, touch takes precedence over the system touch, and because this module doesn't work with directories the build failed.

The builds started suddenly failing, because Travis CI started including Node 5.0 in their environment setup. This includes npm 3, which has the new flat module layout. This brought up the this module from the node_modules depths, and voila โ€“ failing builds.

Interesting little detour. :o)

It was easy enough to fix. Just changed it to append node_modules/.bin to $PATH, as opposed to prepending it:

PATH := $(PATH):node_modules/.bin

Someone else might run into the same issue, so hopefully searching will lead them here.

atime is not set when passing a Date as the documentation says

In onopen:

  onopen (er, fd) {
    if (er) {
      if (er.code === 'EISDIR')
        this.onopen(null, null)
      else if (er.code === 'ENOENT' && this.nocreate)
        this.emit('done')
      else
        this.emit('error', er)
    } else {
      this.fd = fd
      if (this.ref)
        this.statref()
      else if (!this.atime || !this.mtime)
        this.fstat()
      else
        this.futimes()
    }
  }

In onfstat:

  onfstat (st) {
    if (typeof this.atime !== 'number')
      this.atime = parseInt(st.atime.getTime()/1000, 10)

    if (typeof this.mtime !== 'number')
      this.mtime = parseInt(st.mtime.getTime()/1000, 10)

    this.futimes()
  }

If atime or mtime is missing stat is called:

      else if (!this.atime || !this.mtime)
        this.fstat()

In the stat callback onstat if atime is not number it is overwritten with the value returned by stat:

    if (typeof this.atime !== 'number')
      this.atime = parseInt(st.atime.getTime()/1000, 10)

The doc says atime should be a date not a number

atime like touch -a Can be either a Boolean, or a Date.

The doc is wrong but this causes a bug that is hard to debug.

touch -h

Any idea how to implement such option in nodejs ?

Changelog

Hi,

It would be useful to get the list of changes and bugfixes between versions, with migrations notes or recommendations if any. For now we have to check in the code if any change in the API was made, and it can take some time when you have a lot of dependencies to update.

Please provide a CHANGELOG.md file or GitHub releases.

Thank you.

Does not work with babel & ES6

import * as touch from 'node-touch';

C:\projects\theben3\node_modules\node-inserted\index.js:5
var elem = document.createElement('style');
^

ReferenceError: document is not defined
at module.exports (C:\projects\theben3\node_modules\node-inserted\index.js:5:12)
at Object. (C:\projects\theben3\node_modules\node-touch\index.js:1:25)
at Module._compile (module.js:635:30)
at Module._extensions..js (module.js:646:10)
at Object.require.extensions.(anonymous function) [as .js] (C:\projects\theben3\node_modules\babel-register\lib\node.js:152:7)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)

Got a strange error

When I was trying to use this module I got the following error:

ReferenceError: document is not defined
 at module.exports (C:\Develop\trunk\node_modules\node-touch\node_modules\node-inserted\index.js:5:12)
 at Object.<anonymous> (C:\Develop\trunk\node_modules\node-touch\index.js:1:87)

I am using node 0.10.32 on Windows 7 64bit.

Project Status?

Is this project still alive? Asking, since there are outdated dependencies.

Edit: Just seen that fs.utimesSync will do as a good substitute.

win32 fun: touch throws an error in fs.js for openSync

Trying to use touch to make sure a file exists before it's used as a stream, and am getting this error:

c:\users\mike\documents\Git projects\released\flickrmirror>node app

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'c:\users\mike\documents\Git projects\released\flickrmirror\logs\2013-11-23 13:14:24.log'
    at Object.fs.openSync (fs.js:427:18)
    at openThenF (c:\users\mike\documents\Git projects\released\flickrmirror\node_modules\touch\touch.js:76:40)
    at touch_ (c:\users\mike\documents\Git projects\released\flickrmirror\node_modules\touch\touch.js:69:10)
    at optionsRef (c:\users\mike\documents\Git projects\released\flickrmirror\node_modules\touch\touch.js:41:28)
    at touch (c:\users\mike\documents\Git projects\released\flickrmirror\node_modules\touch\touch.js:65:10)
    at getFileStream (c:\users\mike\documents\Git projects\released\flickrmirror\app.js:84:11)
    at c:\users\mike\documents\Git projects\released\flickrmirror\app.js:87:19
    at Function.<anonymous> (c:\users\mike\documents\Git projects\released\flickrmirror\app.js:100:4)
    at Function.app.configure (c:\users\mike\documents\Git projects\released\flickrmirror\node_modules\express\lib\application.js:393:61)
    at Object.<anonymous> (c:\users\mike\documents\Git projects\released\flickrmirror\app.js:75:5)

Relevant code in the actual app.js:

var dateFormat = require("dateformat"),
    touch = require("touch"),
    getFileStream = function() {
      var now = new Date(),
          suffix = dateFormat(now, "yyyy-mm-dd HH:MM:ss"),
          logfile = "./logs/" + suffix + ".log";
      touch(logfile);
      return fs.createWriteStream(logfile, { flags: 'a+' });
    },
    logfile = getFileStream();

This is on windows 7 pro, 64 bit version.

Publish as nodetouch?

Hey @isaacs - I was wondering if you'd want to publish this as nodetouch for easier use with npx?

Difference between the commands would be:
npx -p touch nodetouch gulpfile.js
vs
npx nodetouch gulpfile.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.