How to know the directory from which a script is called? - javascript

I'm running a script defined in my package.json defined like "generate": "node generators/index.js"and it simply runs when I run npm run generate.
My script generates a copy from a template folder that is in the root of my project, the thing is that it's creating the template copies to the same root folder, and what I want it to do is to create the copy in the folder where I'm currently in the terminal.
Eg. I am in bin/data I run my command and I want to create a copy of the folder from my template stored in templates/state so that the copy of this template will be created in bin/data/state
I was trying to use the proccess.cwd() method but it creates all in the root path as this is a method that is called in a script stored in root folder.
How can I achieve this?

Use (process.env.PWD) inside the node script.

Related

How can I run this JavaScript file?

I have this project:
but I don't know how to run the generate_js.js in my browser so I can see use console.log inside of the file.
The whole purpose of this project is to run generate_js.js, which is then supposed to generate an icon.js file which contains the svg icons in a particular object format/structure. But what happens when I run generate_js.js is that a folder generate_js is created with all the icons as js files, and each file has an export statement.
I am trying to understand how is all of this working, but I can't. I need to be able to see what's happening on my browser. I need to use console.log to see, but I don't know how to run this project on my browser. There is no index.html file, and when I created one, and linked the project_js.js with a script tag, I keep getting Uncaught ReferenceError: require is not defined error.
How can I run this JavaScript/project on my browser?
Here's the relevant part of package json:
Note: This project is installed as a dependency inside another project, and inside the node_modules, there's a dist folder which contains the icons.js file that I referred to. In it, all the icons are created as objects. I need to change the way the object structure a bit, so I need to understand how are they generated by this generate.js file, but I need to be able to console.log what's happening inside the file.

How to access to dist files built by vue-cli?

Please, help me understand, how to deal with such issue:
I use vue-cli and I want to build in dev mode some js file and then be able to access it by url like: http://localhost:8080/my-file.js
But by default, I can't do it in such way. As I understand, I have to override devServer option?
You can put the JS files you want to include in a root folder called /public/ and when yarn build runs (or npm build if you're using that) it will output them exactly as they are in public to the dist folder for reference like you're looking for.
Note that the public folder needs to be at the same level as your src folder - not inside the src folder.
Source: https://cli.vuejs.org/guide/html-and-static-assets.html#preload

VSTS Build Configuration, how to copy files from a specific folder

Here is the structure of files in my vsts project:
$/intra
-BuildProcess Tempalates
-intra-DEV
-Project
-Solution-1
-Solution-2
-intra-QA
-intra-PROD
I have defined the build configuration for the infra-DEV branch and then building the solution via MSBuild. And on the xext step i am trying to copy the build'ed files from $(Build.SourcesDirectory) to $(build.artifactstagingdirectory).
Here, when i use "" in the 'contents' section, it will copy the below folders and the files in it
-$/intra
-BuildProcess Tempalates
-intra-DEV
but how can i copy only the -intra-DEV folder and the contents inside it.

Gulp task to copy folder into build folder give empty folder

So i have built my own module and am trying to make a gulp task to copy the folder into my build folder. When this happens, nothing inside the folder is created in my build folder, it is just an empty folder.
My gulp task:
gulp.task("MyModule", function() {
return gulp.src("MyModule")
.pipe(chmod(777))
.pipe(gulp.dest(paths.build.node_modules));
});
paths.build.node_modules resolves to: build/node_modules
MyModule is in the root of the application folder.
Any reason why it would just be copying the folder and nothing inside of it?
You're not instructing it to copy the contents of the folder.
try gulp.src(["MyModule", "MyModule/**/*"], base:{'.'}) to copy the folder and everything in it instead of just the folder.

Webstorm File Watchers repeats calling batch file for ever

I am using File Watchers within Webstorm for calling a batch file.
This batch file contains an Ant call command like this:
call ant "clean" "debug" "compress" -f C:\Users\cm\workspace2\Games\jsfiles\PokerGame\build\build.xml
File Watchers triggers every time I save changed js files and does not stop it calls and for ever.
The picture shows my configuration for File Watcher in Webstorm.
What am I doing wrong?
just a supposition: the IDE sees the .js files generated by ant (as a result of 'compress' target running) and, as it watches .js files, runs the watcher again and again... Try excluding the directory where your minified files are created from watcher scope - create a new scope (Settings/scopes) with this folder excluded and then set this scope to your file watcher

Categories

Resources