First of all thanks for trying to help me. I'll get straight into it.
I'm trying to transpile Typescript files to JS files. These typescript files are scattered throughout a directory (all modules follow the same file structure)
The package.json command is:
"build:js": "babel app/code/VendorName/**/view/adminhtml/web/ts --out-dir js --extensions \".ts,.tsx\" --source-maps inline"
All of the typescript files reside in different folders within VendorName (notice the **). Within it through the typescript files are in view/adminhtml/web/ts, always.
I would like to transpile all of these files and put them in their respective modules' js folders which are in:
app/code/VendorName/**/view/adminhtml/web/js. Meaning literally next to the ts folder. How can I make it, so that the --out-dir is relative to the directory that I'm transpiling? Is that even possible? Otherwise I'll have to setup a config for each and every single module I'm developing, which would be a bit of a nuisance.
The correct answer is adding the --relative flag. Position is very important "babel --verbose app/code/VenderName/**/view/adminhtml/web/ts --ignore \"**/*.d.ts\" --relative --out-dir ../js --extensions \".ts\" --source-maps inline"
So I have a question, I'm looking into compiling all of my .js files along with the node modules also into one single .js file.
I currently have all of my import statements inside main.js, and then I have my babel script using the following: "js-build": "babel js --out-file js/all.js --ignore js/main/main.js", that takes all the imports from main.js and compiles it to all.js.
Problem:
It doesn't overwrite the files and I can't import node_modules, does someone have any recommendations on traditional ways to use npm to compile js files? Do you recommend things such as webpack? I'd like to stay away from gulp.
i can do it by remove
exclude: /node_modules/
I want ESLint skip processing .js files and only deal with .ts files.
To that end, I created .eslintignore and added:
*.js
**/*.js
However, it seems like ESLint ignores this file. Am I missing something simple here?
Assuming all the other typescript-eslint config is configured, you have to explicitly tell ESLint you want to include those file extensions:
eslint <path to files> --ext ts
I have a problem to structure my electron project using typescript.
Basically, I want my file structure to look like this:
+dist
compiled .js files from .ts files
+src
.ts files
+gui
html pages
+package.json
+tsconfig.json
My tsconfig.json files is as follows:
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true
},
and my package.json files is as follows:
"name": "electron_test",
"version": "1.0.0",
"description": "",
"main": "./dist/main.js",
"scripts": {
"build": "tsc",
"prestart": "npm run build",
"start": "tsc && electron ./dist/main.js",
"pack": "electron-packager . sample --out=dist --arch=x64 --platform=win32 --electron-version=3.0.3 --overwrite --prune --ignore=dist"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^3.0.3",
"electron-packager": "^12.2.0",
"typescript": "^3.1.1"
}
}
The problem with these files is when typescript files are compiled, they are converted to javascript inside the dist file. Here I need to use main.js for my electron app to call within html pages. However when Html pages are not inside the dist file, if I run the app, html pages are not called. Somehow main.js and html pages should be inside the same directory.
You probably want to move all source files to src directory. This is not required but this is how usually people structure projects.
src
controllers (or w/e you call it)
ts files
gui
html files
I would recommend to use webpack instead of raw tsc. You want to use CopyWebpackPLugin
const CopyWebpackPlugin = require('copy-webpack-plugin');
plugins: [
new CopyWebpackPlugin([
{from: './src/gui', to: ''},
]),
If you still want to use tsc, you can copy files manually my using cp in package.json.
package.json:
"scripts": {
"copyHtml": "cp ./src/gui ./dist",
"build": "tsc && npm run copyHtml",
"prestart": "npm run build",
"start": "tsc && npm run copyHtml && electron ./dist/main.js",
"pack": "electron-packager . sample --out=dist --arch=x64 --platform=win32 --electron-version=3.0.3 --overwrite --prune --ignore=dist"
},
You can also use cpx if you worry about crossOs support.
Anyway the point is that dist directory should contain all output files. And it's self-contained, meaning you can send this directory to anyway and he/she should be able to run your project w/o any other dependencies.
I know I'm a year late to the party, but I hope I can still help others with my answer. Here's an alternative solution to the complex file structure of electron apps that I came up with myself. It's not as conventional, but to me it makes a lot more sense.
My project's directory structure is roughly as follows:
app/
|- index.html
|- index.js (electron main script)
|- bundle.js (generated via webpack)
build/
|- compiled ts -> js files
dist/
|- packaged executables
src/
|- all source files (in typescript)
Basically, I just put the electron main script into app/ alongside index.html. This makes sense to me since dist/ should be reserved for the distributed application delivered to the end user, and in the case of an electron app, we don't give the user access to index.html directly anyways. The build process then runs as follows:
call tsc on src/, output into build/
done by setting "outdir": "build" in tsconfig.json, then running npx tsc
call webpack on build/, bundle everything into a single app/bundle.js
done by setting output: { filename: 'bundle.js', path: path.resolve(__dirname, 'app')}, then running webpack build/src/[entry point]
index.html loads bundle.js via a script element
done by adding <script src="bundle.js"></script>
main.js renders index.html via electron
done by setting "main": "app/main.js" in package.json, then running npx electron .
electron-builder packages app/ into a single executable
done by npx electron-builder, with a corresponding config specified in package.json
Given how the build process runs, the directory structure makes a lot of sense to me. src/ stores the typescript source files, build/ stores the built javascript files, app/ stores all the files for the electron renderer process, and dist/ stores the packaged distributables.
I've been hunting around on stackoverflow but I can't find a method to exclude a file from being included in the linter script I have. I am trying to exclude the karma.conf.js file:
"lint": "node_modules/eslint/bin/eslint.js --ext=.js client/ lib/ models/ routes/ test/backend/ *.js !karma.conf.js"
I've tried using: -I, --exclude='karma.conf.js', --ignore=karma.conf.js and a few others, but no luck. Any advice?