Recently added a fresh install of meteor alongside apollo and sequelize, created a .sequelizerc file which works as required but whenever I run meteor it fails with: Error: Cannot find module '/lib/database/mysql/models/..config.json'
Application Structure:
/.meteor
/client
/lib
/database
/mysql
/migrations
/models
index.js
/seeders
config.json
/node_modules
/.bin
.sequelizerc
/server
.sequelizerc file
var path = require('path');
module.exports = {
'config': path.resolve('../../lib/database/mysql', 'config.json'),
'migrations-path': path.resolve('../../lib/database/mysql', 'migrations'),
'models-path': path.resolve('../../lib/database/mysql', 'models'),
'seeders-path': path.resolve('../../lib/database/mysql', 'seeders'),
}
/lib/database/models/index.js file
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(module.filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/..\config.json')[env];
var db = {};
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function(file) {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
package.json
{
"name": "meteor-apollo-sequelize",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"apollo-client": "^0.3.12",
"apollo-server": "^0.1.1",
"express": "^4.14.0",
"graphql": "^0.6.2",
"graphql-tools": "^0.6.4",
"meteor-node-stubs": "^0.2.3",
"mysql": "^2.11.1",
"sequelize": "^3.24.0",
"sequelize-cli": "^2.4.0"
}
}
Fix your backslash/forward slash - change this line:
var config = require(__dirname + '/..\config.json')[env];
to
var config = require(__dirname + '/../config.json')[env];
Related
I tried to run the gulp to covert SCSS to CSS,the gulp is working wihout any error but there aren't have any css files output to the target folder, I also tried to change the output path but it still didn't work,and my code is below :
// gulpfile.js
var gulp = require('gulp');
var sass = require('gulp-sass')(require('node-sass'));
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync').create();
var notify = require('gulp-notify');
var sassLint = require('gulp-sass-lint');
var styleLink = {
sassLink: 'src/**/*.(scss|sass)',
OutputLink: '../css'
}
var browserSyncLink = {
root: '../',
watchHtml: '../*.html',
watchJS: '../*.js'
}
// notify
function showErrorNotify(error) {
var args = Array.prototype.slice.call(arguments);
// Show notification
notify.logLevel(0);
notify
.onError({
title: '[' + error.relativePath + '] Error',
message: '<%= error.messageOriginal %>',
sound: 'Pop'
})
.apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
}
// sass task
function sassTask() {
return gulp.src(styleLink.sassLink, { sourcemaps: true })
.pipe(sass()) // compile SCSS to CSS
.pipe(autoprefixer())
.pipe(gulp.dest('./', { sourcemaps: '.' }));
}
function browserSyncServer(cb) {
browserSync.init({
server: {
baseDir: browserSyncLink.root
}
})
cb();
}
function browserSyncLoad(cb) {
browserSync.reload();
cb();
}
function sassLinkTask() {
return gulp
.src(styleLink.sassLink)
.pipe(
plumber({
errorHandler: showErrorNotify
})
)
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
}
function watchTask() {
gulp.watch('../*.html', browserSyncLoad);
gulp.watch(['src/**/*.+(scss|sass)', '../js/*.js'], gulp.series(gulp.parallel(sassTask, sassLinkTask), browserSyncLoad));
}
exports.default = gulp.series(gulp.parallel(sassTask, sassLinkTask), browserSyncServer, watchTask);
when I ran this code i alos didn't get any error.
It seems no error..
Could anyone please help me ? Thanks.
and please excuse my poor English...
In your watchTask you have this:
src/**/*.+(scss|sass) note the + sign before the alternation.
But in your styleLink variable you have:
var styleLink = {
sassLink: 'src/**/*.(scss|sass)',
OutputLink: '../css'
}
Change to sassLink: 'src/**/*.+(scss|sass)',
I'm using Protractor and jasmine-allure-reporter. I'm running protractor from bash script and the problem is with resultsDir, because I want results to generate in a specific folder. Currently they generate in ~/e2e/project_name/conf/allure-results/ folder. What I need is to have them generated in ~/e2e/reports/project_name/allure_results/. Simply entering full path resultsDir: '/home/e2e/reports/project_name/allure-results' in resultsDir parameter changes nothing. How can I solve this?
Current setup in conf.js file:
browser.manage().timeouts().implicitlyWait(15000);
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport: {
resultsDir: 'allure-results'
}
}));
Desired setup in conf.js file:
browser.manage().timeouts().implicitlyWait(15000);
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport: {
resultsDir: '~/e2e/reports/project_name/allure_results/allure-results'
}
}));
I found answer for you:
There is one file named Jasmine2AllureReporter.js under \node_modules\jasmine-allure-reporter\src\jasmine2AllureReporter.js.
Open the file:
Change the following and try:
As i have taken example of D:\\K\\allure-results
Change the same under pluginConfig.resultsDir and var outDir, It will work.
function Jasmine2AllureReporter(userDefinedConfig, allureReporter) {
var Status = {PASSED: 'passed', FAILED: 'failed', BROKEN: 'broken', PENDING: 'pending'};
this.allure = allureReporter || allure;
this.configure = function(userDefinedConfig) {
var pluginConfig = {};
userDefinedConfig = userDefinedConfig || {};
pluginConfig.resultsDir = 'D:\\K\\allure-results';
//pluginConfig.resultsDir = userDefinedConfig.resultsDir || 'allure-results';
pluginConfig.basePath = userDefinedConfig.basePath || '.';
// var outDir = path.resolve(pluginConfig.basePath, pluginConfig.resultsDir);
var outDir = 'D:\\K\\allure-results';
this.allure.setOptions({targetDir: outDir});
};
I'm trying to use gulp-cssbeautify in my projects but I can't make it work .
I have the following dependencies which are working fine except gulp-cssbeautify
" gulp": "^3.9.1",
"gulp-browserify": "^0.5.1",
"gulp-concat": "^2.6.1",
"gulp-connect": "^5.0.0",
"gulp-cssbeautify": "^0.1.3",
"gulp-sass": "^3.0.0",
"gulp-sourcemaps": "^2.4.0",
"gulp-util": "^3.0.8"
This is my gulpfile.js code :
var gulp = require('gulp'),
gutil = require('gulp-util'),
browserify = require('gulp-browserify'),
connect = require('gulp-connect'),
concat = require('gulp-concat'),
sourceMap = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
cssbeautify = require('gulp-cssbeautify');
var env, jsSources, sassSources, htmlSources, sassStyle, outputDir , cssSource;
var env = process.env.NODE_ENV || 'dev';
outputDir = 'dev/';
sassStyle = 'expanded';
jsSources = ['components/scripts/*.js'];
sassSources = ['components/sass/screen.scss'];
htmlSources = [outputDir + '*.html'];
cssSource = ['./' + outputDir + 'css/*.css'];
//gulp.task('js', function() {
// gulp.src(jsSources)
// .pipe(concat('script.js'))
// .pipe(browserify())
// .pipe(gulp.dest(outputDir + 'scripts'))
// .pipe(connect.reload())
//});
gulp.task('sass', function() {
gulp.src(sassSources)
.pipe(sourceMap.init())
.pipe(sass({
compass: true,
css: outputDir + 'css',
sass: 'components/sass',
image: outputDir + 'images',
style: sassStyle
//comments: true,
//require: ['susy', 'modular-scale']
})
.on('error', gutil.log))
.pipe(sourceMap.write('./maps'))
.pipe(gulp.dest(outputDir + 'css'))
.pipe(connect.reload());
});
gulp.task('css', function() {
return gulp.src('.dev/css/*.css')
.pipe(cssbeautify({
indent: ' ',
openbrace: 'end-of-line',
autosemicolon: true
}))
.pipe(gulp.dest('./dev/css/'));
});
gulp.task('watch', function() {
// gulp.watch(jsSources, ['js']);
gulp.watch('components/sass/**/*.scss', ['sass']);
gulp.watch(htmlSources, ['html']);
gulp.watch('.dev/css/*.css', ['css']);
});
gulp.task('connect', function() {
connect.server({
root: outputDir,
livereload: true
});
});
gulp.task('html', function() {
gulp.src(htmlSources)
.pipe(connect.reload())
});
gulp.task('default', ['html', 'sass', 'css', 'connect', 'watch']);
My folder structure for css files is project/dev/css/*.css
Your css task specifies gulp.src('.dev/css/*.css'). Looks like you mean ./dev not .dev.
I recommend reading through your gulpfile and straightenin up your directory names. Sometime you use variables, sometimes you don't. In this example, without changing anything else you could just source gulp.src(cssSource) in your css task
I want to be able to have different subprojects inside my main project. For example:
-- my-project/
- Gruntfile.js
- subproject1/
- index.html
- scss/
- main.scss
- subproject2/
- index.html
- scss/
- main.scss
I want to be able to modify a file in subproject1 without triggering subproject2 tasks.
As of right now I'm configuring my gruntfile like so:
watch: {
subproject1: {
files: ['subproject1/*.html', 'subproject1/scss/**/*.scss'],
tasks: ['sass', 'premailer:subproject1']
},
subproject2: {
files: ['subproject2/*.html', 'subproject2/scss/**/*.scss'],
tasks: ['sass', 'premailer:subproject2']
}
},
premailer: {
subproject1: {
options: {
css: 'subproject1/css/main.css',
verbose: false
},
files: [
{
'subproject1/dist/index.html' : 'subproject1/index.html'
}
]
},
subproject2: {
options: {
css: 'subproject2/css/main.css',
verbose: false
},
files: [
{
'subproject2/dist/index.html' : 'subproject2/index.html'
}
]
},
}
Is there a way to dynamically specify to grunt what task to run depending on file modified (eg, I modify folder/index.html, then run premailer:folder) or is this the only way to achieve it ?
You can check all folders in your main folder inside your Gruntfile, using the grunt.file methods (docs here), create an array of subproject names and then using forEach to create your task dynamically.
Something like this should go:
/*global module:false*/
module.exports = function(grunt) {
var mycwd = "./";
var tempFileList = grunt.file.expand(
{ filter: function (src) {
if (grunt.file.isDir(src) == true) {
return true;
}
return false;
} },
[ mycwd + "!(Gruntfile.js|node_modules|package.json)" ] // structure to analyse
);
// I create an empty array to put all elements in, once cleaned.
var fileList = [];
tempFileList.forEach(function(url){
var cwd = url;
cwd = cwd.replace(mycwd, "");
fileList.push(cwd);
})
var watchObject = {};
var premailerObject = {};
fileList.forEach(function(name) {
watchObject[name] = {
files: [name + '/*.html', name + '/scss/**/*.scss'],
tasks: ['sass', 'premailer:' + name]
};
var filesObject = {};
filesObject[name+'/css/main.css'] = name + '/index.html';
premailerObject[name] = {
options: { css: name + '/css/main.css', verbose: false },
files: [ filesObject ]
};
});
var configObject = {
watch: watchObject,
premailer: premailerObject
};
// just to check the final structure
console.log(configObject);
grunt.initConfig(configObject);
};
I am using Browserify within gulp. I am trying to compile down my tests to a single file as well. But unlike my main app, which I have working just fine, I am having trouble getting the tests to compile. The major difference is the tests have multiple entry points, there isn't one single entry point like that app. But I am getting errors fro Browserify that it can't find the entry point.
browserify = require 'browserify'
gulp = require 'gulp'
source = require 'vinyl-source-stream'
gulp.task 'tests', ->
browserify
entries: ['./app/js/**/*Spec.coffee']
extensions: ['.coffee']
.bundle
debug: true
.pipe source('specs.js')
.pipe gulp.dest('./specs/')
Below is a task I was able to build that seems to solve the problem. Basically I use an outside library to gather the files names as an array. And then pass that array as the entry points
'use strict;'
var config = require('../config');
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var glob = require('glob');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
gulp.task('tests', function(){
var testFiles = glob.sync('./spec/**/*.js');
return browserify({
entries: testFiles,
extensions: ['.jsx']
})
.bundle({debug: true})
.pipe(source('app.js'))
.pipe(plumber())
.pipe(gulp.dest(config.dest.development));
});
Here's an alternate recipe that fits more with the gulp paradigm using gulp.src()
var gulp = require('gulp');
var browserify = require('browserify');
var transform = require('vinyl-transform');
var concat = require('gulp-concat');
gulp.task('browserify', function () {
// use `vinyl-transform` to wrap around the regular ReadableStream returned by b.bundle();
// so that we can use it down a vinyl pipeline as a vinyl file object.
// `vinyl-transform` takes care of creating both streaming and buffered vinyl file objects.
var browserified = transform(function(filename) {
var b = browserify(filename, {
debug: true,
extensions: ['.coffee']
});
// you can now further configure/manipulate your bundle
// you can perform transforms, for e.g.: 'coffeeify'
// b.transform('coffeeify');
// or even use browserify plugins, for e.g. 'minifyiy'
// b.plugins('minifyify');
// consult browserify documentation at: https://github.com/substack/node-browserify#methods for more available APIs
return b.bundle();
});
return gulp.src(['./app/js/**/*Spec.coffee'])
.pipe(browserified)/
.pipe(concat('spec.js'))
.pipe(gulp.dest('./specs'));
});
gulp.task('default', ['browserify']);
For more details about how this work, this article that I wrote goes more in-depth: http://medium.com/#sogko/gulp-browserify-the-gulp-y-way-bb359b3f9623
For start, you can write a suite.js to require all the tests which you want to run and browserify them.
You can see two examples from my project https://github.com/mallim/sbangular.
One example for grunt-mocha-phantomjs
https://github.com/mallim/sbangular/blob/master/src/main/resources/js/suite.js
One example for protractor
https://github.com/mallim/sbangular/blob/master/src/main/resources/js/suite.js
This is just a start and I am sure there are more fancy ways available.
A little more complicated example to build files by glob pattern into many files with watching and rebuilding separated files. Not for .coffee, for es2015, but not a big difference:
var gulp = require("gulp");
var babelify = require("babelify");
var sourcemaps = require("gulp-sourcemaps");
var gutil = require("gulp-util");
var handleErrors = require("../utils/handleErrors.js");
var browserify = require("browserify");
var eventStream = require("event-stream");
var glob = require("glob");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var watchify = require("watchify");
var SRC_PATH = "./src";
var BUILD_PATH = "./build";
var bundle = function (bundler, entryFilepath) {
console.log(`Build: ${entryFilepath}`);
return bundler.bundle()
.on("error", handleErrors)
.pipe(source(entryFilepath.replace(SRC_PATH, BUILD_PATH)))
.pipe(buffer())
.on("error", handleErrors)
.pipe(
process.env.TYPE === "development" ?
sourcemaps.init({loadMaps: true}) :
gutil.noop()
)
.on("error", handleErrors)
.pipe(
process.env.TYPE === "development" ?
sourcemaps.write() :
gutil.noop()
)
.on("error", handleErrors)
.pipe(gulp.dest("."))
.on("error", handleErrors);
};
var buildScripts = function (done, watch) {
glob(`${SRC_PATH}/**/[A-Z]*.js`, function (err, files) {
if (err) {
done(err);
}
var tasks = files.map(function (entryFilepath) {
var bundler = browserify({
entries: [entryFilepath],
debug: process.env.TYPE === "development",
plugin: watch ? [watchify] : undefined
})
.transform(
babelify,
{
presets: ["es2015"]
});
var build = bundle.bind(this, bundler, entryFilepath);
if (watch) {
bundler.on("update", build);
}
return build();
});
return eventStream
.merge(tasks)
.on("end", done);
});
};
gulp.task("scripts-build", function (done) {
buildScripts(done);
});
gulp.task("scripts-watch", function (done) {
buildScripts(done, true);
});
Complete code here https://github.com/BigBadAlien/browserify-multy-build