@masatomakino/gulptask-ejs 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Masato Makino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # gulptask-ejs
package/bin/CLI.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=CLI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CLI.d.ts","sourceRoot":"","sources":["../src/CLI.ts"],"names":[],"mappings":""}
package/bin/CLI.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const index_1 = require("./index");
6
+ const program = new commander_1.Command();
7
+ program
8
+ .option("-W --watch", "watch mode. default : false")
9
+ .option("--srcDir <path>", "Source directory for ejs files ex. './src/ejs'")
10
+ .option("--distDir <path>", "Output directory. ex. './dist'")
11
+ .option("--componentPatterns <string | string[]>", "[optional] Glob pattern for ejs components.")
12
+ .parse(process.argv);
13
+ const args = program.opts();
14
+ (async () => {
15
+ const task = (0, index_1.generateTasks)(args.srcDir, args.distDir, args.componentPatterns);
16
+ if (args.watch) {
17
+ task.watchEJS();
18
+ }
19
+ else {
20
+ await task.buildEJS();
21
+ }
22
+ })();
package/bin/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * ejs変換タスクを取得する。
3
+ * @param srcDir - 入力ディレクトリ ex) "./src/"
4
+ * @param distDir 出力先ディレクトリ ex) "./dist/"
5
+ * @param componentPatterns - コンポーネントファイルのglob、出力対象にはならないが、watchの対象にはなる。
6
+ * @return gulpタスク
7
+ */
8
+ export declare function generateTasks(srcDir: string, distDir: string, componentPatterns?: string | string[]): {
9
+ buildEJS: Function;
10
+ watchEJS: Function;
11
+ };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GACpC;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAyBA"}
package/bin/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTasks = void 0;
4
+ const ejs = require("ejs");
5
+ const path = require("path");
6
+ const glob = require("glob");
7
+ const chokidar = require("chokidar");
8
+ const promises_1 = require("fs/promises");
9
+ /**
10
+ * ejs変換タスクを取得する。
11
+ * @param srcDir - 入力ディレクトリ ex) "./src/"
12
+ * @param distDir 出力先ディレクトリ ex) "./dist/"
13
+ * @param componentPatterns - コンポーネントファイルのglob、出力対象にはならないが、watchの対象にはなる。
14
+ * @return gulpタスク
15
+ */
16
+ function generateTasks(srcDir, distDir, componentPatterns) {
17
+ distDir = path.resolve(process.cwd(), distDir);
18
+ const buildEJS = async () => {
19
+ const srcFiles = await existsTarget(srcDir, componentPatterns);
20
+ for (const srcFile of srcFiles) {
21
+ await build(srcFile, srcDir, distDir);
22
+ }
23
+ };
24
+ const watchEJS = () => {
25
+ chokidar
26
+ .watch(path.resolve(srcDir, "**/*.ejs"))
27
+ .on("all", (type, filePath) => {
28
+ console.log(`gulptask-ejs : [${type}] ${path.relative(srcDir, filePath)}`);
29
+ buildEJS();
30
+ });
31
+ };
32
+ return {
33
+ buildEJS,
34
+ watchEJS,
35
+ };
36
+ }
37
+ exports.generateTasks = generateTasks;
38
+ /**
39
+ * 1つのejsファイルをrenderingして、ファイルに保存する
40
+ * @param srcFile ファイルパス srcDirからの相対パス
41
+ * @param srcDir 入力ディレクトリ
42
+ * @param distDir 出力ディレクトリ
43
+ */
44
+ const build = async (srcFile, srcDir, distDir) => {
45
+ const result = await ejs.renderFile(path.resolve(srcDir, srcFile));
46
+ const distPath = path.parse(path.resolve(distDir, srcFile));
47
+ await (0, promises_1.mkdir)(distPath.dir, { recursive: true });
48
+ await (0, promises_1.writeFile)(path.resolve(distPath.dir, distPath.name + ".html"), result);
49
+ };
50
+ const existsTarget = async (dir, ignorePattern) => {
51
+ const targets = await glob.sync("**/*.ejs", {
52
+ cwd: dir,
53
+ ignore: ignorePattern,
54
+ });
55
+ if (targets == null || targets.length === 0) {
56
+ console.error("\x1b[31m%s\x1b[0m", `gulptask-ejs : Error no target files.
57
+ The file specified by ${dir} does not exist. The EJS task exits without outputting anything.
58
+ ${dir}で指定されたファイルが存在しません。EJSタスクは何も出力せずに終了します。`);
59
+ }
60
+ return targets;
61
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@masatomakino/gulptask-ejs",
3
+ "version": "0.3.2",
4
+ "description": "ejs compiler task for gulp.js",
5
+ "main": "./bin/index.js",
6
+ "types": "./bin/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://MasatoMakino@github.com/MasatoMakino/gulptask-ejs.git"
10
+ },
11
+ "author": "MasatoMakino <unagiinu.g@gmail.com>",
12
+ "license": "MIT",
13
+ "files": [
14
+ "bin"
15
+ ],
16
+ "bin": {
17
+ "gulptask-ejs": "bin/CLI.js"
18
+ },
19
+ "dependencies": {
20
+ "chokidar": "^3.5.3",
21
+ "commander": "^9.3.0",
22
+ "ejs": "^3.1.8",
23
+ "glob": "^8.0.3"
24
+ },
25
+ "devDependencies": {
26
+ "@types/ejs": "^3.1.1",
27
+ "@types/glob": "^7.2.0",
28
+ "@types/node": "^17.0.39",
29
+ "husky": "^8.0.1",
30
+ "prettier": "^2.6.2",
31
+ "pretty-quick": "^3.1.3",
32
+ "typescript": "^4.7.3"
33
+ },
34
+ "scripts": {
35
+ "build": "npx tsc",
36
+ "dev": "npx tsc -w",
37
+ "run": "node gulpfile.js",
38
+ "buildEJS": "npx gulptask-ejs --srcDir ./testEjs --distDir ./dist --componentPatterns '**/_*.ejs'",
39
+ "watchEJS": "npm run buildEJS -- -W"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/MasatoMakino/gulptask-ejs/issues"
43
+ },
44
+ "homepage": "https://github.com/MasatoMakino/gulptask-ejs#readme"
45
+ }