Force-latest with Bower programmatic API - javascript

I'm using the Bower programmatic API to install a list of libraries at once, and some of them have dependency version conflicts. I would like to use the 'force-latest' flag to default to the latest version, but I can't figure out how to make it work with the programmatic API.
The bower documentation shows this example:
var bower = require('bower');
bower.commands
.install(['jquery'], { save: true }, { /* custom config */ })
.on('end', function (installed) {
console.log(installed);
});
I hoped I could change {save: true} to {save: true, 'force-latest': true} but it didn't seem to have any effect. I can handle prompts by adding interactive: true to the config and listening for prompt events, but I would like to make it more automated.
Does anyone know how to do this or know where there is more documentation on the programmatic API? Bower just directs you to the source code for more information. I've looked at it a bit, but I'm not really making sense of it. I'll look further if no one else knows.
Thanks!

The bower programmatic API has very little documentation so you are forced to look at their source code to figure out how to interact with it. After some digging, I have found that the 'force-latest' flag is converted to camel case when used. So, your command will need to be something like this:
var bower = require('bower');
bower.commands
.install(['jquery'], { save: true, forceLatest: true }, { /* custom config */ })
.on('end', function (installed) {
console.log(installed);
});
I hope that in the near future, the guys behind bower will offer a little more documentation to this powerful tool.

Related

How to get JQuery Code Completion in Monaco Editor?

I'm new to Monaco and Typescript in general. I'm trying to get JQuery code completion to work on my editor. I've tried just about every example I've been able to find on how to accomplish this. I think I'm pretty close, but probably missing something fundamental.
From the DefinitelyTyped folks, I've gotten their jquery directory and included it in my web project. In the file that is creating my Monaco editor I have the following.
const path = "/jslib/monaco/types/jquery/index.d.ts";
const typings = readTextFile(path);
monaco.languages.typescript.javascriptDefaults.addExtraLib(typings, path);
readTextFile() is just a little function I'm using to get the contents of index.d.ts (which I can confirm is working). Here is the rest of my monaco setup.
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target:
monaco.languages.typescript.ScriptTarget.ES2016,
allowNonTsExtensions: true,
module: monaco.languages.typescript.ModuleKind.System,
noEmit: true,
typeRoots: ["/jslib/monaco/types"],
noLib: true
});
window.editor = monaco.editor.create(document.getElementById('monacodiv'), {
value: $("#formula").val(),
language: 'javascript',
theme: "vs-dark",
autoIndent: true,
dragAndDrop: true,
tabCompletion: true,
fontFamily: "monospace",
scrollBeyondLastLine: false
});
If anyone could let me know what I'm doing wrong, that would be awesome!
So I just ran into this problem, after digging into the DefinitelyTyped definitions, I noticed that index.d.ts is just aggregates the content from four different files (JQueryStatic, JQuery, misc, legacy). Adding the content of all of these files by repeatedly using addExtraLib should work! Otherwise, not sure how monaco could find the contents.

What does api.cache(true) do in Expo's babel.config.js?

This line appears in the default Expo babel.config.js, but I can't find any reference anywhere to what it does. Is there anyone who knows what this does?
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
By default, Babel will evaluate configuration each time it processes a new file. It is possible to optimize the build process performance by caching config function execution result. api.cache(true) does exactly that. When the cache is enabled this way, config function will be called only once.
Here is a link for a more detailed explanation of Babel configuration caching: https://babeljs.io/docs/en/config-files#apicache

How to build sails.js offline documentation?

I want to use offline sails.js documentation in my system.
The documentation of sails.js is maintained at the link Sails.js Documentation.
As they mention there, they use doc-templater to build the documentation. I tried the code below in the node REPL.
require('doc-templater')().build({
remote: 'git#github.com:balderdashy/sails.git',
remoteSubPath: '',
cachePath: '/code/sandbox/doctemplatertest/foo/bar/cache/',
htmlDirPath: '/code/sandbox/doctemplatertest/foo/bar/html',
jsMenuPath: '/code/sandbox/doctemplatertest/foo/bar.jsmenu'
}, function (e,r) {
if (e) {console.log('ERROR:\n',require('util').inspect(e, false, null));}
else console.log('RESULT:\n',require('util').inspect(r, false, null));
});`
But it is not working; I'm getting this result:
RESULT:
[]
undefined
Can anyone please show the way it works.
It looks like they never got that module quite working:
https://github.com/balderdashy/sails-docs/issues/523#issuecomment-136823015
Alternatively you can clone the git repo of the documentation website:
https://github.com/balderdashy/www.sailsjs.org
And run it with sails?

Grunt and hood.ie test database

I'm currently running my test suite on AngularJS using Grunt, Karma, Jasmine and Protractor. The database library I'm using is hood.ie, which is a library on top of CouchDB. I start hood.ie using the following code in my Gruntfile:
hoodie: {
start: {
options: {
callback: function(config) {
grunt.config.set('connect.proxies.0.port', config.stack.couch.port);
}
}
}
},
However, I would like to have a separate database for running tests, which automatically resets afterwards. This way, the production data won't conflict with the tests.
How should I approach this? I would assume there's some kind of standard way of doing this, as I can imagine other people have come across the same problem, but I'm unable to find anything on the internet.
Currently, this seems to be impossible as the hoodie server does not support it. The best way to go about this is to modify it yourself at Hood.ie server Github repository by adding a parameter to define the folder in which the data will be stored, which is at the moment hardcoded to 'data' (https://github.com/hoodiehq/hoodie-server/blob/master/lib/core/environment.js#L48)
Something similar to this should work:
app_path: path.resolve(project_dir, argv.folder || 'data')
As the hoodie task is a 'multitask' you could have a test target in your hood.ie grunt task specific to testing, and then reference this in a grunt command used to run tests e.g:
hoodie: {
start: {
options: {
callback: function(config) {
grunt.config.set('connect.proxies.0.port', config.stack.couch.port);
}
}
},
test: {
options: {
callback: function(config) {
// Make test specific changes here.
}
}
}
}
// The task that runs tests first starting test deps. 'runtests' can be anything you want.
grunt.registerTask('test', 'Run unit tests', ['hoodie:test', 'runtests']);
Note: this will mean any other times you're referencing the hoodie task you'll need to be explicit as otherwise all the specified targets will be run. See this documentation on multitasks for more info. In this example you'd change hoodie to hoodie:start to run the 'start' task as previously defined.

Grunt-Init Conditional Prompts Template

I am getting started with grunt-init templating and trying to write conditional prompts. I've been kicking this around for a few hours, and have had no real success. It probably doesn't help that javascript isn't my strongest language.
I found this answer, but it doesn't really handle what I am trying to do: grunt-init template conditional prompts
I am trying to do something along the lines of the following:
exports.template = function(grunt, init, done) {
init.process({}, [
// Prompt for these values.
{
name: 'css',
message: 'Which CSS Preprocess are you using?',
default: 'SASS/Less/Stylus/none'
}
if (css.value == 'SASS'){
// prompt for Compass / Bourbon / None;
}
], function(err, props) {
...
Obviously this doesn't work, but I have tried going through the grunt-init source and documentation, and haven't found anything helpful.
If this isn't possible, are there other grunt project generators that CAN handle this kind of conditional logic?
For anyone wondering, it appears that to do what I am requesting, you would have to modify the grunt-init source to handle these kind of conditionals. I ended up using the yeoman generator instead.
http://yeoman.io/generators.html

Categories