I've decided to rewrite my generator from ES5 syntax to ES6. But I faced the issue with transpiling generator on pre-publish.
Issue: As we know Yeoman generators have templates folder where different files is located. When Babel is traspiling all the generators sources via babel src --out-dir generators it skips the templates files or breaks the traspiling with error.
My Attepmts: I was trying to make something like babel src --out-dir generators && cp -rn src/ generators/ but I don't like this solution.
Question: How can I make old structure generators/sub-generators but in ES6 syntax, not in ES5.
Thanks.
UPD: I'm hoping that Yeoman has something like Mocha has --require babelhook.js.
I've found the solution for this case.
First of all, I've created src folder where generator sources in ES6 syntax is located. Structure of this folder is the same as in usual ES5 generator.
When I want to compile these sources I just need to copy them and compile in generators folders.
So I've written the following scripts in package.json;
"scripts": {
"clean": "rm -rf ./generators",
"compile": "npm run clean && cp -r src/ generators/ && babel src --out-dir generators",
"prepublish": "npm run compile",
"test": "istanbul cover _mocha"
}
And last thing that I've done is add ignore field in .babelrc file. So I'm sure that templates will be just copied but not traspiled.
{
"stage": 0,
"ignore": [
"app/templates",
]
}
Related
I setup a basic web app in VS Code. I want to copy the html file to the out dir whenever it changes. My folder structure looks like this:
src
css
_Index.scss
global.scss
html
index.html
scripts
index.ts
In my package.json I included the following scripts to automatically compile TypeScript and SASS files:
"watch:tsc": "tsc --watch",
"watch:sass": "sass --watch --sourcemap=none src:out",
"watch": "concurrently --kill-others \"npm run watch:sass\" \"npm run watch:tsc\""
A tsconfig.json handles the TypeScript compilation. This is all working fine.
What do I need to setup to also copy the html file to the out dir? Simply including a copy statement feels wrong. Maybe at some point I'd like to include images as well, I wouldn't want to adjust the copy statement for every new file type would I?
I feel like I'm missing some super basic stuff here.
I want to run lint check all the file *.js without node_modules
Here my command: "lint": "eslint **/*.js",, My folder structure look like: app > module_name > module.js but in the app folder still having some files common like helpers.js server.js and I also want to check them.
In .eslint config I added "ignorePatterns": "node_modules" and tried added a file .eslintignore and add node_modules but it's not working.
When I run npm run lint it always throw error:
Oops! Something went wrong! :(
ESLint: 7.32.0
You are linting "node_modules/bignumber.js", but all of the files matching the glob pattern "node_modules/bignumber.js" are ignored.
If you don't want to lint these files, remove the pattern "node_modules/bignumber.js" from the list of arguments passed to ESLint.
If you do want to lint these files, try the following solutions:
* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.
You could add node_modules/ in your .eslintignore file, and update the package.json file with script: "lint": "eslint --ext .js app/", before running npm run lint.
You could add node_modules/ in your .eslintignore file, and update the package.json file with script:
if u r using ubuntu/linux
"lint": "eslint '**/*.js'"
if project structure like these folder/file.js
if u r using windows
"lint": "eslint **/*.js"
if project structure like these folder/file.js
The Situation
I'm working on a project in Node.js and using babel to transpile my code. My package.json has a build command defined like this:
"scripts": {
"build": "yarn run babel src -d lib",
},
The Problem
This transpiles fine, taking the content of src and outputing the result to lib, but there are two issues:
lib will contain old files from past transpiles even if they no longer have a matching file in src.
Babel will not rename files with a changed case if my OS is case insensitive. For example, if I had transpiled a file named src/Foo.js and later renamed it to src/foo.js then future transpiles will still be named lib/Foo.js
The Question
Can I tell babel to wipe away the contents of the lib directory before transpiling or do I need to just insert a rm into the build script?
Babel does not have functionality to do this. It is very common to use a rimraf or some other means to delete the directory before running Babel. rm directly is certainly also an option, but that does get more complicated if you want to support Windows too, hence the rimraf usage.
Babel CLI has a flag to remove the output directory: --delete-dir-on-start
Couldn't find any online documentation for it, but it's listed in babel --help:
--delete-dir-on-start Delete the out directory before compilation
Was added in this PR back in 2017.
I am trying to run some Mocha tests within my Node.js app.
Here is my folder structure:
compute/
folder1/
app/
tests/
mytest.js
folder2/
app/
tests/
mytest2.js
I got a package.json in both with mocha installed.
When I try to start a test with yarn test, I got an error
Warning: Could not find any test files matching pattern: test
No test files found
How can I manage to run it?
Because my folders' names are "tests" and not "test" as in the default and they are not at source.
When you don't use the default folders, you need to specify them as arguments. An example follows:
mocha "folder{1,2}/**/tests/*.js"
If you want to run with only npm test/yarn test, then you need to update your package.json file like following:
"scripts": {
"test": "mocha \"folder{1,2}/**/tests/*.js\"",
},
It appears as though TypeScript is transpiling target files that are not executable.
I have to run chmod u+x <file> after transpilation to get the files to become executable.
This is the case, even if they have a hashbang:
#!/usr/bin/env node
How can I tell TypeScript / tsc to create files which are executable?
Changing file's permissions isn't typescript responsibility.
Solution 1.
Use a separate step in the build process in your package.json. For example:
{
"name": "temp",
"version": "1.0.0",
"scripts": {
"build": "tsc && chmod +x build/index.js"
},
"dependencies": {
"typescript": "^2.3.4"
}
}
Solution 2.
Write TypeScript Language Service Plugin. I think, in your case this is overengineering.