Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run in node.js #3

Open
g-rodigy opened this issue Mar 28, 2021 · 5 comments
Open

Run in node.js #3

g-rodigy opened this issue Mar 28, 2021 · 5 comments

Comments

@g-rodigy
Copy link

g-rodigy commented Mar 28, 2021

I try run glyphhanger in node like this

const cp = require('child_process')

cp.exec('glyphhanger --version')
cp.exec('glyphhanger --subset="*.ttf"')

It's not working and process never ends. Empirically, I found a place where this happens - here. We waiting for input but it doesn't happen. Can you help me?

@Paul-Hebert
Copy link

@g-rodigy not sure if you're still running into this or not.

I ran into a similar issue but was able to get it working using the spawn method:

const cp = require('child_process');

const glyphhangerProcess = cp.spawn(
  'glyphhanger',
  [
    // Pass in flags here
    '--subset="*.tff"',
  ],
  { stdio: 'inherit' }
);

glyphhangerProcess.on('close', () => {
  console.log('glyphhanger completed');
});

@SamuelMiller
Copy link

SamuelMiller commented May 31, 2022

Any suggestions on how I could create a glyphhanger gulp task/function in gulpfile.js, perhaps using the above code? Thanks.

@Paul-Hebert
Copy link

@SamuelMiller , it's been a little while since I wrote a gulp task, but I think the majority of the code above could be repurposed for that. I think the main relevant change would be to call the cb() function from the gulp task when the task completes. Maybe something like this?

const cp = require('child_process');

function runGlyphhanger(cb) {
  const glyphhangerProcess = cp.spawn(
    'glyphhanger',
    [
      // Pass in flags here
      '--subset="*.tff"',
    ],
    { stdio: 'inherit' }
  );
  
  glyphhangerProcess.on('close', () => {
    console.log('glyphhanger completed');
    // Run `cb` to complete the Gulp task
    cb();
  });
}

// This assumes this is the only task in this file and you want to export it for
// use in other Gulp files.
// If that's not true you could change this to a call to `series` or 
// `parallel` to run this task and other tasks
// @see https://gulpjs.com/docs/en/getting-started/creating-tasks/
exports.default = runGlyphhanger;

I haven't tested this code but it seems like it should work. If you try it and get an error let me know and I may be able to help (though I'll be out of the office for the rest of the week after today)

@SamuelMiller
Copy link

Thanks for responding. When I return to the part of my current web project that will be using glyphhanger to optimize my fonts, I'll test out the code and get back to you.

@ShahriarKh
Copy link

Try execSync:

// example:
const result = execSync('npx glyphhanger http://localhost:3001').toString();
console.log(result)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants