Skip to content

Commit

Permalink
config/* convert to es module
Browse files Browse the repository at this point in the history
  • Loading branch information
Shirtiny committed Dec 9, 2021
1 parent e6c52c1 commit 819559b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 72 deletions.
6 changes: 3 additions & 3 deletions .sh.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-26 20:47:19
* @LastEditTime: 2021-11-27 10:52:42
* @LastEditTime: 2021-12-09 15:14:12
* @Description:
*/

const camelCase = require("camelcase");
import camelCase from "camelcase";

const { MY_ENV, HOST, PORT, NODE_ENV, npm_package_version, npm_package_name } =
process.env;
Expand All @@ -28,7 +28,7 @@ const globalName =

console.log("APP globalName : ", globalName);

module.exports = {
export default {
globalName,
outputFileName: "main",
devServer: {
Expand Down
40 changes: 26 additions & 14 deletions config/builder.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-26 17:41:22
* @LastEditTime: 2021-12-09 14:54:59
* @LastEditTime: 2021-12-09 15:47:31
* @Description:
*/
const esbuild = require("esbuild");
const childProcess = require("child_process");
const path = require("path");
const { sassPlugin } = require("esbuild-sass-plugin");
const postcss = require("postcss");
const autoprefixer = require("autoprefixer");
const postcssPresetEnv = require("postcss-preset-env");
const { config, isDev } = require("./var");
const logger = require("./logger");
import esbuild from "esbuild";
import childProcess from "child_process";
import path from "path";
import { sassPlugin } from "esbuild-sass-plugin";
import postcss from "postcss";
import autoprefixer from "autoprefixer";
import postcssPresetEnv from "postcss-preset-env";
import timePlugin from "esbuild-plugin-time";
import { config, isDev } from "./var.js";
import logger from "./logger.js";

const srcDirPath = "../src";
const distDirPath = "../dist";
const __dirname = process.cwd();

const srcDirPath = "./src";
const distDirPath = "./dist";
const typesDirPath = path.resolve(__dirname, `${distDirPath}/types`);
const fileName = config.outputFileName || "main";

Expand All @@ -27,6 +30,7 @@ const createFilePath = (dirPath, fileName) => {

const buildList = [
{
name: "Bundle Browser",
entryPoints: [createFilePath(srcDirPath, "browser.ts")],
platform: "browser",
outfile: createFilePath(distDirPath, fileName + ".browser.js"),
Expand All @@ -46,6 +50,7 @@ const buildList = [
},
},
{
name: "Bundle Esm",
entryPoints: [createFilePath(srcDirPath, "es.ts")],
platform: "neutral",
outfile: createFilePath(distDirPath, fileName + ".es.js"),
Expand All @@ -65,14 +70,21 @@ const buildList = [
},
},
{
name: "Bundle Node",
entryPoints: [createFilePath(srcDirPath, "cli.ts")],
platform: "node",
outfile: createFilePath(distDirPath, fileName + ".cli.js"),
plugins: [],
},
];

const build = async ({ entryPoints = [], platform, outfile, plugins = [] }) => {
const build = async ({
name,
entryPoints = [],
platform,
outfile,
plugins = [],
}) => {
await logger.runTask({
title: `Building ${entryPoints.join("; ")}`,
successTitle: `Build ${outfile} successfully`,
Expand All @@ -88,7 +100,7 @@ const build = async ({ entryPoints = [], platform, outfile, plugins = [] }) => {
"process.env": JSON.stringify(config.env || process.env),
},
outfile,
plugins: [...plugins],
plugins: [...plugins, timePlugin(name)],
jsxFactory: config.jsxFactory,
jsxFragment: config.jsxFragment,
});
Expand Down
10 changes: 6 additions & 4 deletions config/logger.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-26 21:18:47
* @LastEditTime: 2021-12-09 14:46:47
* @LastEditTime: 2021-12-09 15:14:57
* @Description:
*/

const chalk = require("chalk");
const tasuku = require("tasuku");
import chalk from "chalk";
import tasuku from "tasuku";

const log = (...messages) => {
console.log(chalk.hex("#00b7c3")(...messages));
Expand Down Expand Up @@ -48,9 +48,11 @@ const runTask = async ({
return t.result;
};

module.exports = {
const logger = {
chan,
server,
log,
runTask,
};

export default logger;
34 changes: 18 additions & 16 deletions config/server.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-25 17:35:25
* @LastEditTime: 2021-12-09 14:46:56
* @LastEditTime: 2021-12-09 15:31:14
* @Description:
*/
"use strict";

const esbuild = require("esbuild");
const http = require("http");
const path = require("path");
const open = require("open");
const { sassPlugin } = require("esbuild-sass-plugin");
const postcss = require("postcss");
const autoprefixer = require("autoprefixer");
const postcssPresetEnv = require("postcss-preset-env");
const util = require("./util");
const { config } = require("./var");
const logger = require("./logger");

const publicDirPath = path.resolve(__dirname, "../public");
const srcDirPath = path.resolve(__dirname, "../src");
const distDirPath = path.resolve(__dirname, "../dist");
import esbuild from "esbuild";
import http from "http";
import path from "path";
import open from "open";
import { sassPlugin } from "esbuild-sass-plugin";
import postcss from "postcss";
import autoprefixer from "autoprefixer";
import postcssPresetEnv from "postcss-preset-env";
import { config } from "./var.js";
import util from "./util.js";
import logger from "./logger.js";

const __dirname = process.cwd();

const publicDirPath = path.resolve(__dirname, "./public");
const srcDirPath = path.resolve(__dirname, "./src");
const distDirPath = path.resolve(__dirname, "./dist");

const srcFileName = "index.ts";
const distFileName = "index.js";
Expand Down
10 changes: 6 additions & 4 deletions config/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-26 18:51:15
* @LastEditTime: 2021-12-09 14:47:01
* @LastEditTime: 2021-12-09 15:18:21
* @Description:
*/

const fs = require("fs");
const shell = require("shelljs");
import fs from "fs";
import shell from "shelljs";

const isPathExisted = async (path) => {
return new Promise((resolve) => {
Expand Down Expand Up @@ -35,9 +35,11 @@ const cpAllDirChildsToDir = (dirPath, targetDirPath) => {
shell.cp("-rf", `${dirPath}/*`, `${targetDirPath}/`);
};

module.exports = {
const util = {
isPathExisted,
mkdir,
rm,
cpAllDirChildsToDir,
};

export default util;
11 changes: 5 additions & 6 deletions config/var.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*
* @Author: Shirtiny
* @Date: 2021-06-26 20:17:19
* @LastEditTime: 2021-12-09 14:51:30
* @LastEditTime: 2021-12-09 15:19:55
* @Description:
*/

const config = require("../.sh");
import config from "../.sh.js";

console.log("ENV: ", config.env);

module.exports = {
config,
isDev: process.env.NODE_ENV === "development",
};
const isDev = process.env.NODE_ENV === "development";

export { config, isDev };
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@shirtiny/ts-lib-template",
"version": "1.4.15",
"description": "ts-lib-template desc",
"type": "module",
"types": "./dist/types/main.d.ts",
"main": "./dist/main.es.js",
"browser": "./dist/main.es.js",
Expand Down Expand Up @@ -60,6 +61,7 @@
"dotenv-cli": "^4.0.0",
"esbuild": "0.12.5",
"esbuild-plugin-inline-worker": "^0.1.1",
"esbuild-plugin-time": "^1.0.0",
"esbuild-sass-plugin": "^1.4.8",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
34 changes: 9 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ chalk@^2.0.0:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^4.0.0:
chalk@^4.0.0, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.npmmirror.com/chalk/download/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha1-qsTit3NKdAhnrrFr8CqtVWoeegE=
Expand Down Expand Up @@ -1589,6 +1589,13 @@ esbuild-plugin-inline-worker@^0.1.1:
esbuild latest
find-cache-dir "^3.3.1"

esbuild-plugin-time@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/esbuild-plugin-time/-/esbuild-plugin-time-1.0.0.tgz#0bac573ae8c0c7d012c39fb1a855519684d35ea0"
integrity sha512-I4Shhi0fpgXxSoc34djTHIuhbEzkcBbKKiNtb3LhZe2JEE1vSxXilW+KE0M/KZ4kqORLGgdGCKuJh9CNUL55yw==
dependencies:
chalk "^4.1.2"

esbuild-sass-plugin@^1.4.8:
version "1.8.0"
resolved "https://registry.npmmirror.com/esbuild-sass-plugin/download/esbuild-sass-plugin-1.8.0.tgz#36d00adb049735278ca2272bf2164f53a7b70e92"
Expand Down Expand Up @@ -1624,30 +1631,7 @@ [email protected]:
resolved "https://registry.npmmirror.com/esbuild/download/esbuild-0.12.5.tgz#36076a6bc1966ba2741981d30512e95e8aaff495"
integrity sha1-Ngdqa8GWa6J0GYHTBRLpXoqv9JU=

esbuild@^0.14.1:
version "0.14.2"
resolved "https://registry.npmmirror.com/esbuild/download/esbuild-0.14.2.tgz#9c1e1a652549cc33e44885eea42ea2cc6267edc2"
integrity sha512-l076A6o/PIgcyM24s0dWmDI/b8RQf41uWoJu9I0M71CtW/YSw5T5NUeXxs5lo2tFQD+O4CW4nBHJXx3OY5NpXg==
optionalDependencies:
esbuild-android-arm64 "0.14.2"
esbuild-darwin-64 "0.14.2"
esbuild-darwin-arm64 "0.14.2"
esbuild-freebsd-64 "0.14.2"
esbuild-freebsd-arm64 "0.14.2"
esbuild-linux-32 "0.14.2"
esbuild-linux-64 "0.14.2"
esbuild-linux-arm "0.14.2"
esbuild-linux-arm64 "0.14.2"
esbuild-linux-mips64le "0.14.2"
esbuild-linux-ppc64le "0.14.2"
esbuild-netbsd-64 "0.14.2"
esbuild-openbsd-64 "0.14.2"
esbuild-sunos-64 "0.14.2"
esbuild-windows-32 "0.14.2"
esbuild-windows-64 "0.14.2"
esbuild-windows-arm64 "0.14.2"

esbuild@latest:
esbuild@^0.14.1, esbuild@latest:
version "0.14.2"
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.14.2.tgz#9c1e1a652549cc33e44885eea42ea2cc6267edc2"
integrity sha512-l076A6o/PIgcyM24s0dWmDI/b8RQf41uWoJu9I0M71CtW/YSw5T5NUeXxs5lo2tFQD+O4CW4nBHJXx3OY5NpXg==
Expand Down

0 comments on commit 819559b

Please sign in to comment.