@tsparticles/cli 3.0.0 → 3.0.2
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/.github/workflows/node.js-ci.yml +8 -8
- package/dist/build/build-bundle.js +5 -44
- package/dist/build/build-circular-deps.js +4 -10
- package/dist/build/build-clear.js +4 -10
- package/dist/build/build-distfiles.js +21 -60
- package/dist/build/build-diststats.js +8 -47
- package/dist/build/build-eslint.js +7 -8
- package/dist/build/build-prettier.js +38 -47
- package/dist/build/build-tsc.js +7 -46
- package/dist/build/build.js +13 -49
- package/dist/cli.js +10 -15
- package/dist/create/create.js +9 -12
- package/dist/create/plugin/create-plugin.js +22 -28
- package/dist/create/plugin/plugin.js +12 -18
- package/dist/create/preset/create-preset.js +26 -32
- package/dist/create/preset/preset.js +12 -18
- package/dist/create/shape/create-shape.js +23 -29
- package/dist/create/shape/shape.js +12 -18
- package/dist/utils/file-utils.js +16 -25
- package/dist/utils/string-utils.js +3 -8
- package/dist/utils/template-utils.js +23 -35
- package/eslint.config.js +0 -1
- package/files/empty-project/eslint.config.js +6 -0
- package/files/empty-project/package.dist.json +1 -0
- package/files/empty-project/package.json +2 -1
- package/files/empty-project/webpack.config.js +10 -3
- package/package.json +7 -11
- package/pnpm-workspace.yaml +1 -0
- package/src/build/build-eslint.ts +3 -1
- package/src/tsconfig.json +1 -1
- package/tests/create-plugin.test.ts +4 -5
- package/tests/create-preset.test.ts +4 -5
- package/tests/create-shape.test.ts +4 -5
- package/tests/file-utils.test.ts +8 -9
- package/tests/string-utils.test.ts +24 -25
- package/tests/tsconfig.json +2 -1
- package/vitest.config.ts +11 -0
- package/files/empty-project/.eslintignore +0 -2
- package/files/empty-project/.eslintrc.js +0 -5
|
@@ -12,18 +12,18 @@ jobs:
|
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
if: ${{ github.event_name != 'pull_request' }}
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v5
|
|
16
16
|
name: Checkout [main]
|
|
17
17
|
with:
|
|
18
18
|
fetch-depth: 0
|
|
19
19
|
- uses: actions/setup-node@v4
|
|
20
20
|
with:
|
|
21
|
-
node-version: "
|
|
22
|
-
- uses: pnpm/action-setup@
|
|
21
|
+
node-version: "22"
|
|
22
|
+
- uses: pnpm/action-setup@v4
|
|
23
23
|
name: Install pnpm
|
|
24
24
|
id: pnpm-install
|
|
25
25
|
with:
|
|
26
|
-
version:
|
|
26
|
+
version: 10
|
|
27
27
|
run_install: false
|
|
28
28
|
- name: Get pnpm version
|
|
29
29
|
id: pnpm-version
|
|
@@ -49,19 +49,19 @@ jobs:
|
|
|
49
49
|
runs-on: ubuntu-latest
|
|
50
50
|
if: ${{ github.event_name == 'pull_request' }}
|
|
51
51
|
steps:
|
|
52
|
-
- uses: actions/checkout@
|
|
52
|
+
- uses: actions/checkout@v5
|
|
53
53
|
with:
|
|
54
54
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
55
55
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
56
56
|
fetch-depth: 0
|
|
57
57
|
- uses: actions/setup-node@v4
|
|
58
58
|
with:
|
|
59
|
-
node-version: "
|
|
60
|
-
- uses: pnpm/action-setup@v3
|
|
59
|
+
node-version: "22"
|
|
60
|
+
- uses: pnpm/action-setup@v3
|
|
61
61
|
name: Install pnpm
|
|
62
62
|
id: pnpm-install
|
|
63
63
|
with:
|
|
64
|
-
version:
|
|
64
|
+
version: 10
|
|
65
65
|
run_install: false
|
|
66
66
|
- name: Get pnpm version
|
|
67
67
|
id: pnpm-version
|
|
@@ -1,55 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.bundle = bundle;
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const webpack_1 = __importDefault(require("webpack"));
|
|
1
|
+
import path from "path";
|
|
2
|
+
import webpack from "webpack";
|
|
42
3
|
/**
|
|
43
4
|
* @param basePath -
|
|
44
5
|
* @returns true if the bundle was created
|
|
45
6
|
*/
|
|
46
|
-
async function bundle(basePath) {
|
|
7
|
+
export async function bundle(basePath) {
|
|
47
8
|
console.log("Bundling started");
|
|
48
9
|
let res = false;
|
|
49
10
|
try {
|
|
50
|
-
const options = (await
|
|
11
|
+
const options = (await import(path.join(basePath, "webpack.config.js")));
|
|
51
12
|
res = await new Promise((resolve, reject) => {
|
|
52
|
-
(
|
|
13
|
+
webpack(options.default, (err, stats) => {
|
|
53
14
|
if (err) {
|
|
54
15
|
console.error(err.stack ?? err);
|
|
55
16
|
reject(err);
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildCircularDeps = buildCircularDeps;
|
|
7
|
-
const madge_1 = __importDefault(require("madge"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import madge from "madge";
|
|
2
|
+
import path from "path";
|
|
9
3
|
/**
|
|
10
4
|
*
|
|
11
5
|
* @param basePath -
|
|
12
6
|
* @returns true if no circular dependencies are found, false otherwise
|
|
13
7
|
*/
|
|
14
|
-
async function buildCircularDeps(basePath) {
|
|
8
|
+
export async function buildCircularDeps(basePath) {
|
|
15
9
|
let res = false;
|
|
16
10
|
try {
|
|
17
|
-
const madgeRes = await (
|
|
11
|
+
const madgeRes = await madge(path.join(basePath, "src"), {
|
|
18
12
|
fileExtensions: ["ts"],
|
|
19
13
|
detectiveOptions: {
|
|
20
14
|
ts: {
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.clearDist = clearDist;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const rimraf_1 = require("rimraf");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { rimraf } from "rimraf";
|
|
9
3
|
/**
|
|
10
4
|
* @param basePath -
|
|
11
5
|
* @returns true if the dist folder was cleared
|
|
12
6
|
*/
|
|
13
|
-
async function clearDist(basePath) {
|
|
7
|
+
export async function clearDist(basePath) {
|
|
14
8
|
console.log("Clearing dist folder");
|
|
15
9
|
let res = false;
|
|
16
10
|
try {
|
|
17
|
-
await
|
|
11
|
+
await rimraf(path.join(basePath, "dist"));
|
|
18
12
|
res = true;
|
|
19
13
|
}
|
|
20
14
|
catch (e) {
|
|
@@ -1,55 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.buildDistFiles = buildDistFiles;
|
|
40
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
41
|
-
const klaw_1 = __importDefault(require("klaw"));
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import klaw from "klaw";
|
|
3
|
+
import path from "path";
|
|
43
4
|
/**
|
|
44
5
|
* @param basePath -
|
|
45
6
|
* @returns true if the dist files process was successful
|
|
46
7
|
*/
|
|
47
|
-
async function buildDistFiles(basePath) {
|
|
8
|
+
export async function buildDistFiles(basePath) {
|
|
48
9
|
console.log("Build - started on dist files");
|
|
49
10
|
let res;
|
|
50
11
|
try {
|
|
51
|
-
const pkgInfo = (await
|
|
52
|
-
const data = await
|
|
12
|
+
const pkgInfo = (await import(path.join(basePath, "package.json"))), libPackage = path.join(basePath, "package.dist.json"), distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist");
|
|
13
|
+
const data = await fs.readFile(libPackage), text = data.toString(), libObj = JSON.parse(text);
|
|
53
14
|
libObj.version = pkgInfo.version;
|
|
54
15
|
if (pkgInfo.dependencies) {
|
|
55
16
|
libObj.dependencies = JSON.parse(JSON.stringify(pkgInfo.dependencies).replaceAll("workspace:", ""));
|
|
@@ -58,7 +19,7 @@ async function buildDistFiles(basePath) {
|
|
|
58
19
|
libObj.peerDependencies = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
|
|
59
20
|
}
|
|
60
21
|
const jsonIndent = 2;
|
|
61
|
-
await
|
|
22
|
+
await fs.writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
|
|
62
23
|
console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
|
|
63
24
|
const rootFilesToCopy = [
|
|
64
25
|
"LICENSE",
|
|
@@ -69,23 +30,23 @@ async function buildDistFiles(basePath) {
|
|
|
69
30
|
},
|
|
70
31
|
];
|
|
71
32
|
for (const file of rootFilesToCopy) {
|
|
72
|
-
const src =
|
|
73
|
-
await
|
|
33
|
+
const src = path.join(basePath, typeof file === "string" ? file : file.source), dest = path.join(distPath, typeof file === "string" ? file : file.destination);
|
|
34
|
+
await fs.copyFile(src, dest);
|
|
74
35
|
}
|
|
75
|
-
const scriptsPath =
|
|
76
|
-
if ((await
|
|
77
|
-
await
|
|
78
|
-
const installPath =
|
|
79
|
-
if (await
|
|
80
|
-
await
|
|
36
|
+
const scriptsPath = path.join(basePath, "scripts"), distScriptsPath = path.join(distPath, "scripts");
|
|
37
|
+
if ((await fs.exists(scriptsPath)) && !(await fs.exists(distScriptsPath))) {
|
|
38
|
+
await fs.mkdir(distScriptsPath);
|
|
39
|
+
const installPath = path.join(scriptsPath, "install.js");
|
|
40
|
+
if (await fs.exists(installPath)) {
|
|
41
|
+
await fs.copyFile(installPath, path.join(distScriptsPath, "install.js"));
|
|
81
42
|
}
|
|
82
43
|
}
|
|
83
|
-
for await (const file of (
|
|
44
|
+
for await (const file of klaw(distPath)) {
|
|
84
45
|
if (file.stats.isDirectory()) {
|
|
85
46
|
continue;
|
|
86
47
|
}
|
|
87
|
-
const contents = await
|
|
88
|
-
await
|
|
48
|
+
const contents = await fs.readFile(file.path, "utf8");
|
|
49
|
+
await fs.writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
|
|
89
50
|
}
|
|
90
51
|
/* for await (const file of klaw(path.join(distPath, "cjs"))) {
|
|
91
52
|
await fs.rename(file.path, file.path.replace(/\.js$/, ".cjs"));
|
|
@@ -94,9 +55,9 @@ async function buildDistFiles(basePath) {
|
|
|
94
55
|
for await (const file of klaw(path.join(distPath, "esm"))) {
|
|
95
56
|
await fs.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
|
|
96
57
|
} */
|
|
97
|
-
await
|
|
98
|
-
await
|
|
99
|
-
await
|
|
58
|
+
await fs.writeFile(path.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
|
|
59
|
+
await fs.writeFile(path.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
|
|
60
|
+
await fs.writeFile(path.join(distPath, "browser", "package.json"), `{ "type": "module" }`);
|
|
100
61
|
res = true;
|
|
101
62
|
}
|
|
102
63
|
catch (e) {
|
|
@@ -1,43 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getDistStats = getDistStats;
|
|
40
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
1
|
+
import fs from "fs-extra";
|
|
41
2
|
/**
|
|
42
3
|
* @param folderPath - the path to the folder to get the stats for
|
|
43
4
|
* @param bundlePath - the bundle path to get the bundle size for
|
|
@@ -50,10 +11,10 @@ async function getFolderStats(folderPath, bundlePath) {
|
|
|
50
11
|
totalFolders: 0,
|
|
51
12
|
totalSize: 0,
|
|
52
13
|
};
|
|
53
|
-
if (!(await
|
|
14
|
+
if (!(await fs.pathExists(folderPath))) {
|
|
54
15
|
return stats;
|
|
55
16
|
}
|
|
56
|
-
const dir = await
|
|
17
|
+
const dir = await fs.promises.opendir(folderPath), path = await import("path");
|
|
57
18
|
for await (const dirent of dir) {
|
|
58
19
|
const increment = 1;
|
|
59
20
|
if (dirent.isDirectory()) {
|
|
@@ -63,7 +24,7 @@ async function getFolderStats(folderPath, bundlePath) {
|
|
|
63
24
|
stats.totalSize += subDirStats.totalSize;
|
|
64
25
|
}
|
|
65
26
|
else {
|
|
66
|
-
const fileStats = await
|
|
27
|
+
const fileStats = await fs.stat(path.join(folderPath, dirent.name));
|
|
67
28
|
stats.totalFiles++;
|
|
68
29
|
stats.totalSize += fileStats.size;
|
|
69
30
|
if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
|
|
@@ -78,10 +39,10 @@ async function getFolderStats(folderPath, bundlePath) {
|
|
|
78
39
|
* @param basePath - the base path to the project
|
|
79
40
|
* @returns the stats for the dist folder
|
|
80
41
|
*/
|
|
81
|
-
async function getDistStats(basePath) {
|
|
82
|
-
const path = await
|
|
83
|
-
? (await
|
|
84
|
-
: {}, bundlePath = (await
|
|
42
|
+
export async function getDistStats(basePath) {
|
|
43
|
+
const path = await import("path"), distFolder = path.join(basePath, "dist"), pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
|
|
44
|
+
? (await import(path.join(distFolder, "package.json")))
|
|
45
|
+
: {}, bundlePath = (await fs.exists(distFolder)) && pkgInfo.jsdelivr
|
|
85
46
|
? path.resolve(path.join(distFolder, pkgInfo.jsdelivr))
|
|
86
47
|
: undefined;
|
|
87
48
|
return await getFolderStats(distFolder, bundlePath);
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const eslint_1 = require("eslint");
|
|
1
|
+
import { ESLint } from "eslint";
|
|
2
|
+
import { defineConfig } from "eslint/config";
|
|
3
|
+
import tsParticlesESLintConfig from "@tsparticles/eslint-config";
|
|
5
4
|
/**
|
|
6
5
|
* @param ci -
|
|
7
6
|
* @returns true if the linting was successful
|
|
8
7
|
*/
|
|
9
|
-
async function lint(ci) {
|
|
8
|
+
export async function lint(ci) {
|
|
10
9
|
console.log("ESLint - started on src");
|
|
11
10
|
let res;
|
|
12
11
|
try {
|
|
13
|
-
const eslint = new
|
|
14
|
-
const results = await eslint.lintFiles(["src"]), errors =
|
|
15
|
-
await
|
|
12
|
+
const eslint = new ESLint({ baseConfig: defineConfig([tsParticlesESLintConfig]), fix: !ci });
|
|
13
|
+
const results = await eslint.lintFiles(["src"]), errors = ESLint.getErrorResults(results);
|
|
14
|
+
await ESLint.outputFixes(results);
|
|
16
15
|
const formatter = await eslint.loadFormatter("stylish"), resultText = formatter.format(results), minimumLength = 0;
|
|
17
16
|
if (errors.length > minimumLength) {
|
|
18
17
|
const messages = errors.map(t => t.messages
|
|
@@ -1,44 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.prettifySrc = prettifySrc;
|
|
7
|
-
exports.prettifyPackageJson = prettifyPackageJson;
|
|
8
|
-
exports.prettifyPackageDistJson = prettifyPackageDistJson;
|
|
9
|
-
exports.prettifyReadme = prettifyReadme;
|
|
10
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
-
const klaw_1 = __importDefault(require("klaw"));
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const prettier_1 = __importDefault(require("prettier"));
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import klaw from "klaw";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import prettier from "prettier";
|
|
14
5
|
/**
|
|
15
6
|
* @param basePath -
|
|
16
7
|
* @param srcPath -
|
|
17
8
|
* @param ci -
|
|
18
9
|
* @returns true if the prettify src process was successful
|
|
19
10
|
*/
|
|
20
|
-
async function prettifySrc(basePath, srcPath, ci) {
|
|
11
|
+
export async function prettifySrc(basePath, srcPath, ci) {
|
|
21
12
|
console.log("Prettier - started on src");
|
|
22
13
|
let res;
|
|
23
14
|
try {
|
|
24
|
-
for await (const file of (
|
|
15
|
+
for await (const file of klaw(srcPath)) {
|
|
25
16
|
if (file.stats.isDirectory()) {
|
|
26
17
|
continue;
|
|
27
18
|
}
|
|
28
|
-
const contents = await
|
|
19
|
+
const contents = await fs.readFile(file.path, "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
29
20
|
options.printWidth = 120;
|
|
30
21
|
options.endOfLine = "lf";
|
|
31
22
|
options.parser = "typescript";
|
|
32
23
|
options.tabWidth = 4;
|
|
33
24
|
options.arrowParens = "avoid";
|
|
34
25
|
if (ci) {
|
|
35
|
-
if (!(await
|
|
26
|
+
if (!(await prettier.check(contents, options))) {
|
|
36
27
|
throw new Error(`${file.path} is not formatted correctly`);
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
else {
|
|
40
|
-
const formatted = await
|
|
41
|
-
await
|
|
31
|
+
const formatted = await prettier.format(contents, options);
|
|
32
|
+
await fs.writeFile(file.path, formatted, "utf8");
|
|
42
33
|
}
|
|
43
34
|
}
|
|
44
35
|
res = true;
|
|
@@ -55,23 +46,23 @@ async function prettifySrc(basePath, srcPath, ci) {
|
|
|
55
46
|
* @param ci -
|
|
56
47
|
* @returns true if the prettify package.json process was successful
|
|
57
48
|
*/
|
|
58
|
-
async function prettifyPackageJson(basePath, ci) {
|
|
49
|
+
export async function prettifyPackageJson(basePath, ci) {
|
|
59
50
|
console.log("Prettier - started on package.json");
|
|
60
51
|
let res;
|
|
61
52
|
try {
|
|
62
|
-
const contents = await
|
|
53
|
+
const contents = await fs.readFile("package.json", "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
63
54
|
options.tabWidth = 2;
|
|
64
55
|
options.printWidth = 120;
|
|
65
56
|
options.endOfLine = "lf";
|
|
66
57
|
options.parser = "json";
|
|
67
58
|
if (ci) {
|
|
68
|
-
if (!(await
|
|
59
|
+
if (!(await prettier.check(contents, options))) {
|
|
69
60
|
throw new Error(`package.json is not formatted correctly`);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
else {
|
|
73
|
-
const formatted = await
|
|
74
|
-
await
|
|
64
|
+
const formatted = await prettier.format(contents, options);
|
|
65
|
+
await fs.writeFile("package.json", formatted, "utf8");
|
|
75
66
|
}
|
|
76
67
|
res = true;
|
|
77
68
|
}
|
|
@@ -87,11 +78,11 @@ async function prettifyPackageJson(basePath, ci) {
|
|
|
87
78
|
* @param _ci -
|
|
88
79
|
* @returns true if the prettify package.dist.json process was successful
|
|
89
80
|
*/
|
|
90
|
-
async function prettifyPackageDistJson(basePath, _ci) {
|
|
81
|
+
export async function prettifyPackageDistJson(basePath, _ci) {
|
|
91
82
|
console.log("Prettier - started on package.dist.json");
|
|
92
83
|
let res;
|
|
93
84
|
try {
|
|
94
|
-
const contents = await
|
|
85
|
+
const contents = await fs.readFile("package.dist.json", "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
95
86
|
options.tabWidth = 2;
|
|
96
87
|
options.printWidth = 120;
|
|
97
88
|
options.endOfLine = "lf";
|
|
@@ -102,8 +93,8 @@ async function prettifyPackageDistJson(basePath, _ci) {
|
|
|
102
93
|
throw new Error(`package.dist.json is not formatted correctly`);
|
|
103
94
|
}
|
|
104
95
|
} else { */
|
|
105
|
-
const formatted = await
|
|
106
|
-
await
|
|
96
|
+
const formatted = await prettier.format(contents, options);
|
|
97
|
+
await fs.writeFile("package.dist.json", formatted, "utf8");
|
|
107
98
|
// }
|
|
108
99
|
res = true;
|
|
109
100
|
}
|
|
@@ -119,22 +110,22 @@ async function prettifyPackageDistJson(basePath, _ci) {
|
|
|
119
110
|
* @param ci -
|
|
120
111
|
* @returns true if the prettify readme process was successful
|
|
121
112
|
*/
|
|
122
|
-
async function prettifyReadme(basePath, ci) {
|
|
113
|
+
export async function prettifyReadme(basePath, ci) {
|
|
123
114
|
console.log("Prettier - started on README.md");
|
|
124
115
|
let res;
|
|
125
116
|
try {
|
|
126
|
-
const contents = await
|
|
117
|
+
const contents = await fs.readFile("README.md", "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
127
118
|
options.printWidth = 120;
|
|
128
119
|
options.endOfLine = "lf";
|
|
129
120
|
options.parser = "markdown";
|
|
130
121
|
if (ci) {
|
|
131
|
-
if (!(await
|
|
122
|
+
if (!(await prettier.check(contents, options))) {
|
|
132
123
|
throw new Error(`README.md is not formatted correctly`);
|
|
133
124
|
}
|
|
134
125
|
}
|
|
135
126
|
else {
|
|
136
|
-
const formatted = await
|
|
137
|
-
await
|
|
127
|
+
const formatted = await prettier.format(contents, options);
|
|
128
|
+
await fs.writeFile("README.md", formatted, "utf8");
|
|
138
129
|
}
|
|
139
130
|
res = (await prettifyTraductions(basePath, ci)) && (await prettifyMarkdownTypeDocFiles(basePath, ci));
|
|
140
131
|
}
|
|
@@ -154,27 +145,27 @@ async function prettifyTraductions(basePath, ci) {
|
|
|
154
145
|
console.log("Prettier - started on traductions");
|
|
155
146
|
let res = false;
|
|
156
147
|
try {
|
|
157
|
-
const folder = "traduction", folderPath =
|
|
158
|
-
if (!
|
|
148
|
+
const folder = "traduction", folderPath = path.join(basePath, folder);
|
|
149
|
+
if (!fs.existsSync(folderPath)) {
|
|
159
150
|
res = true;
|
|
160
151
|
}
|
|
161
152
|
if (!res) {
|
|
162
|
-
for await (const file of (
|
|
153
|
+
for await (const file of klaw(folderPath)) {
|
|
163
154
|
if (file.stats.isDirectory()) {
|
|
164
155
|
continue;
|
|
165
156
|
}
|
|
166
|
-
const contents = await
|
|
157
|
+
const contents = await fs.readFile(file.path, "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
167
158
|
options.printWidth = 120;
|
|
168
159
|
options.endOfLine = "lf";
|
|
169
160
|
options.parser = "markdown";
|
|
170
161
|
if (ci) {
|
|
171
|
-
if (!(await
|
|
162
|
+
if (!(await prettier.check(contents, options))) {
|
|
172
163
|
throw new Error(`${file.path} is not formatted correctly`);
|
|
173
164
|
}
|
|
174
165
|
}
|
|
175
166
|
else {
|
|
176
|
-
const formatted = await
|
|
177
|
-
await
|
|
167
|
+
const formatted = await prettier.format(contents, options);
|
|
168
|
+
await fs.writeFile(file.path, formatted, "utf8");
|
|
178
169
|
}
|
|
179
170
|
}
|
|
180
171
|
res = true;
|
|
@@ -196,27 +187,27 @@ async function prettifyMarkdownTypeDocFiles(basePath, ci) {
|
|
|
196
187
|
console.log("Prettier - started on markdown");
|
|
197
188
|
let res = false;
|
|
198
189
|
try {
|
|
199
|
-
const folder = "markdown", folderPath =
|
|
200
|
-
if (!
|
|
190
|
+
const folder = "markdown", folderPath = path.join(basePath, folder);
|
|
191
|
+
if (!fs.existsSync(folderPath)) {
|
|
201
192
|
res = true;
|
|
202
193
|
}
|
|
203
194
|
if (!res) {
|
|
204
|
-
for await (const file of (
|
|
195
|
+
for await (const file of klaw(folderPath)) {
|
|
205
196
|
if (file.stats.isDirectory()) {
|
|
206
197
|
continue;
|
|
207
198
|
}
|
|
208
|
-
const contents = await
|
|
199
|
+
const contents = await fs.readFile(file.path, "utf8"), options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
209
200
|
options.printWidth = 120;
|
|
210
201
|
options.endOfLine = "lf";
|
|
211
202
|
options.parser = "markdown";
|
|
212
203
|
if (ci) {
|
|
213
|
-
if (!(await
|
|
204
|
+
if (!(await prettier.check(contents, options))) {
|
|
214
205
|
throw new Error(`${file.path} is not formatted correctly`);
|
|
215
206
|
}
|
|
216
207
|
}
|
|
217
208
|
else {
|
|
218
|
-
const formatted = await
|
|
219
|
-
await
|
|
209
|
+
const formatted = await prettier.format(contents, options);
|
|
210
|
+
await fs.writeFile(file.path, formatted, "utf8");
|
|
220
211
|
}
|
|
221
212
|
}
|
|
222
213
|
res = true;
|