Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wixc3/codux-librarian

Package Overview
Dependencies
Maintainers
64
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/codux-librarian - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

dist/services/library-builder.d.ts

7

dist/cli.js

@@ -34,4 +34,7 @@ "use strict";

const config = (0, read_config_1.readConfig)(args.config);
const shouldRemoveBuildDir = (0, is_path_strictly_inside_directory_1.isPathStrictlyInsideDirectory)(config.buildDir, process.cwd());
const packageBuilder = new index_1.PackageBuilder({ config, shouldRemoveBuildDir }, node_1.default);
const rootPath = process.cwd();
const shouldRemoveBuildDir = !config.manifestOnly
? (0, is_path_strictly_inside_directory_1.isPathStrictlyInsideDirectory)(config.buildDir, rootPath)
: false;
const packageBuilder = new index_1.LibraryBuilder({ config, shouldRemoveBuildDir, currentRoot: rootPath }, node_1.default);
const stats = await packageBuilder.build();

@@ -38,0 +41,0 @@ if ('errors' in stats) {

@@ -1,2 +0,2 @@

export * from './services/package-builder';
export * from './services/library-builder';
//# sourceMappingURL=index.d.ts.map

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./services/package-builder"), exports);
__exportStar(require("./services/library-builder"), exports);
//# sourceMappingURL=index.js.map

@@ -11,8 +11,11 @@ "use strict";

function resolvePathsInConfig(config, configPath) {
return {
const resolved = {
...config,
buildDir: (0, node_path_1.resolve)(configPath, config.buildDir),
boardsPath: (0, node_path_1.resolve)(configPath, config.boardsPath),
libraryIcon: (0, node_path_1.resolve)(configPath, config.libraryIcon),
};
if (!resolved.manifestOnly) {
resolved.buildDir = (0, node_path_1.resolve)(configPath, resolved.buildDir);
}
return resolved;
}

@@ -19,0 +22,0 @@ function readConfig(pathToConfig) {

@@ -8,12 +8,30 @@ "use strict";

.nonempty("can't be empty");
exports.LibrarianConfigValidator = zod_1.z.object({
const manifestFields = {
boardsPath: nonEmptyRequiredString,
libraryName: nonEmptyRequiredString,
libraryIcon: nonEmptyRequiredString,
};
const allFields = {
...manifestFields,
buildDir: nonEmptyRequiredString,
packageName: nonEmptyRequiredString,
packageVersion: nonEmptyRequiredString,
libraryName: nonEmptyRequiredString,
libraryIcon: nonEmptyRequiredString,
}, {
};
const objectError = {
invalid_type_error: 'Config has to be an object',
});
};
exports.LibrarianConfigValidator = zod_1.z.discriminatedUnion('manifestOnly', [
zod_1.z.object({
manifestOnly: zod_1.z.literal(true),
...manifestFields,
}, objectError),
zod_1.z.object({
manifestOnly: zod_1.z.literal(false),
...allFields,
}, objectError),
zod_1.z.object({
manifestOnly: zod_1.z.undefined(),
...allFields,
}, objectError),
]);
/** Format validation errors to human readable format. */

@@ -20,0 +38,0 @@ function formatConfigValidatorError(error) {

import type { IFileSystem } from '@file-services/types';
import type { CoduxManifest, LibrarianConfig } from '../types';
export type BuildResult = {
errors: Error[];
} | {
manifest: CoduxManifest;
import type { BoardDetails, ManifestConfig, PackageConfig } from '../types';
type PackageBuilderOptions = {
config: ManifestConfig & PackageConfig;
shouldRemoveBuildDir?: boolean | undefined;
};
export type PackageBuilderOptions = {
config: LibrarianConfig;
shouldRemoveBuildDir?: boolean;
};
export declare class PackageBuilder {

@@ -17,16 +12,8 @@ private fs;

constructor({ config, shouldRemoveBuildDir }: PackageBuilderOptions, fs: IFileSystem);
build(): Promise<BuildResult>;
private findBoards;
private parseBoards;
private buildPackage;
buildPackage(boards: BoardDetails[]): Promise<void>;
private copyBoards;
private copyBoard;
private getRelativeBoardPathInPackage;
private getAbsoluteBoardPathInPackage;
private getBoardPathForManifest;
private getBoardCategory;
private prepareBoardForManifest;
private generateManifest;
private generatePackageJson;
}
export {};
//# sourceMappingURL=package-builder.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackageBuilder = void 0;
const constants_1 = require("../constants");
const image_file_to_data_url_1 = require("../utils/image-file-to-data-url");
const to_error_1 = require("../utils/to-error");
const ensure_posix_path_1 = require("../utils/ensure-posix-path");
const board_parser_1 = require("./board-parser");
const path_utils_1 = require("./path-utils");
class PackageBuilder {

@@ -15,29 +11,2 @@ constructor({ config, shouldRemoveBuildDir }, fs) {

}
async build() {
const boardPaths = this.findBoards();
const { boards, errors } = await this.parseBoards(boardPaths);
if (errors.length)
return { errors };
const manifest = await this.buildPackage(boards);
return { manifest };
}
findBoards() {
return this.fs.findFilesSync(this.config.boardsPath, {
filterFile: ({ name }) => name.endsWith('.board.tsx') && !name.startsWith('_'),
});
}
async parseBoards(boardPaths) {
const boards = [];
const errors = [];
await Promise.all(boardPaths.map(async (path) => {
try {
const parser = new board_parser_1.BoardParser(path, this.fs);
boards.push(await parser.parse());
}
catch (error) {
errors.push((0, to_error_1.toError)(error));
}
}));
return { boards, errors };
}
async buildPackage(boards) {

@@ -49,8 +18,3 @@ const { buildDir } = this.config;

this.fs.ensureDirectorySync(buildDir);
const [manifest] = await Promise.all([
this.generateManifest(boards),
this.copyBoards(boards),
this.generatePackageJson(),
]);
return manifest;
await Promise.all([this.copyBoards(boards), this.generatePackageJson()]);
}

@@ -61,38 +25,6 @@ async copyBoards(boards) {

async copyBoard(board) {
const pathToBoardInPackage = this.getAbsoluteBoardPathInPackage(board.path);
const pathToBoardInPackage = (0, path_utils_1.getAbsoluteBoardPathInPackage)(this.fs, board.path, this.config.boardsPath, this.config.buildDir);
await this.fs.promises.ensureDirectory(this.fs.dirname(pathToBoardInPackage));
await this.fs.promises.copyFile(board.path, pathToBoardInPackage);
}
getRelativeBoardPathInPackage(originalBoardPath) {
const relativeSourcePath = this.fs.relative(this.config.boardsPath, originalBoardPath);
return this.fs.join(constants_1.boardsDirectoryInPackage, relativeSourcePath);
}
getAbsoluteBoardPathInPackage(originalBoardPath) {
return this.fs.join(this.config.buildDir, this.getRelativeBoardPathInPackage(originalBoardPath));
}
getBoardPathForManifest(originalBoardPath) {
return (0, ensure_posix_path_1.ensurePosixPath)(this.getRelativeBoardPathInPackage(originalBoardPath));
}
getBoardCategory(originalBoardPath) {
const relativeSourcePath = this.fs.relative(this.config.boardsPath, originalBoardPath);
return relativeSourcePath.split(this.fs.sep).slice(0, -1);
}
prepareBoardForManifest(board) {
return {
...board,
path: this.getBoardPathForManifest(board.path),
category: this.getBoardCategory(board.path),
};
}
async generateManifest(boards) {
const manifest = {
name: this.config.libraryName,
icon: await (0, image_file_to_data_url_1.imageFileToDataUrl)(this.config.libraryIcon, this.fs),
manifestFileVersion: constants_1.manifestFileVersion,
boards: boards.map((board) => this.prepareBoardForManifest(board)),
};
const manifestPath = this.fs.join(this.config.buildDir, constants_1.manifestFileName);
await this.fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
return manifest;
}
async generatePackageJson() {

@@ -99,0 +31,0 @@ const { packageName, packageVersion } = this.config;

@@ -5,5 +5,10 @@ /**

*/
export interface LibrarianConfig {
/** Source directory containing boards. */
boardsPath: string;
export type LibrarianConfig =
/** if true will generate manifest only from src files, withought creating a package */
({
manifestOnly: true;
} & ManifestConfig) | ({
manifestOnly?: false | undefined;
} & PackageConfig & ManifestConfig);
export type PackageConfig = {
/**

@@ -19,2 +24,6 @@ * The output directory for the resulting NPM package. If this directory

packageVersion: string;
};
export type ManifestConfig = {
/** Source directory containing boards. */
boardsPath: string;
/** The library name to be shown in Codux. */

@@ -24,3 +33,3 @@ libraryName: string;

libraryIcon: string;
}
};
//# sourceMappingURL=librarian-config.d.ts.map
{
"name": "@wixc3/codux-librarian",
"version": "0.1.4",
"version": "0.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc