netlify-cli 17.23.6 → 17.23.7
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/dist/commands/functions/functions-create.d.ts.map +1 -1
- package/dist/commands/functions/functions-create.js +1 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/copy-template-dir/copy-template-dir.d.ts +2 -0
- package/dist/utils/copy-template-dir/copy-template-dir.d.ts.map +1 -0
- package/dist/utils/copy-template-dir/copy-template-dir.js +74 -0
- package/npm-shrinkwrap.json +24 -2180
- package/package.json +4 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-template-dir.d.ts","sourceRoot":"","sources":["../../../src/utils/copy-template-dir/copy-template-dir.ts"],"names":[],"mappings":"AA0DA,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAiClG"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// License for copy-template-dir.
|
|
2
|
+
// Original repository: https://github.com/yoshuawuyts/copy-template-dir
|
|
3
|
+
// The MIT License (MIT)
|
|
4
|
+
// Copyright (c) 2015 Yoshua Wuyts
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
10
|
+
// Software.
|
|
11
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
12
|
+
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
13
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
14
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
15
|
+
import assert from 'assert';
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { pipeline } from 'stream';
|
|
19
|
+
import { promisify } from 'util';
|
|
20
|
+
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'maxstache... Remove this comment to see the full error message
|
|
21
|
+
import maxstache from 'maxstache';
|
|
22
|
+
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'maxstache-stream... Remove this comment to see the full error message
|
|
23
|
+
import maxstacheStream from 'maxstache-stream';
|
|
24
|
+
import readdirp from 'readdirp';
|
|
25
|
+
const noop = () => undefined;
|
|
26
|
+
// Remove a leading underscore
|
|
27
|
+
function removeUnderscore(filepath) {
|
|
28
|
+
const parts = filepath.split(path.sep);
|
|
29
|
+
const filename = parts.pop()?.replace(/^_/, '') || '';
|
|
30
|
+
return [...parts, filename].join(path.sep);
|
|
31
|
+
}
|
|
32
|
+
// Write a file to a directory
|
|
33
|
+
async function writeFile(outDir, vars, file) {
|
|
34
|
+
const fileName = file.path;
|
|
35
|
+
const inFile = file.fullPath;
|
|
36
|
+
const parentDir = path.dirname(file.path);
|
|
37
|
+
const outFile = path.join(outDir, maxstache(removeUnderscore(fileName), vars));
|
|
38
|
+
await fs.promises.mkdir(path.join(outDir, maxstache(parentDir, vars)), { recursive: true });
|
|
39
|
+
const rs = fs.createReadStream(inFile);
|
|
40
|
+
const ts = maxstacheStream(vars);
|
|
41
|
+
const ws = fs.createWriteStream(outFile);
|
|
42
|
+
await promisify(pipeline)(rs, ts, ws);
|
|
43
|
+
}
|
|
44
|
+
// High throughput template dir writes
|
|
45
|
+
export async function copyTemplateDir(srcDir, outDir, vars) {
|
|
46
|
+
if (!vars)
|
|
47
|
+
vars = noop;
|
|
48
|
+
assert.strictEqual(typeof srcDir, 'string');
|
|
49
|
+
assert.strictEqual(typeof outDir, 'string');
|
|
50
|
+
assert.strictEqual(typeof vars, 'object');
|
|
51
|
+
await fs.promises.mkdir(outDir, { recursive: true });
|
|
52
|
+
const rs = readdirp(srcDir);
|
|
53
|
+
const streams = [];
|
|
54
|
+
const createdFiles = [];
|
|
55
|
+
rs.on('data', (file) => {
|
|
56
|
+
createdFiles.push(path.join(outDir, maxstache(removeUnderscore(file.path), vars)));
|
|
57
|
+
streams.push(writeFile(outDir, vars, file));
|
|
58
|
+
});
|
|
59
|
+
await new Promise((resolve, reject) => {
|
|
60
|
+
rs.on('end', async () => {
|
|
61
|
+
try {
|
|
62
|
+
await Promise.all(streams);
|
|
63
|
+
resolve();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
reject(error);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
rs.on('error', (error) => {
|
|
70
|
+
reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return createdFiles;
|
|
74
|
+
}
|