demos/ago-node-cli/lib/item-export-command.js
function (id, fileName) {
    console.info(`Exporting item ${id} to file ${fileName}`);
    // construct the search call..
    let model = {};
    return getItem(id)
    .then((item) => {
      model.item = item;
      if (this.shouldFetchData(item.type)){
        console.info(`...Fetching ./data for item of type ${item.type}`);
        return getItemData(id);
      } else {
        console.info(`...Items of type ${item.type} do not have json ./data - skipping`);
        return Promise.resolve();
      }
    })
    .then((maybeData) => {
      if (maybeData) {
        model.data = maybeData;
      }
      // now write out the file...
      jsonfile.writeFileSync(fileName, model,  {spaces: 2});
      console.info(`Done. Exported "${model.item.title}" to ${fileName}`);
    })
    .catch((err) => {
      console.error(err);
    });
  }
function (id, fileName) {
    console.info(`Exporting item ${id} to file ${fileName}`);
    // construct the search call..
    let model = {};
    return getItem(id)
    .then((item) => {
      model.item = item;
      if (this.shouldFetchData(item.type)){
        console.info(`...Fetching ./data for item of type ${item.type}`);
        return getItemData(id);
      } else {
        console.info(`...Items of type ${item.type} do not have json ./data - skipping`);
        return Promise.resolve();
      }
    })
    .then((maybeData) => {
      if (maybeData) {
        model.data = maybeData;
      }
      // now write out the file...
      jsonfile.writeFileSync(fileName, model,  {spaces: 2});
      console.info(`Done. Exported "${model.item.title}" to ${fileName}`);
    })
    .catch((err) => {
      console.error(err);
    });
  }
Execute the command