@es-pkg/publish 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +253 -0
- package/esm/index.d.ts +3 -0
- package/{src/index.ts → esm/index.js} +238 -242
- package/esm/type.d.ts +46 -0
- package/package.json +6 -4
- /package/{src → cjs}/type.d.ts +0 -0
package/README.md
CHANGED
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
|
|
30
30
|
#### default
|
|
31
31
|
|
|
32
|
-
* default(done:`Undertaker.TaskCallback`): `void` | `EventEmitter`<`DefaultEventMap`\> | `internal.Stream` | `"child_process".ChildProcess` | `asyncDone.Observable`<`any`\>
|
|
32
|
+
* default(done:`Undertaker.TaskCallback`): `void` | `EventEmitter`<`DefaultEventMap`\> | `internal.Stream` | `PromiseLike`<`any`\> | `"child_process".ChildProcess` | `asyncDone.Observable`<`any`\>
|
package/cjs/index.d.ts
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_gulp = __toESM(require("@es-pkg/gulp"));
|
|
36
|
+
var import_chalk = __toESM(require("chalk"));
|
|
37
|
+
var import_gulp_logger = __toESM(require("@es-pkg/gulp-logger"));
|
|
38
|
+
var import_fs = __toESM(require("fs"));
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_utils = require("@es-pkg/utils");
|
|
41
|
+
var import_config = require("@es-pkg/config");
|
|
42
|
+
var import_prompts = __toESM(require("prompts"));
|
|
43
|
+
const scoped = /^@[a-zA-Z0-9-]+\/.+$/;
|
|
44
|
+
const REGISTRY = import_config.config.publishRegistry;
|
|
45
|
+
const json = import_config.pkg;
|
|
46
|
+
const publishDir = import_path.default.join(import_config.config.publishDir, "./__npm__");
|
|
47
|
+
import_gulp.default.task("clean", async () => {
|
|
48
|
+
(0, import_utils.log)(`\u6E05\u9664${publishDir}\u5F00\u59CB`);
|
|
49
|
+
try {
|
|
50
|
+
await (0, import_utils.remove)(publishDir);
|
|
51
|
+
(0, import_utils.log)(`\u6E05\u9664${publishDir}\u5B8C\u6210`);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
(0, import_utils.log)(`\u6E05\u9664${publishDir}\u5931\u8D25\uFF1A`, e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
import_gulp.default.task("del-cjs-iife-es", async () => {
|
|
57
|
+
if (import_config.config.iife) {
|
|
58
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.iife)} \u5F00\u59CB`);
|
|
59
|
+
await (0, import_utils.remove)(`${import_path.default.join(`${publishDir}`, import_config.config.iife)}`);
|
|
60
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.iife)} \u7ED3\u675F`);
|
|
61
|
+
}
|
|
62
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.cjs)} \u5F00\u59CB`);
|
|
63
|
+
await (0, import_utils.remove)(`${import_path.default.join(`${publishDir}`, import_config.config.cjs)}`);
|
|
64
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.cjs)} \u7ED3\u675F`);
|
|
65
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.es)} \u5F00\u59CB`);
|
|
66
|
+
await (0, import_utils.remove)(`${import_path.default.join(`${publishDir}`, import_config.config.es)}`);
|
|
67
|
+
(0, import_utils.log)(`\u5220\u9664 ${import_path.default.join(`${publishDir}`, import_config.config.es)} \u7ED3\u675F`);
|
|
68
|
+
});
|
|
69
|
+
import_gulp.default.task("copy-info", (0, import_gulp.series)(async () => {
|
|
70
|
+
(0, import_utils.log)(`\u751F\u6210 package \u5F00\u59CB`);
|
|
71
|
+
let errored = false;
|
|
72
|
+
let version = "";
|
|
73
|
+
try {
|
|
74
|
+
const { stdout } = await (0, import_utils.run)(`npm`, ["view", import_config.pkg.name, "version"], {
|
|
75
|
+
stdio: void 0,
|
|
76
|
+
cwd: import_path.default.join(process.cwd(), import_config.config.publishDir)
|
|
77
|
+
});
|
|
78
|
+
if (stdout) {
|
|
79
|
+
version = stdout;
|
|
80
|
+
}
|
|
81
|
+
if (!version) {
|
|
82
|
+
const controller = new AbortController();
|
|
83
|
+
const timer = setTimeout(() => {
|
|
84
|
+
controller.abort();
|
|
85
|
+
}, 3e3);
|
|
86
|
+
const start = Date.now();
|
|
87
|
+
const url = `https://img.shields.io/npm/v/${import_config.pkg.name}`;
|
|
88
|
+
const response = await (0, import_utils.fetch)(url, {
|
|
89
|
+
signal: controller.signal
|
|
90
|
+
}).finally(async () => {
|
|
91
|
+
import_utils.log.warn(`\u8FDC\u7A0B\u83B7\u53D6\u7248\u672C\u82B1\u8D39\u65F6\u95F4:${Date.now() - start}`);
|
|
92
|
+
});
|
|
93
|
+
const htmlString = await response.text();
|
|
94
|
+
const regex = /<title>npm: v([\d.]+)<\/title>/;
|
|
95
|
+
version = htmlString.match(regex)?.[1];
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
(0, import_utils.log)(`\u8FDC\u7A0B\u83B7\u53D6\u7248\u672C\u4FE1\u606F tag:`, version);
|
|
99
|
+
if (version) {
|
|
100
|
+
json.version = (0, import_utils.compare)(import_config.pkg.version, version) <= 0 ? (0, import_utils.autoUpgrade)(version) : import_config.pkg.version;
|
|
101
|
+
} else {
|
|
102
|
+
errored = true;
|
|
103
|
+
}
|
|
104
|
+
} catch (e) {
|
|
105
|
+
errored = true;
|
|
106
|
+
}
|
|
107
|
+
if (errored) {
|
|
108
|
+
const { version: version2 } = await (0, import_prompts.default)({
|
|
109
|
+
type: "text",
|
|
110
|
+
name: "version",
|
|
111
|
+
message: "\u8FDC\u7A0B\u83B7\u53D6\u7248\u672C\u5931\u8D25\uFF01\u8BF7\u8F93\u5165\u7248\u672C\u53F7",
|
|
112
|
+
initial: import_config.pkg.version
|
|
113
|
+
});
|
|
114
|
+
json.version = version2;
|
|
115
|
+
}
|
|
116
|
+
delete json.devDependencies;
|
|
117
|
+
delete json.scripts;
|
|
118
|
+
if (!json.publishConfig) {
|
|
119
|
+
json.publishConfig = {
|
|
120
|
+
access: "public",
|
|
121
|
+
registry: REGISTRY
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const es = import_path.default.basename(import_config.config.es);
|
|
125
|
+
const cjs = import_path.default.basename(import_config.config.cjs);
|
|
126
|
+
const iife = import_config.config.iife ? import_path.default.basename(import_config.config.iife) : "";
|
|
127
|
+
const CJSExists = import_fs.default.existsSync(import_path.default.join(`${import_config.config.publishDir}`, cjs));
|
|
128
|
+
const ESExists = import_fs.default.existsSync(import_path.default.join(`${import_config.config.publishDir}`, es));
|
|
129
|
+
const IIFEExists = iife ? import_fs.default.existsSync(import_path.default.join(`${import_config.config.publishDir}`, iife)) : false;
|
|
130
|
+
const mainExists = !!json.main && import_fs.default.existsSync(import_path.default.join((0, import_config.resolveApp)(""), json.main));
|
|
131
|
+
const browserExists = !!json.browser && import_fs.default.existsSync(import_path.default.join((0, import_config.resolveApp)(""), json.main));
|
|
132
|
+
const moduleExists = !!json.module && import_fs.default.existsSync(import_path.default.join((0, import_config.resolveApp)(""), json.main));
|
|
133
|
+
const _es = (0, import_config.getEntrypoint)(import_config.config.es);
|
|
134
|
+
const _cjs = (0, import_config.getEntrypoint)(import_config.config.cjs);
|
|
135
|
+
if (!mainExists) {
|
|
136
|
+
if (ESExists) {
|
|
137
|
+
json.main = _es || _cjs;
|
|
138
|
+
}
|
|
139
|
+
if (CJSExists) {
|
|
140
|
+
json.main = _cjs || _es;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!moduleExists && CJSExists) {
|
|
144
|
+
json.module = _es || _cjs;
|
|
145
|
+
}
|
|
146
|
+
if (!browserExists && IIFEExists) {
|
|
147
|
+
json.browser = (0, import_config.getEntrypoint)(import_config.config.iife);
|
|
148
|
+
}
|
|
149
|
+
if (!json.types) {
|
|
150
|
+
const type = (0, import_config.getEntrypoint)(import_config.config.es, import_config.config.typings) || _es || _cjs;
|
|
151
|
+
const { dir, name, ext } = import_path.default.parse(type);
|
|
152
|
+
json.types = [".ts", ".tsx"].includes(ext) ? type : `${dir}/${name}.d.ts`;
|
|
153
|
+
}
|
|
154
|
+
json.files = Array.from(/* @__PURE__ */ new Set([ESExists && es, CJSExists && cjs, IIFEExists && iife])).filter(Boolean);
|
|
155
|
+
json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(([key, value]) => {
|
|
156
|
+
if (value.startsWith("file://") || value.startsWith("workspace:")) {
|
|
157
|
+
return [key, "latest"];
|
|
158
|
+
}
|
|
159
|
+
return [key, value];
|
|
160
|
+
}));
|
|
161
|
+
let jsonStr = JSON.stringify(json, null, " ");
|
|
162
|
+
const ex = import_fs.default.existsSync(`${import_config.config.publishDir}/`);
|
|
163
|
+
if (!ex) {
|
|
164
|
+
import_fs.default.mkdirSync(`${import_config.config.publishDir}/`, { recursive: true });
|
|
165
|
+
}
|
|
166
|
+
import_fs.default.writeFileSync(`${import_config.config.publishDir}/package.json`, jsonStr);
|
|
167
|
+
(0, import_utils.log)(`\u751F\u6210 package\u5B8C\u6210`, import_chalk.default.green(json.version));
|
|
168
|
+
(0, import_utils.log)(`\u751F\u6210 .npmrc \u5F00\u59CB`);
|
|
169
|
+
import_fs.default.writeFileSync(`${import_config.config.publishDir}/.npmrc`, `registry=${REGISTRY}`);
|
|
170
|
+
(0, import_utils.log)(`\u751F\u6210 .npmrc \u5B8C\u6210`);
|
|
171
|
+
(0, import_utils.log)(`\u62F7\u8D1D README \u5F00\u59CB`);
|
|
172
|
+
}, () => {
|
|
173
|
+
return import_gulp.default.src([`./README.md`]).pipe((0, import_gulp_logger.default)({
|
|
174
|
+
before: "copy README...",
|
|
175
|
+
after: "copy README complete!",
|
|
176
|
+
showChange: false
|
|
177
|
+
})).pipe(import_gulp.default.dest(`${import_config.config.publishDir}/`));
|
|
178
|
+
}));
|
|
179
|
+
import_gulp.default.task("copy-iife", (c) => {
|
|
180
|
+
if (!import_config.config.iife) {
|
|
181
|
+
return c();
|
|
182
|
+
}
|
|
183
|
+
(0, import_utils.log)(`\u62F7\u8D1D '/iife/**' \u5F00\u59CB`);
|
|
184
|
+
return import_gulp.default.src([`${import_config.config.iife}/.**`, `${import_config.config.iife}/**`]).pipe((0, import_gulp_logger.default)({
|
|
185
|
+
before: "copy iife...",
|
|
186
|
+
after: "copy iife complete!",
|
|
187
|
+
showChange: false
|
|
188
|
+
})).pipe(import_gulp.default.dest(import_path.default.join(`${publishDir}`, import_path.default.basename(import_config.config.iife))));
|
|
189
|
+
});
|
|
190
|
+
import_gulp.default.task("copy-cjs", () => {
|
|
191
|
+
return import_gulp.default.src([`${import_config.config.cjs}/.**`, `${import_config.config.cjs}/**`]).pipe((0, import_gulp_logger.default)({
|
|
192
|
+
before: "copy cjs...",
|
|
193
|
+
after: "copy cjs complete!",
|
|
194
|
+
showChange: false
|
|
195
|
+
})).pipe(import_gulp.default.dest(import_path.default.join(`${publishDir}`, import_path.default.basename(import_config.config.cjs))));
|
|
196
|
+
});
|
|
197
|
+
import_gulp.default.task("copy-es", () => {
|
|
198
|
+
return import_gulp.default.src([`${import_config.config.es}/.**`, `${import_config.config.es}/**`]).pipe((0, import_gulp_logger.default)({
|
|
199
|
+
before: "copy es...",
|
|
200
|
+
after: "copy es complete!",
|
|
201
|
+
showChange: false
|
|
202
|
+
})).pipe(import_gulp.default.dest(import_path.default.join(`${publishDir}`, import_path.default.basename(import_config.config.es))));
|
|
203
|
+
});
|
|
204
|
+
import_gulp.default.task("remove-__npm__", (0, import_gulp.series)(() => {
|
|
205
|
+
let promises = [];
|
|
206
|
+
const includes = [import_config.config.es, import_config.config.cjs, import_config.config.iife].flatMap((val) => {
|
|
207
|
+
if (!val) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
const some = (0, import_config.getIncludeFiles)().some((item) => import_path.default.resolve(val).startsWith(import_path.default.resolve(item.path)));
|
|
211
|
+
return some ? [] : [val];
|
|
212
|
+
});
|
|
213
|
+
promises = includes.map((item) => (0, import_utils.remove)(item));
|
|
214
|
+
return Promise.all(promises);
|
|
215
|
+
}, () => {
|
|
216
|
+
return import_gulp.default.src([`${publishDir}/**`, `${publishDir}/.**`]).pipe((0, import_gulp_logger.default)({
|
|
217
|
+
before: "copy __npm__...",
|
|
218
|
+
after: "copy __npm__ complete!",
|
|
219
|
+
showChange: false
|
|
220
|
+
})).pipe(import_gulp.default.dest(`${import_config.config.publishDir}/`));
|
|
221
|
+
}, async () => {
|
|
222
|
+
await (0, import_utils.remove)(publishDir);
|
|
223
|
+
}));
|
|
224
|
+
import_gulp.default.task("npm-publish", async function() {
|
|
225
|
+
let publishAccess = [];
|
|
226
|
+
if (scoped.test(import_config.pkg.name)) {
|
|
227
|
+
publishAccess = ["--access", "public"];
|
|
228
|
+
}
|
|
229
|
+
if (import_config.config.publishAccess) {
|
|
230
|
+
publishAccess = import_config.config.publishAccess;
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
const { stdout } = await (0, import_utils.run)(`npm`, ["whoami", "--registry", REGISTRY], { stdio: void 0 });
|
|
234
|
+
import_utils.log.warn(`===npm\u767B\u5F55\u4FE1\u606F===>${stdout}`);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
import_utils.log.warn(`===npm${REGISTRY}\u672A\u767B\u5F55\uFF01\uFF01\u8BF7\u767B\u5F55`);
|
|
237
|
+
await (0, import_utils.run)(`npm`, ["login", "--registry", REGISTRY]);
|
|
238
|
+
}
|
|
239
|
+
const { confirm } = await (0, import_prompts.default)({
|
|
240
|
+
type: "confirm",
|
|
241
|
+
name: "confirm",
|
|
242
|
+
message: "\u662F\u5426\u53D1\u5E03\uFF1F"
|
|
243
|
+
});
|
|
244
|
+
if (confirm) {
|
|
245
|
+
await (0, import_utils.run)(`npm`, ["publish", ...publishAccess, "--registry", REGISTRY], {
|
|
246
|
+
cwd: import_path.default.join(process.cwd(), import_config.config.publishDir)
|
|
247
|
+
});
|
|
248
|
+
(0, import_utils.success)(`${json.name}@${json.version}:\u53D1\u5E03\u6210\u529F\uFF01`);
|
|
249
|
+
} else {
|
|
250
|
+
(0, import_utils.error)(`${json.name}@${json.version}:\u53D6\u6D88\u6210\u529F\uFF01`);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
var src_default = import_gulp.default.series("clean", "del-cjs-iife-es", "copy-cjs", "copy-es", "copy-iife", "remove-__npm__", "copy-info", "npm-publish");
|
package/esm/index.d.ts
ADDED
|
@@ -1,242 +1,238 @@
|
|
|
1
|
-
import gulp, {series} from '@es-pkg/gulp'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import logger from '@es-pkg/gulp-logger'
|
|
4
|
-
import fs from
|
|
5
|
-
import path from
|
|
6
|
-
import {
|
|
7
|
-
import {config,
|
|
8
|
-
import prompts from
|
|
9
|
-
|
|
10
|
-
const scoped = /^@[a-zA-Z0-9-]+\/.+$/;
|
|
11
|
-
const REGISTRY = config.publishRegistry
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
log(`清除${publishDir}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
log(`删除 ${path.join(`${publishDir}`, config.
|
|
34
|
-
|
|
35
|
-
log(`删除 ${path.join(`${publishDir}`, config.es)}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.pipe(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
export default gulp.series('clean', 'del-cjs-iife-es', 'copy-cjs', 'copy-es', 'copy-iife', 'remove-__npm__', 'copy-info', 'npm-publish')
|
|
1
|
+
import gulp, { series } from '@es-pkg/gulp';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import logger from '@es-pkg/gulp-logger';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { log, remove, run, fetch, autoUpgrade, compare, success, error } from '@es-pkg/utils';
|
|
7
|
+
import { config, pkg, resolveApp, getEntrypoint, getIncludeFiles } from '@es-pkg/config';
|
|
8
|
+
import prompts from 'prompts';
|
|
9
|
+
|
|
10
|
+
const scoped = /^@[a-zA-Z0-9-]+\/.+$/;
|
|
11
|
+
const REGISTRY = config.publishRegistry;
|
|
12
|
+
const json = pkg;
|
|
13
|
+
const publishDir = path.join(config.publishDir, './__npm__');
|
|
14
|
+
gulp.task('clean', async () => {
|
|
15
|
+
log(`清除${publishDir}开始`);
|
|
16
|
+
try {
|
|
17
|
+
await remove(publishDir);
|
|
18
|
+
log(`清除${publishDir}完成`);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
log(`清除${publishDir}失败:`, e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
gulp.task('del-cjs-iife-es', async () => {
|
|
25
|
+
if (config.iife) {
|
|
26
|
+
log(`删除 ${path.join(`${publishDir}`, config.iife)} 开始`);
|
|
27
|
+
await remove(`${path.join(`${publishDir}`, config.iife)}`);
|
|
28
|
+
log(`删除 ${path.join(`${publishDir}`, config.iife)} 结束`);
|
|
29
|
+
}
|
|
30
|
+
log(`删除 ${path.join(`${publishDir}`, config.cjs)} 开始`);
|
|
31
|
+
await remove(`${path.join(`${publishDir}`, config.cjs)}`);
|
|
32
|
+
log(`删除 ${path.join(`${publishDir}`, config.cjs)} 结束`);
|
|
33
|
+
log(`删除 ${path.join(`${publishDir}`, config.es)} 开始`);
|
|
34
|
+
await remove(`${path.join(`${publishDir}`, config.es)}`);
|
|
35
|
+
log(`删除 ${path.join(`${publishDir}`, config.es)} 结束`);
|
|
36
|
+
});
|
|
37
|
+
gulp.task('copy-info', series(async () => {
|
|
38
|
+
log(`生成 package 开始`);
|
|
39
|
+
let errored = false;
|
|
40
|
+
let version = "";
|
|
41
|
+
try {
|
|
42
|
+
const { stdout } = await run(`npm`, ['view', pkg.name, 'version'], {
|
|
43
|
+
stdio: undefined,
|
|
44
|
+
cwd: path.join(process.cwd(), config.publishDir),
|
|
45
|
+
});
|
|
46
|
+
if (stdout) {
|
|
47
|
+
version = stdout;
|
|
48
|
+
}
|
|
49
|
+
if (!version) {
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
const timer = setTimeout(() => {
|
|
52
|
+
controller.abort();
|
|
53
|
+
}, 3000);
|
|
54
|
+
const start = Date.now();
|
|
55
|
+
const url = `https://img.shields.io/npm/v/${pkg.name}`;
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
signal: controller.signal
|
|
58
|
+
}).finally(async () => {
|
|
59
|
+
log.warn(`远程获取版本花费时间:${Date.now() - start}`);
|
|
60
|
+
});
|
|
61
|
+
const htmlString = await response.text();
|
|
62
|
+
const regex = /<title>npm: v([\d.]+)<\/title>/;
|
|
63
|
+
version = htmlString.match(regex)?.[1];
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
}
|
|
66
|
+
log(`远程获取版本信息 tag:`, version);
|
|
67
|
+
if (version) {
|
|
68
|
+
json.version = compare(pkg.version, version) <= 0 ? autoUpgrade(version) : pkg.version;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
errored = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
errored = true;
|
|
76
|
+
}
|
|
77
|
+
if (errored) {
|
|
78
|
+
const { version } = await prompts({
|
|
79
|
+
type: 'text',
|
|
80
|
+
name: 'version',
|
|
81
|
+
message: '远程获取版本失败!请输入版本号',
|
|
82
|
+
initial: pkg.version
|
|
83
|
+
});
|
|
84
|
+
json.version = version;
|
|
85
|
+
}
|
|
86
|
+
delete json.devDependencies;
|
|
87
|
+
delete json.scripts;
|
|
88
|
+
if (!json.publishConfig) {
|
|
89
|
+
json.publishConfig = {
|
|
90
|
+
access: "public",
|
|
91
|
+
registry: REGISTRY
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const es = path.basename(config.es);
|
|
95
|
+
const cjs = path.basename(config.cjs);
|
|
96
|
+
const iife = config.iife ? path.basename(config.iife) : "";
|
|
97
|
+
const CJSExists = fs.existsSync(path.join(`${config.publishDir}`, cjs));
|
|
98
|
+
const ESExists = fs.existsSync(path.join(`${config.publishDir}`, es));
|
|
99
|
+
const IIFEExists = iife ? fs.existsSync(path.join(`${config.publishDir}`, iife)) : false;
|
|
100
|
+
const mainExists = !!json.main && fs.existsSync(path.join(resolveApp(''), json.main));
|
|
101
|
+
const browserExists = !!json.browser && fs.existsSync(path.join(resolveApp(''), json.main));
|
|
102
|
+
const moduleExists = !!json.module && fs.existsSync(path.join(resolveApp(''), json.main));
|
|
103
|
+
const _es = getEntrypoint(config.es);
|
|
104
|
+
const _cjs = getEntrypoint(config.cjs);
|
|
105
|
+
if (!mainExists) {
|
|
106
|
+
if (ESExists) {
|
|
107
|
+
json.main = _es || _cjs;
|
|
108
|
+
}
|
|
109
|
+
if (CJSExists) {
|
|
110
|
+
json.main = _cjs || _es;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!moduleExists && CJSExists) {
|
|
114
|
+
json.module = _es || _cjs;
|
|
115
|
+
}
|
|
116
|
+
if (!browserExists && IIFEExists) {
|
|
117
|
+
json.browser = getEntrypoint(config.iife);
|
|
118
|
+
}
|
|
119
|
+
if (!json.types) {
|
|
120
|
+
const type = getEntrypoint(config.es, config.typings) || _es || _cjs;
|
|
121
|
+
const { dir, name, ext } = path.parse(type);
|
|
122
|
+
json.types = ['.ts', '.tsx'].includes(ext) ? type : `${dir}/${name}.d.ts`;
|
|
123
|
+
}
|
|
124
|
+
json.files = Array.from(new Set([ESExists && es, CJSExists && cjs, IIFEExists && iife])).filter(Boolean);
|
|
125
|
+
json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(([key, value]) => {
|
|
126
|
+
if (value.startsWith('file://') || value.startsWith('workspace:')) {
|
|
127
|
+
return [key, 'latest'];
|
|
128
|
+
}
|
|
129
|
+
return [key, value];
|
|
130
|
+
}));
|
|
131
|
+
let jsonStr = JSON.stringify(json, null, "\t");
|
|
132
|
+
const ex = fs.existsSync(`${config.publishDir}/`);
|
|
133
|
+
if (!ex) {
|
|
134
|
+
fs.mkdirSync(`${config.publishDir}/`, { recursive: true });
|
|
135
|
+
}
|
|
136
|
+
fs.writeFileSync(`${config.publishDir}/package.json`, jsonStr);
|
|
137
|
+
log(`生成 package完成`, chalk.green(json.version));
|
|
138
|
+
log(`生成 .npmrc 开始`);
|
|
139
|
+
fs.writeFileSync(`${config.publishDir}/.npmrc`, `registry=${REGISTRY}`);
|
|
140
|
+
log(`生成 .npmrc 完成`);
|
|
141
|
+
log(`拷贝 README 开始`);
|
|
142
|
+
}, () => {
|
|
143
|
+
return gulp.src([`./README.md`])
|
|
144
|
+
.pipe(logger({
|
|
145
|
+
before: 'copy README...',
|
|
146
|
+
after: 'copy README complete!',
|
|
147
|
+
showChange: false
|
|
148
|
+
}))
|
|
149
|
+
.pipe(gulp.dest(`${config.publishDir}/`));
|
|
150
|
+
}));
|
|
151
|
+
gulp.task('copy-iife', (c) => {
|
|
152
|
+
if (!config.iife) {
|
|
153
|
+
return c();
|
|
154
|
+
}
|
|
155
|
+
log(`拷贝 '/iife/**' 开始`);
|
|
156
|
+
return gulp.src([`${config.iife}/.**`, `${config.iife}/**`])
|
|
157
|
+
.pipe(logger({
|
|
158
|
+
before: 'copy iife...',
|
|
159
|
+
after: 'copy iife complete!',
|
|
160
|
+
showChange: false
|
|
161
|
+
}))
|
|
162
|
+
.pipe(gulp.dest(path.join(`${publishDir}`, path.basename(config.iife))));
|
|
163
|
+
});
|
|
164
|
+
gulp.task('copy-cjs', () => {
|
|
165
|
+
return gulp.src([`${config.cjs}/.**`, `${config.cjs}/**`])
|
|
166
|
+
.pipe(logger({
|
|
167
|
+
before: 'copy cjs...',
|
|
168
|
+
after: 'copy cjs complete!',
|
|
169
|
+
showChange: false
|
|
170
|
+
}))
|
|
171
|
+
.pipe(gulp.dest(path.join(`${publishDir}`, path.basename(config.cjs))));
|
|
172
|
+
});
|
|
173
|
+
gulp.task('copy-es', () => {
|
|
174
|
+
return gulp.src([`${config.es}/.**`, `${config.es}/**`])
|
|
175
|
+
.pipe(logger({
|
|
176
|
+
before: 'copy es...',
|
|
177
|
+
after: 'copy es complete!',
|
|
178
|
+
showChange: false
|
|
179
|
+
}))
|
|
180
|
+
.pipe(gulp.dest(path.join(`${publishDir}`, path.basename(config.es))));
|
|
181
|
+
});
|
|
182
|
+
gulp.task('remove-__npm__', series(() => {
|
|
183
|
+
let promises = [];
|
|
184
|
+
const includes = [config.es, config.cjs, config.iife].flatMap(val => {
|
|
185
|
+
if (!val) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
const some = getIncludeFiles().some(item => path.resolve(val).startsWith(path.resolve(item.path)));
|
|
189
|
+
return some ? [] : [val];
|
|
190
|
+
});
|
|
191
|
+
promises = includes.map(item => remove(item));
|
|
192
|
+
return Promise.all(promises);
|
|
193
|
+
}, () => {
|
|
194
|
+
return gulp.src([`${publishDir}/**`, `${publishDir}/.**`])
|
|
195
|
+
.pipe(logger({
|
|
196
|
+
before: 'copy __npm__...',
|
|
197
|
+
after: 'copy __npm__ complete!',
|
|
198
|
+
showChange: false
|
|
199
|
+
}))
|
|
200
|
+
.pipe(gulp.dest(`${config.publishDir}/`));
|
|
201
|
+
}, async () => {
|
|
202
|
+
await remove(publishDir);
|
|
203
|
+
}));
|
|
204
|
+
gulp.task('npm-publish', async function () {
|
|
205
|
+
let publishAccess = [];
|
|
206
|
+
//公共包
|
|
207
|
+
if (scoped.test(pkg.name)) {
|
|
208
|
+
publishAccess = ["--access", "public"];
|
|
209
|
+
}
|
|
210
|
+
if (config.publishAccess) {
|
|
211
|
+
publishAccess = config.publishAccess;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const { stdout } = await run(`npm`, ["whoami", '--registry', REGISTRY], { stdio: undefined });
|
|
215
|
+
log.warn(`===npm登录信息===>${stdout}`);
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
log.warn(`===npm${REGISTRY}未登录!!请登录`);
|
|
219
|
+
await run(`npm`, ["login", '--registry', REGISTRY]);
|
|
220
|
+
}
|
|
221
|
+
const { confirm } = await prompts({
|
|
222
|
+
type: 'confirm',
|
|
223
|
+
name: 'confirm',
|
|
224
|
+
message: '是否发布?',
|
|
225
|
+
});
|
|
226
|
+
if (confirm) {
|
|
227
|
+
await run(`npm`, ['publish', ...publishAccess, '--registry', REGISTRY], {
|
|
228
|
+
cwd: path.join(process.cwd(), config.publishDir),
|
|
229
|
+
});
|
|
230
|
+
success(`${json.name}@${json.version}:发布成功!`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
error(`${json.name}@${json.version}:取消成功!`);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
var index = gulp.series('clean', 'del-cjs-iife-es', 'copy-cjs', 'copy-es', 'copy-iife', 'remove-__npm__', 'copy-info', 'npm-publish');
|
|
237
|
+
|
|
238
|
+
export { index as default };
|
package/esm/type.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
declare module "rename" {
|
|
4
|
+
export = rename;
|
|
5
|
+
|
|
6
|
+
function rename(filepath: string | rename.FileObject, transformer: rename.Transformer): rename.FilePath;
|
|
7
|
+
|
|
8
|
+
namespace rename {
|
|
9
|
+
interface FileObject {
|
|
10
|
+
// using package's terminology
|
|
11
|
+
dirname?: string | undefined;
|
|
12
|
+
basename?: string | undefined;
|
|
13
|
+
extname?: string | undefined;
|
|
14
|
+
path?: string | undefined;
|
|
15
|
+
hash?: string | undefined; // not populated by package
|
|
16
|
+
origin?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Specification {
|
|
20
|
+
dirname?: string | undefined;
|
|
21
|
+
prefix?: string | undefined;
|
|
22
|
+
basename?: string | undefined;
|
|
23
|
+
suffix?: string | undefined;
|
|
24
|
+
extname?: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type FilePath =
|
|
28
|
+
| string
|
|
29
|
+
| Specification;
|
|
30
|
+
|
|
31
|
+
type Transformer =
|
|
32
|
+
| ((spec: FileObject) => FilePath)
|
|
33
|
+
| FilePath;
|
|
34
|
+
|
|
35
|
+
interface ParsedFileObject {
|
|
36
|
+
dirname: string;
|
|
37
|
+
extname: string;
|
|
38
|
+
basename: string;
|
|
39
|
+
origin: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parse(filename: string | Partial<ParsedFileObject>): ParsedFileObject;
|
|
43
|
+
|
|
44
|
+
function stringify(obj: FileObject): string;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@es-pkg/publish",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "组件打包工具",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "cjs/index.js",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=14.6.0"
|
|
8
8
|
},
|
|
@@ -28,8 +28,10 @@
|
|
|
28
28
|
"access": "public",
|
|
29
29
|
"registry": "https://registry.npmjs.org"
|
|
30
30
|
},
|
|
31
|
-
"
|
|
31
|
+
"module": "esm/index.js",
|
|
32
|
+
"types": "esm/index.d.ts",
|
|
32
33
|
"files": [
|
|
33
|
-
"
|
|
34
|
+
"esm",
|
|
35
|
+
"cjs"
|
|
34
36
|
]
|
|
35
37
|
}
|
/package/{src → cjs}/type.d.ts
RENAMED
|
File without changes
|