Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format build files #359

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 62 additions & 78 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,113 +10,97 @@ const gulp = require("gulp");
const rename = require("gulp-rename");

gulp.task("copy-thirdparty-codemirror", function () {
return gulp.src(
[
"addon/{,*/}*",
"keymap/{,*/}*",
"lib/{,*/}*",
"mode/{,*/}**",
"theme/{,*/}*"
],
{
return gulp
.src(["addon/{,*/}*", "keymap/{,*/}*", "lib/{,*/}*", "mode/{,*/}**", "theme/{,*/}*"], {
cwd: "src/node_modules/codemirror",
base: "src/node_modules/codemirror"
}
)
base: "src/node_modules/codemirror",
})
.pipe(gulp.dest("src/thirdparty/CodeMirror"));
});

gulp.task("copy-thirdparty-less", function () {
return gulp.src(
"dist/less.min.js",
{
cwd: "src/node_modules/less"
}
)
return gulp
.src("dist/less.min.js", {
cwd: "src/node_modules/less",
})
.pipe(gulp.dest("src/thirdparty"));
});

gulp.task("copy-thirdparty-acorn", function () {
return gulp.src(
"dist/{,*/}*",
{
cwd: "src/node_modules/acorn"
}
)
return gulp
.src("dist/{,*/}*", {
cwd: "src/node_modules/acorn",
})
.pipe(gulp.dest("src/thirdparty/acorn"));
});

gulp.task("copy-thirdparty-immutable", function () {
return gulp.src(
"dist/immutable.js",
{
cwd: "src/node_modules/immutable"
}
)
return gulp
.src("dist/immutable.js", {
cwd: "src/node_modules/immutable",
})
.pipe(gulp.dest("src/thirdparty"));
});

gulp.task("copy-thirdparty-react", function () {
return gulp.src(
"umd/react.development.js",
{
cwd: "src/node_modules/react"
}
)
.pipe(rename(function (path) {
path.basename = path.basename.replace(".development", "");
}))
return gulp
.src("umd/react.development.js", {
cwd: "src/node_modules/react",
})
.pipe(
rename(function (path) {
path.basename = path.basename.replace(".development", "");
})
)
.pipe(gulp.dest("src/thirdparty"));
});

gulp.task("copy-thirdparty-react-dom", function () {
return gulp.src(
[
"umd/react-dom.development.js",
"umd/react-dom-test-utils.development.js"
],
{
cwd: "src/node_modules/react-dom"
}
)
.pipe(rename(function (path) {
path.basename = path.basename.replace(".development", "");
}))
return gulp
.src(["umd/react-dom.development.js", "umd/react-dom-test-utils.development.js"], {
cwd: "src/node_modules/react-dom",
})
.pipe(
rename(function (path) {
path.basename = path.basename.replace(".development", "");
})
)
.pipe(gulp.dest("src/thirdparty"));
});

gulp.task("copy-thirdparty-create-react-class", function () {
return gulp.src(
"create-react-class.js",
{
cwd: "src/node_modules/create-react-class"
}
)
return gulp
.src("create-react-class.js", {
cwd: "src/node_modules/create-react-class",
})
.pipe(gulp.dest("src/thirdparty"));
});

gulp.task("copy-thirdparty-codemirror-addon-toggle-comment", function () {
return gulp.src(
[
"dist/toggle-comment-simple.js",
"dist/toggle-comment-simple.min.js",
"dist/toggle-comment-simple.js.map"
],
{
cwd: "src/node_modules/codemirror-addon-toggle-comment"
}
)
return gulp
.src(
[
"dist/toggle-comment-simple.js",
"dist/toggle-comment-simple.min.js",
"dist/toggle-comment-simple.js.map",
],
{
cwd: "src/node_modules/codemirror-addon-toggle-comment",
}
)
.pipe(gulp.dest("src/thirdparty/codemirror-addon-toggle-comment"));
});


gulp.task("copy-thirdparty", gulp.parallel(
"copy-thirdparty-codemirror",
"copy-thirdparty-less",
"copy-thirdparty-acorn",
"copy-thirdparty-immutable",
"copy-thirdparty-react",
"copy-thirdparty-react-dom",
"copy-thirdparty-create-react-class",
"copy-thirdparty-codemirror-addon-toggle-comment"
));
gulp.task(
"copy-thirdparty",
gulp.parallel(
"copy-thirdparty-codemirror",
"copy-thirdparty-less",
"copy-thirdparty-acorn",
"copy-thirdparty-immutable",
"copy-thirdparty-react",
"copy-thirdparty-react-dom",
"copy-thirdparty-create-react-class",
"copy-thirdparty-codemirror-addon-toggle-comment"
)
);
98 changes: 55 additions & 43 deletions tasks/download-default-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const gulp = require("gulp");
const log = require("fancy-log");
const PluginError = require("plugin-error");
const file = require("./lib/file");
const exec = require("child_process").exec;
const fs = require("fs-extra");
const https = require("https");
const path = require("path");
const tar = require("tar");
const temp = require("temp");
const zlib = require("zlib");
const file = require("./lib/file");
const exec = require("child_process").exec;
const fs = require("fs-extra");
const https = require("https");
const path = require("path");
const tar = require("tar");
const temp = require("temp");
const zlib = require("zlib");

temp.track();

