Urara-Blog/node_modules/.pnpm-store/v3/files/31/86d8e898b5f7ef335f0c07c6086fceaf4c6c926ad2c2a44c7da3f005d3efcd2b2fc2b10e189034390528cdb3a3f2627b319bdbded9f0ea7d150db6299321dd-exec
2022-08-14 01:14:53 +08:00

74 lines
1.8 KiB
JavaScript
Executable file

#!/usr/bin/env node
var path = require( 'path' );
var minimist = require( 'minimist' );
var sander = require( 'sander' );
var showHelp = require( './showHelp' );
var command;
var sorcery = require( '../' );
var validExtensions = { js: true };
command = minimist( process.argv.slice( 2 ), {
alias: {
i: 'input',
o: 'output',
v: 'version',
h: 'help',
d: 'datauri',
x: 'excludeContent'
}
});
if ( command.help ) {
showHelp( process.stdout );
}
else if ( process.argv.length <= 2 && process.stdin.isTTY ) {
showHelp( process.stderr );
}
else if ( command.version ) {
console.log( 'Sorcery version ' + require( '../package.json' ).version );
}
else if ( !command.input ) {
console.error( 'Error: You must supply an --input (-i) argument. Type sorcery --help for more info' );
}
else {
sander.stat( command.input ).then( function ( stats ) {
if ( stats.isDirectory() ) {
return sander.lsr( command.input ).then( function ( files ) {
files = files.filter( function ( file ) {
return validExtensions[ path.extname( file ).slice( 1 ) ];
});
return files.reduce( function ( promise, file ) {
return promise.then( function () {
var input = path.join( command.input, file );
var output = path.join( command.output || command.input, file );
return sorcery.load( input ).then( function ( chain ) {
return chain.write( output, {
inline: command.datauri,
includeContent: !command.excludeContent
});
});
});
}, Promise.resolve() );
});
}
return sorcery.load( command.input ).then( function ( chain ) {
return chain.write( command.output || command.input, {
inline: command.datauri,
includeContent: !command.excludeContent
});
});
}).catch( function ( err ) {
setTimeout( function () {
throw err;
});
});
}