How to deploy client side dependencies on webserver? - javascript

I have done some web developing using Python and Django. I use virtualenv to make a bootstrap script that can install all my Python dependencies on a server. I have a repository for the code I have written myself, and in that repository are two file (beside my code): requirements.txt and bootstrap.py. Using the bootstrap script, it installs all the dependencies on the server.
Now I would like something similar for the client side dependencies. E.g. jQuery, jQuery-ui and bootstrap. Currently I manually download the files and put them in the static folder on the server.
I have run into Bower, and I understand that it can indeed download various js-libraries. But I don't see how to use it in an elegant way. E.g. for jQuery it downloads the entire jQuery repository, which means both a dist folder and a src folder, containing tons of files. All I need is the jQuery.min.js.
Well, wide question, what is the neat way of automating the deployment of client side dependencies?

you can use composer
{
"require": {
"jquery/jquery": "*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "jquery/jquery",
"version": "1.8.2",
"dist": {
"url": "http://code.jquery.com/jquery-1.8.2.min.js",
"type": "file"
}
}
}
]
}

Related

How to include two C++ libraries - Boost and Quantlib - in node gyp?

I am new to working with node-gyp in making C++ Addons for JavaScript on Windows and have been struggling for a while with including Quantlib in my binding.gyp file. I was able to generate the .lib file from Quantlib's official site (https://www.quantlib.org/install/vc10.shtml); however, the guide did not mention anything about generating a .dll file, and I am not sure if a .dll file is needed to include Quantlib. Although I cannot include the Quantlib library, I have been successful in linking another C++ library in my binding.gyp file. Any help would be much appreciated!
My binding.gyp file:
{
"targets": [
{
"target_name": "hello",
"sources": [ "src/hello.cc", "src/test.cpp", "src/test.h"],
"include_dirs": ["<!(node -e \"require('nan')\")", "eigen-3.3.7/eigen-3.3.7", "ql/math", "ql", "Quantlib"],
"libraries": ["<(module_root_dir)/Quantlib/QuantLib-mt.lib"]
}
]
}
NOTE: eigen-3.3.7 is the C++ library I was able to include in my binding.gyp file. I created a directory in my root folder for quantlib's .lib file called "Quantlib".

Javascript dependency in PHP library

I have a PHP library that depends on a Javascript repo (also my lib). In the PHP lib, I don't want a CDN url or a minified copy. The PHP lib uses a framework (also home-brewed) that will compile the JS files together along with all the resources on my site.
I don't want to change anything about the JS lib, aka I don't want to make a composer.json file. I'm aware git submodule exists, though I'm not sure how to use it and I've read that it's a thoroughly bad way to handle dependencies, and I'm guessing my submodules wouldn't get included through composer?
Are there any other ways to include a JS dependency in a PHP library? (aside from copy+pasting the files) (and/or tips to make submodule a good option)
Composer defaults to using the metadata from Packagist, which Packagist pulls from each repo's composer.json file.
However, it is possible to just specify any file that you want to download yourself. It might be a bit cumbersome if you want to have a lot of versions though.
Composer has some documentation about it here but I tried it out myself and will include my sample composer file below. I was able to use composer update to download a git repo which didn't contain a composer.json file.
Sample Composer file for the PHP project:
It looks like you'll need a "package" section for each version you want.
{
"repositories": [
{
"type": "package",
"package": {
"name": "testy/testyson",
"version": "1.0.0",
"dist": {
"url": "https://github.com/mickadoo/testlib/archive/1.0.0.zip",
"type": "zip"
}
}
},
{
"type": "package",
"package": {
"name": "testy/testyson",
"version": "2.0.0",
"dist": {
"url": "https://github.com/mickadoo/testlib/archive/2.0.0.zip",
"type": "zip"
}
}
}
],
"require": {
"testy/testyson": "2.*"
}
}
The test repository I loaded just contains a text file with the contents "This is version 1" and using the different version in the require section of the PHP package I was able to switch between them.

How to create an express api executable

I have created a fully functioning fairly basic javaScript Node.js Express API application that I want to run as an executable in a windows environment. I am wanting to do this so I can give clients the ability to run my API on premise without exposing my source code to them.
Currently I have been using the pkg npm package which allows me to package my node.js application into an executable that will contain everything needed to run the app including node and my bundled source code.
My executable runs but my POST route is breaking with the following error:
"name": "RequestError",
"message": "Error: form-data: File or directory 'C:\\**\\myapp-api\\uploads\\1553103249524_test.wav' was not included into executable at compilation stage. Please recompile adding it as asset or script.",
"cause": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\test.wav",
"pkg": true
},
"error": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\1553103249524_test.wav",
"pkg": true
},
My POST allows clients to upload a file in a multipart form using multer.js to another external API that will return some metadata. pkg.js doesn't appear to have the means to discover files that are included after the bundling of the executable.
Is there anything I can do in my configuration for my uploaded files to be included? Is there some other utility or process that others use for creating an executable of their node.js express APIs that would better handle the issue I am having?
Any guidance would really be great.
Try adding your files under "assets" in the package.json file.
The config paragraph on the pkg website https://www.npmjs.com/package/pkg#config states:
So you must specify the files - scripts and assets - manually in pkg property of your package.json file.
"pkg": {
"scripts": "build/**/*.js",
"assets": "views/**/*"
}
You may also specify arrays of globs:
"assets": [ "assets/**/*", "images/**/*" ]
Just be sure to call pkg package.json or pkg . to make use of scripts and assets entries.
You are probably using something like this in your script (I am guessing since you didnt provide this part of the code)
app.use(express.static(__dirname+'/uploads'));
res.sendFile(path.join(__dirname+'/uploads'));
__dirname will be wrong when you pack your .exe get rid of it everywhere and replace it with ./
app.use(express.static('./uploads'));
res.sendFile(path.join('./uploads'));
Something like that. It worked for me.
Good luck!