Expand Down Expand Up @@ -38,26 +38,26 @@ function getTempDirectory(tempName) {
function downloadUrlToFolder(url, dirPath) {
return new Promise(function (resolve, reject) {
log.info(url + " downloading...");
https.get(url, function (res) {

if (res.statusCode !== 200) {
return reject(new Error("Request failed: " + res.statusCode));
}
https
.get(url, function (res) {
if (res.statusCode !== 200) {
return reject(new Error("Request failed: " + res.statusCode));
}

const unzipStream = zlib.createGunzip();
res.pipe(unzipStream);
const unzipStream = zlib.createGunzip();
res.pipe(unzipStream);

const extractStream = tar.extract({ cwd: dirPath, strip: 0 });
unzipStream.pipe(extractStream);
const extractStream = tar.extract({ cwd: dirPath, strip: 0 });
unzipStream.pipe(extractStream);

extractStream.on("finish", function () {
log.info(url + " successfully downloaded");
resolve(path.resolve(dirPath, "package"));
extractStream.on("finish", function () {
log.info(url + " successfully downloaded");
resolve(path.resolve(dirPath, "package"));
});
})
.on("error", function (err) {
reject(err);
});

}).on("error", function (err) {
reject(err);
});
});
}

Expand Down Expand Up @@ -91,32 +91,44 @@ function downloadAndInstallExtensionFromNpm(obj) {
return downloadUrlToFolder(data.urlToDownload, data.tempDirPath);
})
.then(function (extensionPath) {
const target = path.resolve(__dirname, "..", "src", "extensions", "default", extensionName);
const target = path.resolve(
__dirname,
"..",
"src",
"extensions",
"default",
extensionName
);
return move(extensionPath, target);
});
}

function downloadDefaultExtensions(cb) {
const packageJSON = file.readJSON("package.json");
const extensionsToDownload = Object
.keys(packageJSON.defaultExtensions)
.map(function (name) {
return {
name: name,
version: packageJSON.defaultExtensions[name]
};
});

Promise.all(extensionsToDownload.map(function (extension) {
return downloadAndInstallExtensionFromNpm(extension);
})).then(function () {
return cb();
}).catch(function (err) {
log.error(err);
const errPlugin = new PluginError("npm-download-default-extensions", err, { showStack: true });
cb(errPlugin);
const extensionsToDownload = Object.keys(packageJSON.defaultExtensions).map(function (name) {
return {
name: name,
version: packageJSON.defaultExtensions[name],
};
});

Promise.all(
extensionsToDownload.map(function (extension) {
return downloadAndInstallExtensionFromNpm(extension);
})
)
.then(function () {
return cb();
})
.catch(function (err) {
log.error(err);
const errPlugin = new PluginError("npm-download-default-extensions", err, {
showStack: true,
});
cb(errPlugin);
});
}
downloadDefaultExtensions.description = "Downloads extensions from npm and puts them to the src/extensions/default folder";
downloadDefaultExtensions.description =
"Downloads extensions from npm and puts them to the src/extensions/default folder";

gulp.task("npm-download-default-extensions", downloadDefaultExtensions);
33 changes: 12 additions & 21 deletions tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const gulp = require("gulp");
const eslint = require("gulp-eslint-new");

const meta = {
app: [
"app/**/*.js",
"app/**/*.ts"
],
app: ["app/**/*.js", "app/**/*.ts"],
src: [
"src/**/*.js",
"src/**/*.ts",
Expand All @@ -27,7 +24,7 @@ const meta = {
"!src/extensions/disabled/**",
"!**/node_modules/**",
"!src/**/*-min.js",
"!src/**/*.min.js"
"!src/**/*.min.js",
],
test: [
"test/**/*.js",
Expand All @@ -41,23 +38,22 @@ const meta = {
"!test/thirdparty/**",
"!test/**/node_modules/**/*.js",
"test/spec/LanguageTools-test-files/**/*.js",
"test/spec/LanguageTools-test-files/**/*.ts"
"test/spec/LanguageTools-test-files/**/*.ts",
],
build: [
"gulpfile.js",
"tasks/**/*.js",
"tasks/**/*.ts"
]
build: ["gulpfile.js", "tasks/**/*.js", "tasks/**/*.ts"],
};
exports.meta = meta;

function eslintTask(files) {
// To automatically fix issues add `fix: true` to the eslint options and
// `.pipe(gulp.dest("./"));` at the end of the pipe.
return gulp.src(files, { base: "." })
.pipe(eslint({
quiet: true
}))
return gulp
.src(files, { base: "." })
.pipe(
eslint({
quiet: true,
})
)
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
Expand All @@ -78,9 +74,4 @@ gulp.task("eslint:build", () => {
return eslintTask(meta.build);
});

gulp.task("eslint", gulp.parallel(
"eslint:build",
"eslint:app",
"eslint:src",
"eslint:test"
));
gulp.task("eslint", gulp.parallel("eslint:build", "eslint:app", "eslint:src", "eslint:test"));
2 changes: 1 addition & 1 deletion tasks/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getGlobs() {
...meta.app,
// ...meta.src,
// ...meta.test,
// ...meta.build,
...meta.build,
];
return globs;
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ function writeJSON(pathJson, obj) {
file.write(pathJson, content);
}

exports.writeJSON = writeJSON;
exports.resolve = resolve;
exports.writeJSON = writeJSON;
exports.resolve = resolve;
Loading
Loading