You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

36 lines
982 B

'use strict';
const yeoman = require('yeoman-environment');
const npm = require('npm');
const path = require('path');
const temp = require('../../src/temp');
const env = yeoman.createEnv();
module.exports = (args, done) => {
// For initializing a project, the preset is not installed in the project.
// Rather, we install it ourselves into a temp directory and invoke from there.
const tempDir = temp();
const packageName = args.packageName;
npm.load({ loglevel: 'silent' }, (err, npm) => {
if (err) {
console.error(err);
return done(1);
}
const pkg = path.join(tempDir, 'node_modules', packageName.startsWith('@') || !packageName.includes(path.sep) ?
packageName :
path.basename(packageName));
npm.commands.install(tempDir, [packageName], (err) => {
if (err) {
console.error(err);
return done(1);
}
env.register(pkg, 'neutrino:init');
env.run('neutrino:init', done);
});
});
};