Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"tasks": [
{
"label": "build",
"args": [],
"args": ["build"],
"type": "shell",
"group": "build",
"isBackground": false,
Expand All @@ -25,7 +25,7 @@
},
{
"label": "build_without_view",
"args": [],
"args": ["build_without_view"],
"group": "build",
"isBackground": false,
"problemMatcher": [
Expand Down
58 changes: 41 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const gulp = require("gulp");
const eslint = require('gulp-eslint');
const eslint = require("gulp-eslint");
const tslint = require("gulp-tslint");
const PluginError = require('plugin-error');
const log = require('fancy-log');
const PluginError = require("plugin-error");
const log = require("fancy-log");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const webpack = require("webpack");
const del = require('del');
const del = require("del");
const download = require("download");
const extract = require("extract-zip");
const fs = require("fs");
const path = require("path");
const childProcess = require("child_process");
const argv = require('minimist')(process.argv.slice(2));
const argv = require("minimist")(process.argv.slice(2));

gulp.task("tslint", () => {
return gulp.src(["**/*.ts", "**/*.tsx", "!**/*.d.ts", "!./vendor/**", "!node_modules/**", "!./src/views/node_modules/**", "!out/**"])
Expand All @@ -28,39 +30,61 @@ gulp.task("eslint", () => {
gulp.task("html-webpack", (done) => {
const config = require("./src/views/webpack.config.js");
config.context = `${__dirname}/src/views`;
config.mode = argv.mode ? argv.mode : 'production';
config.mode = argv.mode ? argv.mode : "production";
return webpack(config, (err, stats) => {
const statsJson = stats.toJson();
if (err || (statsJson.errors && statsJson.errors.length)) {
statsJson.errors.forEach(webpackError => {
log.error(`Error (webpack): ${webpackError}`);
});

throw new PluginError('webpack', JSON.stringify(err || statsJson.errors));
throw new PluginError("webpack", JSON.stringify(err || statsJson.errors));
}
log('[webpack]', stats.toString());
log("[webpack]", stats.toString());
done();
});
});

gulp.task("node_modules-webpack", (done) => {
const config = require("./webpack.config.js");
config.context = `${__dirname}`;
config.mode = argv.mode ? argv.mode : 'production';
config.mode = argv.mode ? argv.mode : "production";
return webpack(config, (err, stats) => {
const statsJson = stats.toJson();
if (err || (statsJson.errors && statsJson.errors.length)) {
statsJson.errors.forEach(webpackError => {
log.error(`Error (webpack): ${webpackError}`);
});

throw new PluginError('webpack', JSON.stringify(err || statsJson.errors));
throw new PluginError("webpack", JSON.stringify(err || statsJson.errors));
}
log('[webpack]', stats.toString());
log("[webpack]", stats.toString());
done();
});
});

gulp.task("insert-serial-monitor-cli", async (done) => {
const platforms = [
"linux",
"darwin",
"win32",
];
const release = "latest";
const destDir = path.resolve("out", "serial-monitor-cli");

async function downloadAndUnzip(platform) {
const fileName = `${platform}.zip`;
const zipPath = path.join(destDir, fileName);
await download(`https://github.com/microsoft/serial-monitor-cli/releases/${release}/download/${fileName}`,
destDir,
);
await extract(zipPath, { dir: path.join(destDir, platform) });
fs.rmSync(zipPath);
}

Promise.all(platforms.map(downloadAndUnzip)).then(done);
});

gulp.task("ts-compile", () => {
const tsProject = ts.createProject("./tsconfig.json");
return tsProject.src()
Expand All @@ -71,13 +95,13 @@ gulp.task("ts-compile", () => {
// Correct source map path.
const relativeSourcePath = path.relative(path.dirname(file.path), path.join(file.base, sourcePath));
return relativeSourcePath;
}
},
}))
.pipe(gulp.dest("out"));
});

gulp.task("clean", (done) => {
return del('out', done);
return del("out", done);
});

gulp.task("genAikey", (done) => {
Expand All @@ -100,8 +124,8 @@ gulp.task("test", (done) => {
}

// When using cli command "npm test" to exec test, the depended extensions (cpptools) are not available so that
// the extension cannot be activated. As a workaround, remove extensionDependencies from package.json before running test
// and restore extensionDependencies after test exited.
// the extension cannot be activated. As a workaround, remove extensionDependencies from package.json before
// running test and restore extensionDependencies after test exited.
removeExtensionDependencies();

const child = childProcess.spawn("node", ["./out/test/runTest"], {
Expand Down Expand Up @@ -132,11 +156,11 @@ gulp.task("test", (done) => {
});
});

gulp.task("build", gulp.series("clean", "ts-compile", "html-webpack", "node_modules-webpack"));
gulp.task("build", gulp.series("clean", "ts-compile", "html-webpack", "node_modules-webpack", "insert-serial-monitor-cli"));

gulp.task("build_without_view", gulp.series("clean", "ts-compile"));

gulp.task("watch", () => {
gulp.watch(["./src/**/*", "./test/**/*", "!./src/views/**/*"], ["ts-compile"]);
gulp.watch(["./src/views/**/*", "!./src/views/node_modules/**"], ["html-webpack"]);
});
});
Loading