1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.run = void 0;
|
7 | const chalk_1 = __importDefault(require("chalk"));
|
8 | const chokidar_1 = __importDefault(require("chokidar"));
|
9 | const glob_1 = require("glob");
|
10 | const dts_creator_1 = require("./dts-creator");
|
11 | async function run(searchDir, options = {}) {
|
12 | const filesPattern = searchDir.replace(/\\/g, '/') + '/' + (options.pattern || '**/*.css');
|
13 | const creator = new dts_creator_1.DtsCreator({
|
14 | rootDir: process.cwd(),
|
15 | searchDir,
|
16 | outDir: options.outDir,
|
17 | camelCase: options.camelCase,
|
18 | namedExports: options.namedExports,
|
19 | allowArbitraryExtensions: options.allowArbitraryExtensions,
|
20 | dropExtension: options.dropExtension,
|
21 | });
|
22 | const checkFile = async (f) => {
|
23 | try {
|
24 | const content = await creator.create(f, undefined, false);
|
25 | return await content.checkFile();
|
26 | }
|
27 | catch (error) {
|
28 | console.error(chalk_1.default.red(`[ERROR] An error occurred checking '${f}':\n${error}`));
|
29 | return false;
|
30 | }
|
31 | };
|
32 | const writeFile = async (f) => {
|
33 | try {
|
34 | const content = await creator.create(f, undefined, !!options.watch);
|
35 | await content.writeFile();
|
36 | if (!options.silent) {
|
37 | console.log('Wrote ' + chalk_1.default.green(content.outputFilePath));
|
38 | }
|
39 | }
|
40 | catch (error) {
|
41 | console.error(chalk_1.default.red('[Error] ' + error));
|
42 | }
|
43 | };
|
44 | const deleteFile = async (f) => {
|
45 | try {
|
46 | const content = await creator.create(f, undefined, !!options.watch, true);
|
47 | await content.deleteFile();
|
48 | console.log('Delete ' + chalk_1.default.green(content.outputFilePath));
|
49 | }
|
50 | catch (error) {
|
51 | console.error(chalk_1.default.red('[Error] ' + error));
|
52 | }
|
53 | };
|
54 | if (options.listDifferent) {
|
55 | const files = await (0, glob_1.glob)(filesPattern);
|
56 | const hasErrors = (await Promise.all(files.map(checkFile))).includes(false);
|
57 | if (hasErrors) {
|
58 | process.exit(1);
|
59 | }
|
60 | return;
|
61 | }
|
62 | if (!options.watch) {
|
63 | const files = await (0, glob_1.glob)(filesPattern);
|
64 | await Promise.all(files.map(writeFile));
|
65 | }
|
66 | else {
|
67 | console.log('Watch ' + filesPattern + '...');
|
68 | const watcher = chokidar_1.default.watch([filesPattern]);
|
69 | watcher.on('add', writeFile);
|
70 | watcher.on('change', writeFile);
|
71 | watcher.on('unlink', deleteFile);
|
72 | await waitForever();
|
73 | }
|
74 | }
|
75 | exports.run = run;
|
76 | async function waitForever() {
|
77 | return new Promise(() => { });
|
78 | }
|
79 |
|
\ | No newline at end of file |