declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
34 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.compile = exports.deserializeGlobPathFromNpmPackaging = exports.serializeGlobPathForNpmPackaging = void 0;
const copyFileAsync_1 = require("../../utils/fileio/copyFileAsync");
const listFilesInDirectory_1 = require("../../utils/filepaths/listFilesInDirectory");
const serializeGlobPathForNpmPackaging = (path) => path.replace(/\*/g, '<star>');
exports.serializeGlobPathForNpmPackaging = serializeGlobPathForNpmPackaging;
const deserializeGlobPathFromNpmPackaging = (path) => path.replace(/\<star\>/g, '*');
exports.deserializeGlobPathFromNpmPackaging = deserializeGlobPathFromNpmPackaging;
/**
*
* compiles declarations from a `sourceDirectory` into `distributionDirectory`, making sure that they can be packaged and used with npm successfully
*
* specifically, while copying each file from `sourceDirectory` to `distributionDirectory`:
* - replaces file path `*` chars to `<star>` chars (https://github.com/uladkasach/declapract/issues/5)
*
* note: this is expected to be temporarily required functionality
* - hopefully, we will be able to remove this when npm supports `*` in path names itself
* - https://github.com/npm/cli/issues/3722
*/
const compile = async ({ sourceDirectory, distributionDirectory, }) => {
// list all the files in the source dir
const filePaths = await (0, listFilesInDirectory_1.listFilesInDirectory)({ directory: sourceDirectory });
const relevantFilePaths = filePaths.filter((filePath) => !filePath.endsWith('.declapract.test.ts') &&
!filePath.endsWith('.declapract.test.ts.snap')); // skip the test files
console.log(`📝 compiling ${relevantFilePaths.length} files...`); // tslint:disable-line: no-console
// write each one to the distribution directory
await Promise.all(relevantFilePaths.map((filePath) => (0, copyFileAsync_1.copyFileAsync)({
from: `${sourceDirectory}/${filePath}`,
to: `${distributionDirectory}/${(0, exports.serializeGlobPathForNpmPackaging)(filePath)}`,
})));
};
exports.compile = compile;
//# sourceMappingURL=compile.js.map