as commonjs
This commit is contained in:
37
lib/main.js
37
lib/main.js
@@ -1,13 +1,18 @@
|
||||
import { build } from 'esbuild';
|
||||
import { lstatSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from 'fs';
|
||||
import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths';
|
||||
import readMeta from './readmeta';
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const esbuild_1 = require("esbuild");
|
||||
const fs_1 = require("fs");
|
||||
const paths_1 = require("./paths");
|
||||
const readmeta_1 = __importDefault(require("./readmeta"));
|
||||
async function compileProject(name) {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = readMeta(name);
|
||||
let outPath = DistPath(name);
|
||||
await build({
|
||||
entryPoints: [ScriptPath(name).main],
|
||||
let [metaJson, metaString] = readmeta_1.default(name);
|
||||
let outPath = paths_1.DistPath(name);
|
||||
await esbuild_1.build({
|
||||
entryPoints: [paths_1.ScriptPath(name).main],
|
||||
outfile: outPath,
|
||||
target: 'esnext',
|
||||
platform: 'node',
|
||||
@@ -24,21 +29,21 @@ async function compileProject(name) {
|
||||
},
|
||||
});
|
||||
//add UserScript header
|
||||
let content = readFileSync(outPath).toString();
|
||||
writeFileSync(outPath, metaString + content);
|
||||
let content = fs_1.readFileSync(outPath).toString();
|
||||
fs_1.writeFileSync(outPath, metaString + content);
|
||||
}
|
||||
if (!lstatSync('package.json').isFile()) {
|
||||
if (!fs_1.lstatSync('package.json').isFile()) {
|
||||
console.error('package.json not found, unwilling to run');
|
||||
process.exit(1);
|
||||
}
|
||||
//delete compiled scripts
|
||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`));
|
||||
fs_1.readdirSync(paths_1.DistBase).forEach(file => fs_1.unlinkSync(`${paths_1.DistBase}/${file}`));
|
||||
//compile scripts
|
||||
readdirSync(ScriptBase).forEach(name => {
|
||||
let path = ScriptPath(name);
|
||||
fs_1.readdirSync(paths_1.ScriptBase).forEach(name => {
|
||||
let path = paths_1.ScriptPath(name);
|
||||
if (!name.endsWith('_') &&
|
||||
lstatSync(path.dir).isDirectory() &&
|
||||
lstatSync(path.main).isFile()) {
|
||||
fs_1.lstatSync(path.dir).isDirectory() &&
|
||||
fs_1.lstatSync(path.main).isFile()) {
|
||||
compileProject(name);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user