Should vendor assets be included in version control with bower + rails?

I've started to use bower-rails to manage css/js assets in my rails projects.
By default the dependences are being installed in vendor/assets/bower_components.
The problem is that bower copies the whole packages, including sources, examples, licenses, etc.
I don't have problem to get rid of all those files, but I'm wondering if is necessary to include even the important files, as I think it should be the programmer's responsibility to load those dependences in the computer where is loading the project(maybe with grunt?), besides is supposed you should not touch the vendor packages as they are not your responsibility(regarding all those crappy files I want to delete).
My point is: Is there any kind of "best practice" related with bower packages and version control?
I recently used bower-rails for the first time and had Git ignore the vendor/assets/bower_components directory to good effect.
If you choose to have Git ignore bower_assets, you SHOULD specify a known good version of each library in bower.json instead of using latest to avoid version conflicts.
I'm using bower and bower-installer in my Rails 4.2.x app, without using any gems for javascript dependencies. I'm still using the asset pipeline.
I added vendor/assets/bower_components to my .gitignore file. I use bower-installer to copy just what I need to vendor/assets/{javascripts,stylesheets}, which are in source control.
I think that this gives me the best of both worlds: version control of JS libraries so updates are relatively easy, but no chance of a production deploy failing because someone removed 'leftpad' from the node repo.
Here's a trimmed-down version of my bower.json file (in source control). Note that jquery-form is not in the bower repo, so I included the path to the download file.
{
"name": "icots",
"main": "",
"private": true,
"ignore": [
"**/.*",
"bower_components",
"vendor/assets/bower_components",
"lib"
],
"dependencies": {
"jquery": "^3.1.1",
"jquery-ui": "^1.12.1",
"jquery.form": "http://malsup.github.io/min/jquery.form.min.js"
},
"install": {
"path": {
"js": "vendor/assets/javascripts",
"css": "vendor/assets/stylesheets",
"/[sc|le]ss$/": "vendor/assets/stylesheets"
},
"sources": {
"jquery": "vendor/assets/bower_components/jquery/dist/jquery.min.js",
"jquery-ui": "vendor/assets/bower_components/jquery-ui/jquery-ui.min.js",
"jquery-form": "vendor/assets/bower_components/jquery.form/index.js"
}
}
}

Instruct Sencha SDK tools to bundle other js files specified in app.json

My app.json file of a Sencha touch 2 application contain.
"js": [
{
"path": "sdk/sencha-touch.js"
},
{"path": "js/mootools-1.2.5-core.js"}, // I want these files to be bundled too
{"path": "js/mootools-1.2.5.1-more.js"}, // <----------+
{"path": "js/soundmanager2-nodebug-jsmin.js"}, // <----+
... // <----+ and there are more.
...
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
},
Now I see when I invoke sencha app build production It compiles all the sencha classes into a giant app.js file. But all my other classes are just compressed to build directory. They are not concatenated. how can I include them in app.js?
F.A.Q.
Your json file is properly written, right?
A. Yes, app.json is written without any syntax error. The project builds successfully on invoking sencha app build production
After looking at the source code and talking with the devs behind Cmd, it appears that it is currently not possible.
However, because the build file is written in JavaScript, in theory, it wouldn't take much to modify it and add this functionality into Cmd.
You can find the Sencha Touch build file in:
CMD-ROOT/plugins/touch/current/app-build.js
Where CMD-ROOT is the location of the sencha command - which you can find out by using which sencha.
On my system (OSX), the path is:
/Users/Robert/bin/Sencha/Cmd/3.0.0.250/plugins/touch/current/app-build.js
Hopefully this is of some help to you.
Update
It appears that, after talking to another Cmd developer, this actually is possible. There are 2 steps you need to take to make it happen:
1) Add the skipFrameworkFile property into each JS resource you want to bundle. This tells the compiler to not copy the resource when your build your app.
{
"path": "resources/js/jquery.js",
"skipFrameworkFile": true
},
"path": "resources/js/jquery2.js",
"skipFrameworkFile": true
}
2) Require each of the files in your app.js file using the #require tag. This tells the compiler to include each of your files into your app.js file.
//#require resources/js/jquery.js
//#require resources/js/jquery2.js
For SenchaCmd 3.2, rdougan's solution didn't work for me. However, instead of using:
'skipFrameworkFile: true
I used
'x-bootstrap': true
(by looking at SenchaCmd source code) and it worked!
The other steps are the same as rdougan's
Hope this helps. Cheers

Categories

Resources