How to add async callbacks in node to a function call?

Question is too broad / unclear. Anyone interested in this answer would be better served by visiting: Creating Callbacks for required modules in node.js

Basically I have included a CLI package in my node application. I need the CLI to spin up a new project (this entails creating a folder for the project). After the project folder is created, I need to create some files in the folder (using fs writeFile). The problem is right now, my writeFile function executes BEFORE the folder is created by the CLI package (This is detected by my console.log. This brings me to main main question.

Can I add an async callback function to the CLI.new without modifying the package I included?

FoundationCLI.new(null, { framework: 'sites', // 'apps' or 'emails' also template: 'basic', // 'advanced' also name: projectName, directory: $scope.settings.path.join("") }); try{ if (!fs.existsSync(path)){ console.log("DIRECTORY NOT THERE!!!!!"); } fs.writeFileSync(correctedPath, JSON.stringify(project) , 'utf-8'); } catch(err) { throw err; }

It uses foundation-cli. The new command executes the following async series. I'd love to add a callback to the package - still not quite sure how.

async.series(tasks, finish);

Anyone interested in this can probably get mileage out of:

Creating Callbacks for required modules in node.js

--------------Solutions-------------

The code for the new command seem to be available on https://github.com/zurb/foundation-cli/blob/master/lib/commands/new.js

this code was not written to allow programmatic usage of the new command (it uses console.log everywhere) and does not call any callback when the work is finished.

so no there is no way to use this package to do what you are looking for. Either patch the package or find another way to do what you want to achieve.

Category:node.js Time:2018-11-07 Views:0
Tags: node.js

Related post

  • How to add a parameter to a formatted string function call via a #define function 2010-09-08

    I want to create macros that will insert a parameter into a function call. For example, I have function Action() declared below. Action takes as it's inputs an enum for the state number and a formatted string with optional args for the string. I want

  • How to add before_validation callback to single object, not whole class in ActiveRecord 3? 2010-11-24

    How to add before_validation callback to single object, not whole class in ActiveRecord 3? In AR 2 I did like this: module ObjExtend def before_validation p 'before_validation' return super end end obj.extend ObjExtend but it does not work anymore --

  • How to add to $.get in JQuery error handling function? 2011-09-20

    How to add to $.get in JQuery error handling function ? My request looks like $.get('www.test.com', temp_parameters, function(data) { alert('data='+data['result']); },"json"); but there is no function if error happens. Where to add that function ? --

  • How is the limit defined on the number of function calls in the stack in Java? 2011-08-10

    I've been looking recently on a deep stack with 2000 recursive function calls, and was wondering how is the limit defined on the number of function calls in the stack in Java? --------------Solutions------------- The limit is based on the maximum amo

  • How to add/design callback function 2010-04-27

    How do I setup/register a callback function, in C++, to call a function when there is data to be read from a queue? Edit 1: Using Neil's answer for a complete answer (in header file): #include <vector.h> class QueueListener { public: virtual vo

  • Help! How to add Child to specify Node using PHP simpleXML? 2010-11-19

    my xml structure is: <users> <user id="126"> <name>老黄牛三</name> <watchHistory> <whMonthRecords month="2010-10"> <whDateList month="2010-10"> <date>01</date> <date>02</date> <date>

  • How to add 2 callback to the Jshelper in Cakephp 2.x 2013-04-23

    I want to add 2 callback to Js->submit, My first return true or false. Continuing with that I want to put action. I mean If it is true then it continue to action else halt at that moment. What I have tried yet but its not taking 2 callback. Plaese

  • How to add editable first child node in winforms 2012-01-05

    I have a treeview which represents filesystem, I have a New folder button, It works fine if the selected node has some child nodes, however when selected node does not have any child nodes it is not able to add a editable child node. I am using the f

  • How to add a callback for setAttribute? 2012-04-05

    Is it possible to add a callback on setAttribute on Prototype ? For this example, I would like to show an alert("done !") when setAttribute() is finished. img.setAttribute("src", "http://blabla.com/c.jpg"); --------------Solutions------------- You co

  • CKEditor, how to add a custom button to the toolbar that calls a JavaScript Function 2009-12-24

    I'd like to add a button to the toolbar that calls a JavaScript function like Tada()? Any ideas on how to add this? --------------Solutions------------- I am in the process of developing a number of custom Plugins for CKEditor and here's my survival

  • How do I test 'normal' (non-Node specific) JavaScript functions with Mocha? 2012-04-18

    This seems like it should be extremely simple; however, after two hours of reading and trial-and-error without success, I'm admitting defeat and asking you guys! I'm trying to use Mocha with Should.js to test some JavaScript functions, but I'm runnin

  • How to add code at the entry of every function? 2011-02-22

    I want to add some code before every function call to do some checking. The only way I know is: #define SOME_CODE printf("doing something..."); class testObject { void function1() { SOME_CODE ... } void function2() { SOME_CODE ... } } Is there a clea

  • How to create a universal jquery validate and reset function call 2010-11-30

    I am using the jquery validate plugin to create a validation method for all forms in an application. Using the jquery each() function to cycle each form and applyt the method. I want to achieve the reset using the same each method. how can i accompli

  • How to check whether an argument is supplied in function call? 2011-12-21

    Say that I have a function, dummy, with 2 arguments. The arguments can have default values when not supplied in function call. But how do I know is an arguments is not supplied? I know I can use nargin, like this function dummy(arg1, arg2) if nargin

  • How to get a returned value of an insert function called by asp:ObjectDataSource 2011-08-03

    I'm using an asp:ObjectDatasource to handle an insert (done through Linq to SQL) to my SQL database. The insert function returns an integer. My problem is that how could I get the returned value of the function. Should I manually call the insert func

  • How to declare an object as invalid after a function call in C++11? 2011-12-14

    Is there anyway in C++11 to have an input argument to a function be declared as invalid after the function returns? For a simple example, consider that I have a rectangle object with a coordinate for the lower left corner and a coordinate for the upp

  • How to add custom 'project item nodes' to Visual Studio Flavoured Project 2009-06-20

    I have written a simple flavoured project for Visual Studio 2008, and I want to add a custom 'folder' item to the solution explorer, similar to the 'references' folder. This folder will contain more 'custom' nodes, which dont actually represent files

  • How to add attribute to Nokogiri node? 2010-09-01

    I'm trying to add an attribute to an existing Nokogiri node. What I've done is this: node.attributes['foobar'] = Nokogiri::XML::Attr.new('foo', 'bar') But I get the error: TypeError Exception: wrong argument type String (expected Data) What is a Data

  • Drupal 7: how to add template file to /node/add/content-type 2011-01-10

    In Drupal 7. I want to themming /node/add/content-type by template file as page--node--add--content-type.tpl.php. Please help me. --------------Solutions------------- You need to use page--node--add--content_type.tpl.php instead of page--node--add--c

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 3.082 (s). 13 q(s)