Skip to content

Instantly share code, notes, and snippets.

@Chamber6821
Created July 19, 2022 12:32
Show Gist options
  • Save Chamber6821/2603eaf9c616c66207c866f3916f94e5 to your computer and use it in GitHub Desktop.
Save Chamber6821/2603eaf9c616c66207c866f3916f94e5 to your computer and use it in GitHub Desktop.
Gruntfile for screeps
const path = require("path")
module.exports = function (grunt) {
const screepsOptions = {...require("./config/screeps.json"), ...grunt.options}
grunt.loadNpmTasks("grunt-ts")
grunt.loadNpmTasks("grunt-screeps")
grunt.loadNpmTasks("grunt-contrib-copy")
grunt.loadNpmTasks("grunt-contrib-clean")
grunt.initConfig({
clean: ["dist"],
ts: {default: {tsconfig: "./tsconfig.json"}},
screeps: {options: screepsOptions, dist: ["dist/publish/*.js"]},
copy: {
default: {
files: [{
expand: true,
cwd: "dist/build/",
src: "**",
dest: "dist/publish/",
filter: "isFile",
rename: function (dest, src) {
return dest + src.replace(/[\/\\]/g, "_");
},
}],
options: {
process: function (content, srcPath) {
const buildFolder = "dist/build/" // tsc is compiled into this folder
return content.replace(/require\("(.*)"\)/gm, function (match, importPath) {
const absolutePath = path.resolve(path.dirname(srcPath), importPath)
const absoluteImportPath = path.relative(buildFolder, absolutePath)
return `require("${absoluteImportPath.replace(/[\/\\]/g, "_")}")`
})
},
},
},
},
})
grunt.registerTask("default", ["clean", "ts", "copy", "screeps"])
grunt.registerTask("pack", ["clean", "ts", "copy"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment