generated from Seekra/repository-template
Feat(legal): legal notice #8
+6
-1
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { processPlugin } from './utils/plugin.js';
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import { readdir, rm } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { parseArgs } from 'node:util';
|
||||
@@ -47,6 +47,11 @@ const { values: args } = parseArgs({
|
||||
}
|
||||
});
|
||||
|
||||
await rm(args.distBase, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
|
||||
(await Promise.all(
|
||||
files
|
||||
.filter((file) => file.endsWith('.js'))
|
||||
|
||||
+7
-24
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { checkFileReadAccess, exists, isDirectory } from './fileAccess.js';
|
||||
import { exists, isDirectory } from './fileAccess.js';
|
||||
import { cp, mkdir, writeFile } from 'node:fs/promises';
|
||||
import { dirname, join } from 'node:path';
|
||||
|
||||
@@ -29,27 +29,7 @@ const validateArtifact = function validateArtifact (artifact) {
|
||||
)
|
||||
);
|
||||
} else if (artifact.type === 'copy') {
|
||||
if (typeof artifact.options.source !== 'string') return false;
|
||||
return checkFileReadAccess(artifact.options.source);
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
|
||||
const checkPath = async function checkPath (path) {
|
||||
const directory = dirname(path);
|
||||
if (await exists(directory) && !await isDirectory(directory)) {
|
||||
console.warn('Skipping artifact as parent directory exists and is not a directory.');
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
if (!await exists(directory)) {
|
||||
await mkdir(directory, { recursive: true });
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn('Skipping artifact as directory is not creatable.');
|
||||
return false;
|
||||
}
|
||||
return typeof artifact.options.source === 'string';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,8 +38,11 @@ export const processArtifact = async function processArtifact (artifact, { srcBa
|
||||
console.warn('Skipping artifact as it is invalid.');
|
||||
return;
|
||||
}
|
||||
const distPath = join(distBase, artifact.path)
|
||||
if (!await checkPath(distPath)) return;
|
||||
const distPath = join(distBase, artifact.path);
|
||||
const distPathDirectory = dirname(distPath);
|
||||
if (!await exists(distPathDirectory)) {
|
||||
await mkdir(distPathDirectory, { recursive: true });
|
||||
}
|
||||
if (artifact.type === 'text') {
|
||||
await writeFile(
|
||||
distPath,
|
||||
|
||||
@@ -16,16 +16,6 @@ limitations under the License.
|
||||
|
||||
import { access, constants, stat } from 'node:fs/promises';
|
||||
|
||||
export const checkFileReadAccess = async function checkFileWriteAccess (path) {
|
||||
try {
|
||||
await access(path, constants.F_OK | constants.R_OK);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT' || err.code === 'EACCES') return false;
|
||||
else throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export const exists = async function exists (path) {
|
||||
try {
|
||||
await access(path, constants.F_OK);
|
||||
|
||||
Reference in New Issue
Block a user