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"
I am trying to write a npm script that goes trought all of my src files and tests (lints) files that end in either .ts .tsx .js or .jsx. So the linter should test all of these (and only these).
What I have so far:
"lint": "eslint --max-warnings 0 --ext .js \"src/**/*.ts*\""
Does this test both .ts and .tsx files?
How do I write a pattern for multiple file types?
You could do it like this:
"lint": "eslint --max-warnings 0 --ext .js \"src/**/*.{ts,tsx}\""
As can be seen Here
As far as I know, that is the only way to handle multiple file extensions. When using a asteriks, i get the feedback "The system cannot find the path specified."
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.
We are trying to separate our project into "sub modules" within single repo, but keep things like webpack, express server global, so assume structure like this
package.json
server.js
index.js
node_modules/
public/
index.html
dashboard.js
onboarding.js
dashboard/
index.js
package.json
node_modules/
components/
assets/
onboarding/
index.js
package.json
node_modules/
...
idea here is to keep build / routing / server logic at root lvl and separate modules like dashboard and onboarding into their separate folders and allow them to use their own node modules.
Will this work? Will node modules be included correctly?
webpack will build assets to public/ folder, with some vendor assets and several entry points i.e. all index.js files
What you are proposing will work fine and compile as you expect. NodeJS will initially look for modules included in your modules 'node_modules' sub-directory and then work up the ladder.
I've been attempting to implement a build solution using NPM scripts as opposed to Gulp/Grunt/etc as outlined here: http://substack.net/task_automation_with_npm_run and here: http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/. However, I'm struggling to integrate a clean and sensible approach for managing numerous Jade files in the build process.
The Jade CLI supports passing it a directory and outputting all of the deeply nested compiled Jade files. This is great, however, this completely flattens the folder structure. I'd ideally like to have Jade output the results whilst maintaining the directory structure. What's the best way to go about this?
Example folder structure:
package.json
src/
foo.jade
bar/
baz.jade
qux.jade
Running jade src -o build outputs:
package.json
build/
foo.html
baz.hmtl
qux.html
src/
Instead of:
package.json
build/
foo.html
bar/
baz.html
qux.html
src/
Not sure how I missed this but for anyone who should happen upon this in the future, the -H flag is your friend.
ex: jade src -H -o build
ref: https://github.com/jadejs/jade-cli/blob/master/index.js#L36