Im trying to bundle my app so that I can push it to the test server using Gulp. This is my gulp file. It is not done yet, (Build is supposed to also run vendor-js) but I get an error when it runs bundle:app. This is my gulp file:
var gulp = require('gulp'),
tsc = require('gulp-typescript'),
Builder = require('systemjs-builder'),
tslint = require('gulp-tslint'),
sourcemaps = require('gulp-sourcemaps'),
tscConfig = require('./tsconfig.json');
gulp.task('lint', function () {
return gulp.src('app/**/*.ts')
.pipe(tslint({ formatter: 'prose' }))
.pipe(tslint.report());});
gulp.task('compile', ['lint'], function () {
return gulp.src('app/**/*.ts')
.pipe(sourcemaps.init())
.pipe(tsc(tscConfig.compilerOptions))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/js'));});
var vendorJS = [
'node_modules/core-js/client/shim.min.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs.config.js'];
var concat = require('gulp-concat');
gulp.task('vendor-js', function () {
return gulp.src(vendorJS)
.pipe(concat('vendor.js'))
.pipe(gulp.dest('dist/js'));});
var systemjsBuilder = require('gulp-systemjs-builder');
gulp.task('bundle:app', function () {
var builder = systemjsBuilder();
builder.loadConfigSync('./systemjs.config.js');
builder.buildStatic('dist/js/main.js', 'app.min.js', {})
.pipe(gulp.dest('dist/js'));});
gulp.task('build', ['compile', 'bundle:app']);
The error I am getting is :
Unhandled rejection Error on fetch for dist/js/app.module at
file:///C:/path/dist/js/app.module Loading dist/js/main.js Error:
ENOENT: no such file or directory, open
'C:\Dev\path\dist\js\app.module' at Error (native)
Do you guys have any suggestions on how to make this work and compress the whole thing to something like "app.min.js" anyone?
Related
Can someone tell me what I'm doing wrong in my gulp.js file to allow for the user to hit save and it update my .css file from the .sass file change?
If I manually hit Run under my Task it will work
Can anyone see any issues?
/// <binding AfterBuild='compile' ProjectOpened='default' />
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
// Requires the gulp-sass plugin
var sass = require('gulp-sass');
gulp.task("sass", function (done) {
return gulp.src('Content/styles/**/*.scss', '!Content/styles/vendor')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('Content/styles/'));
});
function watch() {
gulp.watch('Content/styles/**/*.scss', gulp.series("sass"));
}
gulp.task("compile", gulp.series("sass"));
gulp.task('default', watch);
I created a yeoman generator with user interaction, that can be called in the terminal like (after running npm link):
yo mygenerator --name test --path /test/path --project testproject
Now I want to include this generator in my vscode extension.
How can I call the yo generator from my typescript code when the generator when the generator is added as a package.json dependency?
So something like (pseudo code)
import { yo } from 'yeoman';
import mygenerator; // added as a dependency via package.json
const options = {
name: 'test',
path: '/test/path',
project: 'testproject',
};
yo.exec(mygenerator, options, () => {
console.log('yeoman finished')
});
Is something like this possible?
Here is a solution for that:
const env = yeoman.createEnv();
const generatorPath = '../node_modules/generator-name/generators/app/index.js';
env.getByPath(generatorDir);
env.on('error', (err: any) => {
// handle error
});
const options = {
env,
'option1': option1,
'option2': option2,
};
try {
await env.run('name', options);
} catch (err) {
// handle error
}
I can't get the cordova media plugin to work, I get error code 1 which signals that the file is not getting loaded. I've tried a number of variations, but can't figure out which path is correct.
Currently my code looks like this:
function onDeviceMediaReady () {
var path = window.cordova.file.applicationDirectory + 'why.mp3';
console.log(path);
narrative = new Media(path, // success callback
function() {
console.log("playAudio():Audio Success");
},
// error callback
function(err) {
console.log("playAudio():Audio Error: "+ err.code);
});
}
this gives me a path that's file://var/cotainers/Bundle/Application/[GUID]/Cordova400.app/why.mp3
I don't get why I can't find it. the file is in the telerik appbuilder root directory.
Inside your 'WWW' folder place the file inside 'sound' folder & try following
var srcBookmark = "sound/yes.mp3"; //ios
var iOSPlayOptions = {
numberOfLoops: 1,
playAudioWhenScreenIsLocked : false
}
var media = $cordovaMedia.newMedia(srcBookmark);
//media.play(); //android
media.play(iOSPlayOptions); //ios
$timeout(function(){
media.stop();
media.release()
}, 500);
If you're using appBuilder to test your app te aplication folder is the telerik folder, you must deploy your app as APK and test the folder
Gulp plugin gulp-ruby-sass(https://github.com/sindresorhus/gulp-ruby-sass) giving not compiling, the error message in terminal coming like this 👇
Error: must provide pattern
Here is the gulpfile.js details
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
sass = require('gulp-ruby-sass');
gulp.task('styles', function (argument) {
gulp.src('sass/app.scss')
.pipe(sass())
.pipe(gulp.dest('css/'));
});
The gulp-ruby-sass syntax has been changed:
instead of: it is now:
gulp.task('styles', function (){ gulp.task('styles', function (){
gulp.src('sass/app.scss') return
.pipe(sass()) sass('sass/app.scss')
.pipe(gulp.dest('css/') .pipe(gulp.dest('css/')
; ;
}); });
Please check it out and mark your problem as solved.
The official gulp-ruby-sass documentation says it should be done like this:
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
gulp.task('sass', function () {
return sass('source/file.scss')
.on('error', sass.logError)
.pipe(gulp.dest('result'));
});
Install libsass because it runs much faster than ruby sass ,
it works with node
npm install gulp-sass --save-dev`
Install gulp load plugins because it does so much and loads
plugins from your json and you dont need to declare in your gulpfile
(carefull how many you use because if you load too many it hinders
performance)
npm install --save-dev gulp-load-plugins
var gulp = require('gulp'),
$ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/,
lazy: true,
camelize: true
});
gulp.task('libsass', function () {
gulp.src('sass/app.scss')
.pipe($.sass({errLogToConsole: true}))
.pipe($.autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe($.sourcemaps.write('app/css/map'))
.pipe(gulp.dest('app/css'))
});
Lets say I have a project that uses bower, grunt, bowerify(with shim) and since I love Jest so much I want to test with that. How in the world do I get jest to see my browserify shim modules when it runs tests. I use grunt, to kick off the npm test command.
Here is my package.json file.
"browser": {
"jquery": "./bower_components/jquery/dist/jquery.js",
"foundation": "./bower_components/foundation/js/foundation/foundation.js",
"fastclick": "./bower_components/fastclick/lib/fastclick.js",
"greensock-tm": "./bower_components/gsap/src/uncompressed/TweenMax.js",
"greensock-css": "./bower_components/gsap/src/uncompressed/plugins/CSSPlugin.js",
"greensock-time": "./bower_components/gsap/src/uncompressed/TimelineMax.js",
"scrollmagic": "./bower_components/ScrollMagic/js/jquery.scrollmagic.js",
"handlebars": "./bower_components/handlebars/handlebars.runtime.js"
},
"browserify-shim": {
"jquery": "$",
"greensock-css": "CSSPlugin",
"fastclick": "FastClick",
"greensock-tm": "TweenMax",
"greensock-time": "TimelineMax",
"scrollmagic": "ScrollMagic",
"foundation": "foundation",
"handlebars": "Handlebars"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
Right now I almost have this worked out by doing this in my grunt file before I run the test.
grunt.registerTask("shimBowerForTests",function(){
var readJson = require('read-package-json');
var fs = require('fs');
var remapify = require('remapify');
readJson('./package.json', console.error, false, function (er, data) {
if (er) {
throw "There was an error reading the file";
}
var packages = data.browser;
var browserify = require('browserify');
for (var key in packages){
var b = browserify();
var wstream = fs.createWriteStream("devjs/test/modules/"+key+'.js');
b.add(packages[key]);
b.bundle().pipe(wstream);
}
});
});
and.
exec: {
jestTest: {
command: 'cp -r devjs/modules devjs/test/modules && npm test'
}
}
The problem is that using browserify so combine everything for the browser works great with my setup and I can require my shimmed modules like this.
require('jquery') //example but in the jest cli the test fail because they can find the module unless I somehow prefix it with ./, like so require('./jquery')
I'm guessing that the problem is that you've only installed your shimmed modules with bower. If you want them to work in node/jest, you'll have to install them with npm as well. Then just make sure Jest isn't mocking anything in the node_modules directory, and it should find all the required modules in there as long as the names match up.
Your Jest config in package.json should look like:
"jest": {
"unmockedModulePathPatterns": [
"./node_modules"
]
}
And then just download all the dependencies.
npm install jquery --save-dev
UPDATE
Instead of using my below solution you should opt for using Karma,karma browserify. I have converted the below solution into using karma and it is working much much better.
----------------------OLD ANSWER
What I actually did to solve this was, used the Jest source preprocessor to rewrite the require statement to look for a module in a certain directory in my /tests/ folder that I have created using grunt. The Folder contains the files listed in my browserify-shim, browser section of the package.json file.
EDIT: Here is how I shim bower, I made this script in the Gruntfile.js that puts all the bower modules and any commonjs modules that I need into an accessible directory.
grunt.registerTask("shimBowerForTests", function() {
var readJson = require('read-package-json');
var fs = require('fs');
readJson('./package.json', console.error, false, function(er, data) {
if (er) {
throw "There was an error reading the file";
}
var packages = data.browser;
var shim = data['browserify-shim'];
var browserify = require('browserify');
var exclude = ["jquery.maskedinput", "jquery"];
for (var key in packages) {
var b = browserify();
var wstream = fs.createWriteStream("devjs/test/modules/" + key + '.js');
if (shim[key] !== undefined && exclude.indexOf(key) === -1) {
b.add(packages[key]);
b.bundle().pipe(wstream);
} else {
var rstream = fs.createReadStream(packages[key]);
rstream.pipe(wstream);
}
}
});
});
Then in the Jest pre processor file I do this.
module.exports = {
process: function(src, path) {
var src2= src.replace(/require\([\"\']([^\.\'\"]+)[\"\']\)/g, "require(\'../modules/$1\')");
src2= src2.replace(/jest\.dontMock\([\"\']([^\.\'\"]+)[\"\']\)/g, "jest.dontMock(\'../modules/$1\')");
return src2;
}
};