I have this directory structure
├── components
│ ├── quarks
│ │ └── index.js
│ │ └── ...
│ ├── bosons
│ │ └── index.js
│ │ └── GridLayout.vue
│ │ └── ...
│ ├── atoms
│ │ └── ButtonStyle.vue
│ │ └── InputStyle.vue
│ │ └── index.js
│ │ └── ...
│ ├── .......
└─────
I'd like to ignore the index.js within each folder, but I'm not getting it, I've tried it in several ways
const path = require('path')
const chokidar = require('chokidar')
const ROOT_PATH = path.resolve('components')
const watcher = chokidar.watch(ROOT_PATH, {
ignored: ROOT_PATH + '/*/index.js', //does not work
ignoreInitial: true
})
already tried:
'./components/**/index.js',
'./components/*/index.js',
'components/*/index.js',
'components/**/index.js',
'ROOT_PATH + '/**/index.js'
Anyone have any idea how to make it work?
The chokidar documentation specifies that the ignored parameter is anymatch-compatiable so this could be completed in many ways.
Here is a regular expression solution...
Any index.js file, even in the root folder:
{
ignored: /(^|[\/\\])index\.js$/,
// ...
}
Only index.js file in a sub-folder:
{
ignored: /[\/\\]index\.js$/,
// ...
}
Also note in your example you use signoreInitial this is not an option, perhaps you meant ignoreInitial?
Alternatively with callback:
{
ignored: (path) => { return path.endsWith('\\index.js') || path.endsWith('/index.js'); },
// ...
}
Chokidar seems bugged, defective to ignore files on MacOS, that's the impression I have.
So before running my action, I'm checking to see if the file is the same one I want to ignore.
chokidar
.watch('components', { ignoreInitial: true })
.on('all', (event, filename) => {
filename !== 'index.js'
// action here
})
What worked for me on Mac was using **:
ignored: ['**/node_modules'],
So if the other options don't work because of bugs, go for this one:
ignored: ['**/index.js'],
Related
ATM I have a folder in my NodeJS application where I store my JS files with a couple of functions. I require these files in my main.js at the top an use them as usual.
my-app/
├── node_modules/
├── my_jsfiles/
│ ├── functions_1.js
│ └── functions_2.js
├── package.json
└── main.js
main.js:
const myFuncs1 = require('./my_jsfiles/functions_1.js')
const myFuncs2 = require('./my_jsfiles/functions_2.js')
myFuncs1.someFuncsInside()
myFuncs2.someFuncsInside()
APPROACH: Now that I am going to use my_jsfiles in more applications I would like to make my own NodeJS module, which works so far, but I stuck at the point how I can include multiple js files instead of just calling functions from the index.js
my-app/
├── node_modules/
│ ├── my-jsfunctions/
│ │ ├── index.js
│ │ ├── functions_1.js
│ │ └── functions_2.js
├── package.json
└── main.js
main.js:
const myFuncs = require('my-jsfunctions')
//How do I call functions from functions_1.js and functions_2.js?
I know that I can export functions from the index.js
exports.someFunction = function () {
console.log("This is a message from the index.js");
}
But what is the propper way to call functions from the other files, because I do not want to have just one index.js file with million lines of code.
you just need to import all your functions into index.js file and export from there
my-app/
├── node_modules/
├── my_jsfiles/
│ ├── functions_1.js
│ └── functions_2.js
├── package.json
└── main.js
function_1.js
function functions_1_1(){
}
module.exports={functions_1_1}
function_2.js
function functions_2_1(){
}
module.exports={functions_2_1}
index.js
const {functions_1_1} = require("./function_1.js");
const {functions_2_1} = require("./function_2.js");
module.exports={functions_1_1,functions_2_1}
main.js
const {functions_1_1,functions_2_1} =require("./my_jsfiles/index.js");
functions_1_1()
functions_2_1()
you should just be able to do
const myFuncs1 = require('my_jsfiles/functions_1.js')
const myFuncs2 = require('my_jsfiles/functions_2.js')
isn't it working?
From your file index.js on my-jsfunctions, you can export function from other files like so
export * from './functions_1';
export * from './functions_2';
then you can import function
const func1 = require('my-jsfunctions').func1;
const func2 = require('my-jsfunctions').func2;
My Terraform directory structure looks something like :
├── deploy
│ ├── dev.tfvars
│ └── qa.tfvars
├── modules
│ ├── private
│ │ ├── bastion.tf
│ ├── db.tf
│ │ └── variables.tf
│ └── public
│ ├── web.tf
│ └── variables.tf
├── main.tf
In bastion.tf, I am trying to call a variable from variables.tf like this :
resource "aws_eip" "bastion" {
instance = "var.eip"
vpc = true
}
where, eip = 10.x.x.x is set in say, dev.tfvars.
And the configuration for main.tf looks like :
provider "aws" {}
terraform {
backend "s3" {}
}
module "private" {
source = "./modules/private"
}
While running terraform validate, it gives me an error that - The argument "eip" is required, but no definition was found. Even if I try giving eip to module like :
module "private" {
source = "./modules/private"
eip = var.eip
}
it gives me another error :
An input variable with the name "eip" has not been declared.
This variable can be declared with a variable "eip" {} block
I have variable "eip" {} already defined in my variables.tf such that it takes the values from .tfvars file, but somehow it isn't. Can anyone suggest what else could I be missing?
Sounds like you are missing variables declarations...
From your file structure:
├── deploy
│ ├── dev.tfvars
│ └── qa.tfvars
├── modules
│ ├── private
│ │ ├── bastion.tf
│ ├── db.tf
│ │ └── variables.tf
│ └── public
│ ├── web.tf
│ └── variables.tf
├── main.tf
There does not seem to be a companion variables.tf for the main.tf each level needs to declare the variables that will be used by resources or submodules.
If you upload your code to GitHub and post a link I could help to get you unblocked.
I have a react project inside of a folder and I want react-scripts to target and compile from a folder. It looks like this
project
│ README.md
│ package.json
│
└───react
│ │ jsconfig.json
│ │
│ └───src
│ │
│ └───public
│
└───api
│ tsconfig.json
│
└───src
from the project/package.json I want to run react-scripts start and have it compile the /react folder. How can I do this?
I solved the issue with the use off react-app-rewired
See this stackoverflow post on details of how it was done.
const path = require('path');
module.exports = {
paths: function (paths, env) {
paths.appIndexJs = path.resolve(__dirname, 'react/src/index.js');
paths.appSrc = path.resolve(__dirname, 'react/src');
paths.appPublic = path.resolve(__dirname, 'react/public');
paths.appHtml = path.resolve(__dirname, 'react/public/index.html');
return paths;
}
}
I have multiple themes with sass and a common folder with common options but the files should be compiled each theme css folder. It's a little complicated to explain. I want to share with you the scaffolding. I want to compile this with grunt but I don't know how to do
common_files
sass
common_file.scss
theme_foo
sass
file_one.scss
file_two.scss
css
style.scss
theme_bar
sass
file_one.scss
file_two.scss
css
style.scss
Gruntfile.js
I want to compile each theme with their own sass files and common files in their css folder.
Here is my Gruntfile.js
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
grunt.initConfig({
watch: {
sass: {
files: ['sass/{,*/}*.{scss,sass}'],
tasks: ['sass'],
},
},
sass: {
dist: {
options: {
style: 'expanded', // For compressed use 'compressed'
},
files: [{
expand: true,
cwd: 'sass',
src: ['*.{scss,sass}'],
dest: 'css',
ext: '.css',
},],
},
},
})
/* Load plugins */
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-csslint');
/* Tasks */
// Default task
grunt.registerTask('default', [, 'watch']);
};
Here is a complete solution to your problem :
Update your structure
├── project-dir
│ ├── common
│ │ ├── scss
│ │ │ ├── _button.scss
│ │ │ ├── _form.scss
│ │ │ ├── common.scss
│ ├── theme-foo
│ │ ├── scss
│ │ │ ├── _tag.scss
│ │ │ ├── _figure.scss
│ │ │ ├── theme-foo.scss
│ ├── theme-bar
│ │ ├── scss
│ │ │ ├── _tag.scss
│ │ │ ├── _figure.scss
│ │ │ ├── theme-bar.scss
Use main scss file of each folder (common, theme-foo, theme-bar) to import all its files. And for theme files, import alsocommon.scss` file.
E.g : common.scss file :
#import 'button.scss',
'form.scss';
E.g : theme-foo.scss file :
// import common style
#import 'common.scss';
// import theme style
#import 'tag.scss',
'form.scss';
Now you just have to compile theme-foo.scss and theme-bar.scss with grunt-contrib-sass.
E.g :
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
sass: {
dist: {
files: {
'project-dir/theme-foo/css/theme-foo.css': 'project-dir/**/theme-foo.scss',
'project-dir/theme-bar/css/theme-bar.css': 'project-dir/**/theme-bar.scss'
}
}
}
});
grunt.loadNpmTasks('grunt-sass');
};
Take a look sass-guidelines and specially 7-1 pattern to learn a lot of good practices.
This is my configure file:
The layout.jade does not seem to be working. But the jade is working. I used Chrome to check, and am sure that the layout HTML is not loaded into the page.
module.exports = function(app, express, mongoose){
var config=this
app.configure(function (){
app.set('views',__dirname+'/views')
app.set('view engine','jade')
app.set('view options', {layout:true})
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.cookieParser())
app.use(express.session({secret: 'topsecret',store: new express.session.MemoryStore}))
app.use(express.static(app.path.join(app.application_root,"public")))
app.use(express.errorHandler({dumpExceptions:true,showStack:true}))
app.use(express.bodyParser({keepExtensions: true, uploadDir:"./public/uploads"}))
app.use(app.router)
})
/*DB part:*/
app.mongoose.connect('mongodb://localhost/dio_database')
return config
}
The render command:
app.get('/items/:id',function(req,res){
models.ItemModel.findOne({_id:req.params.id}).exec(function(err,item){
if (!err){
res.render('item.jade',item)
} else
return console.log(err)
})
})
My layout.jade, quite simple:
!!!
doctype 5
html
head
title "Dio"
link(rel='icon', href='favicon.ico', type='image/x-icon')
link(rel='shortcut', href='favicon.ico', type='image/x-icon')
link(rel="shortcut", href="favicon.ico", type="image/vnd.microsoft.icon")
link(rel="icon", href="favicon.ico", type="image/vnd.microsoft.icon")
script(src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js")
script(src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js")
script(src="./javascripts/underscore-min.js")
script(src="./javascripts/backbone-min.js")
link(rel='stylesheet', href='./css/main.css', type="text/css", media="screen")
body
div#topbar Dio--where shitty thing happens
div#main!= body
footer
p
| Node.js MVC template by XXX
And the following is my npm list:
├─┬ bcrypt#0.7.3
│ └── bindings#1.0.0
├─┬ express#3.0.3
│ ├── commander#0.6.1
│ ├─┬ connect#2.7.0
│ │ ├── bytes#0.1.0
│ │ ├── formidable#1.0.11
│ │ ├── pause#0.0.1
│ │ └── qs#0.5.1
│ ├── cookie#0.0.5
│ ├── cookie-signature#0.0.1
│ ├── crc#0.2.0
│ ├── debug#0.7.0
│ ├── fresh#0.1.0
│ ├── methods#0.0.1
│ ├── mkdirp#0.3.3
│ ├── range-parser#0.0.4
│ └─┬ send#0.1.0
│ └── mime#1.2.6
├── fs#0.0.0
├── imagemagick#0.1.3
├─┬ jade#0.27.7
│ ├── coffee-script#1.4.0
│ ├── commander#0.6.1
│ └── mkdirp#0.3.4
├─┬ mongodb#1.2.2
│ └── bson#0.1.5
├─┬ mongoose#3.4.0
│ ├── hooks#0.2.1
│ ├─┬ mongodb#1.1.11
│ │ └── bson#0.1.5
│ ├── ms#0.1.0
│ └── sliced#0.0.3
├─┬ node-static#0.6.5 extraneous
│ ├── colors#0.6.0-1
│ └─┬ optimist#0.3.5
│ └── wordwrap#0.0.2
└── path#0.4.9
Actually the reason for such problem is quite simple:
Express 3 no longer supports layout..But do not be sad. Actually Express 3 begins to adopt a more natural and easier way, which is called block/extends.
The basic usage should be like this:
// In layout file: layout.jade
html
head
title XXX
block scripts
body
block content
block footer
// in a extended file, for example index.jade:
extends layout
block scripts
//write javascript part
block content
// write content
block footer
// write the footer
It actually becomes easier and more flexible. Glad to get it finally. But it took me more than 2 hours.
I am just wondering why so few people mentioned this change more clearly and openly. Hope this post can help some people like me.