Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Save plugin to dest directory
const destination = join(__dirname, 'dist', 'plugin.js');
// Babel traspile
if (prog.transpile) {
c.info('Transpiling with babel');
let res = await babel.transformAsync(output, {
presets: ['@babel/preset-env'],
}); // => Promise<{ code, map, ast }>
output = res.code;
}
await fs.outputFile(destination, output);
c.success(
`Your plugin ${gray(name)} has been compiled to ${gray(destination)}`
);
}
const today = () => new Date().setHours(0, 0, 0, 0);
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
const prettifyErrors = err => {
if (!(err instanceof Error)) return err;
if (!logger.dumpStacks) return err.message + stackSuppressed;
const stack = err.stack.slice(err.stack.indexOf('\n'));
const color = colorette[logger.dumpStacks] || colorette.gray;
return err.message + color(stack);
};
const bell = '\x07';
const initTime = today();
const stackSuppressed = colorette.gray('\nStack trace was suppressed. Run with `LOGGY_STACKS=1` to see the trace.');
const logger = {
// Enables or disables system notifications for errors.
notifications: {
app: 'Loggy',
icon: `${__dirname}/logo.png`,
levels: ['error'],
notify,
},
// Colors that will be used for various log levels.
colors: {
error: 'red',
warn: 'yellow',
log: 'cyan',
info: 'green',
'Your repository (and also your published npm package) ' +
'must be named "windy-plugin-AnyOfYourName".' +
' Change the name in your package.json'
);
// Tasks
if (prog.watch || prog.build) {
await build();
}
if (prog.serve) {
await startServer();
}
if (prog.watch) {
c.start(`Staring watch on ${gray(srcDir)} and ${gray('package.json')}...`);
chokidar.watch([srcDir, 'package.json']).on('change', onChange);
}
} catch (e) {
c.error(`Error\u0007`, e);
}
})();
function handleDiff (file, original, formatted) {
var diff
var color = require('colorette')
if (original === formatted) {
diff = 'There is no difference with the original file.'
}
if (color.enabled) {
file = color.blue(file)
if(diff) {
diff = color.gray(diff)
} else {
var JsDiff = require('diff')
diff = JsDiff.createPatch(file, original, formatted)
diff = diff.split('\n').splice(4).map(function (line) {
if (line[0] === '+') {
line = color.green(line)
} else if (line[0] === '-') {
line = color.red(line)
} else if (line.match(/^@@\s+.+?\s+@@/) || '\\ No newline at end of file' === line) {
line = ''
}
return color.gray(line)
})
diff = diff.join('\n').trim()
}
} else if (!diff) {
const onChange = async fullPath => {
c.info(`watch: File changed ${gray(fullPath)}`);
reloadConfig();
await build();
};
return filename + table(messages.map(function (msg) {
var last = msg.text.lastIndexOf('(');
var warning = msg.text.slice(0, last).trim();
var position = msg.text.slice(last, msg.text.length);
return [
'',
gray('line ' + msg.node.source.start.line),
gray('col ' + msg.node.source.start.column),
warning,
gray(position)
];
})) + collisions(messages);
};
options.forEach(a => {
const def = a.hasDefault() ? 'default: ' + JSON.stringify(a.default()) : '';
const req = a.isRequired() ? c.bold('required') : c.gray('optional');
optionsTable.push([a.synopsis(), a.description(), req, c.gray(def)])
});
help += optionsTable.toString();