🎉 initial TS projec
parent
a54b290ac5
commit
7f2470d32e
|
|
@ -0,0 +1,6 @@
|
|||
dist
|
||||
node_modules
|
||||
app-config.user.yaml
|
||||
src/app-config.ts
|
||||
|
||||
.idea/
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# espruino-ts-quickstart
|
||||
Quickstart for Espruino using typescript and Visual Studio Code IDE
|
||||
|
|
@ -0,0 +1 @@
|
|||
refreshPeriodSec: 2
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Port where mcu device is located
|
||||
port: COM4
|
||||
|
||||
# ESP32 after flash has 115200 speed.
|
||||
port_speed: 115200
|
||||
|
||||
board: ESP32
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
const gulp = require('gulp');
|
||||
const ts = require('gulp-typescript');
|
||||
const tsProject = ts.createProject('tsconfig.json');
|
||||
const fs = require("fs");
|
||||
const { fork } = require('child_process');
|
||||
const path = require("path");
|
||||
const yaml = require("js-yaml");
|
||||
const _ = require("lodash");
|
||||
|
||||
const envConfig = yaml.load(fs.readFileSync("env-config.yaml"));
|
||||
|
||||
const distDir = "./dist";
|
||||
const srcDir = "./src";
|
||||
const espReadyBundleFileName = "bundle.js";
|
||||
const espReadyBundlePath = path.join(distDir, espReadyBundleFileName);
|
||||
const appFileName = "app.js";
|
||||
const appFilePath = path.join(distDir, appFileName);
|
||||
const appConfigTsFileName = "app-config.ts";
|
||||
const appConfigFileName = "app-config.yaml";
|
||||
const userAppConfigFileName = "app-config.user.yaml";
|
||||
const espConsoleBeingWatchedFileName = "esp-console-input.js";
|
||||
const espConsoleBeingWatchedFilePath = path.join(distDir, espConsoleBeingWatchedFileName);
|
||||
|
||||
|
||||
function prepare_for_espruino(cb) {
|
||||
if (!fs.existsSync(appFilePath)) {
|
||||
cb("main app file does not exit " + appFilePath);
|
||||
return;
|
||||
}
|
||||
|
||||
let appContent = fs.readFileSync(appFilePath).toString();
|
||||
appContent = appContent.replace('Object.defineProperty(exports, "__esModule", { value: true });', "");
|
||||
fs.writeFileSync(appFilePath, appContent);
|
||||
|
||||
const buildproc = fork(
|
||||
require.resolve("espruino/bin/espruino-cli"),
|
||||
["--board", envConfig.board, appFileName, "-o", espReadyBundleFileName],
|
||||
{ cwd: distDir });
|
||||
buildproc.on('close', () => {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function compile_ts() {
|
||||
const tsResult = tsProject.src().pipe(tsProject());
|
||||
return tsResult.js.pipe(gulp.dest(distDir));
|
||||
}
|
||||
|
||||
function content_to_dist() {
|
||||
return gulp
|
||||
.src("src/**/*.js", { base: 'src' })
|
||||
.pipe(gulp.dest(distDir));
|
||||
}
|
||||
|
||||
function send_to_espruino_console(cb) {
|
||||
const content = fs.readFileSync(espReadyBundlePath);
|
||||
fs.writeFile(
|
||||
espConsoleBeingWatchedFilePath,
|
||||
content,
|
||||
(err) => {
|
||||
if (err) { throw err; }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function clear_espruino_watch_file(cb) {
|
||||
fs.writeFile(
|
||||
espConsoleBeingWatchedFilePath,
|
||||
"",
|
||||
(err) => {
|
||||
if (err) { throw err; }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function espruino_console(cb) {
|
||||
const buildproc = fork(
|
||||
require.resolve("espruino/bin/espruino-cli"),
|
||||
["--board", envConfig.board, "-b", envConfig.port_speed, "--port", envConfig.port, "-w", espConsoleBeingWatchedFileName],
|
||||
{ cwd: distDir });
|
||||
buildproc.on('close', () => {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function gen_config_ts(cb) {
|
||||
if (!fs.existsSync(userAppConfigFileName)) {
|
||||
const content = fs.readFileSync(appConfigFileName)
|
||||
.toString()
|
||||
.split("\n")
|
||||
.map(x => `# ${x}`)
|
||||
.join("\n");
|
||||
|
||||
fs.writeFileSync(userAppConfigFileName, content, { encoding: "utf-8" });
|
||||
}
|
||||
|
||||
const appConfig = yaml.load(fs.readFileSync(appConfigFileName));
|
||||
const userAppConfig = yaml.load(fs.readFileSync(userAppConfigFileName));
|
||||
const mergedAppConfig = _.assign(appConfig, userAppConfig);
|
||||
const jsonString = JSON.stringify(mergedAppConfig);
|
||||
const resultConfigTsContent = `export default ${jsonString};`;
|
||||
fs.writeFileSync(path.join(srcDir, appConfigTsFileName), resultConfigTsContent);
|
||||
cb();
|
||||
}
|
||||
|
||||
gulp.task("gen-config-ts", gen_config_ts);
|
||||
|
||||
gulp.task("compile-ts", gulp.series("gen-config-ts", compile_ts));
|
||||
|
||||
gulp.task("content-to-dist", content_to_dist);
|
||||
|
||||
gulp.task("prepare-for-espruino", gulp.series('compile-ts', 'content-to-dist', prepare_for_espruino));
|
||||
|
||||
gulp.task("build", gulp.series("prepare-for-espruino"));
|
||||
|
||||
gulp.task("send-to-espurino-console", send_to_espruino_console);
|
||||
|
||||
gulp.task("clear-espurino-watch-file", clear_espruino_watch_file);
|
||||
|
||||
gulp.task("espruino-console", gulp.series("clear-espurino-watch-file", espruino_console));
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "papam_clockinfo_tests",
|
||||
"version": "1.0.0",
|
||||
"description": "Quickstart for Espruino using typescript and Visual Studio Code IDE",
|
||||
"main": "app.js",
|
||||
"repository": {
|
||||
"url": "https://github.com/stasberkov/espruino-ts-quickstart"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp build",
|
||||
"send-to-espruino-console": "gulp send-to-espruino-console",
|
||||
"espruino-console": "gulp espruino-console"
|
||||
},
|
||||
"author": "Stanislav Berkov",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/espruino": "^1.94.10",
|
||||
"espruino": "^0.1.55",
|
||||
"gulp": "^5.0",
|
||||
"gulp-typescript": "^5.0.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash": "^4.17",
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import appConfig = require("./app-config");
|
||||
|
||||
setInterval(() => {
|
||||
const temp = E.getTemperature();
|
||||
console.log("Current temp:", temp);
|
||||
}, appConfig.default.refreshPeriodSec * 1000);
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es2015",
|
||||
"dom" // setInterval, console
|
||||
],
|
||||
"strict": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue