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

@mokr/core

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mokr/core - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

lib/parts/JestConfig.d.ts

4

lib/index.d.ts
import * as plugins from './plugins';
import * as templates from './templates';
export { plugins };
export * from './parts';
export * from './utils';
export { plugins, templates };
export declare type Plugins = typeof plugins;

@@ -15,6 +15,4 @@ "use strict";

exports.plugins = plugins;
const templates = __importStar(require("./templates"));
exports.templates = templates;
__export(require("./parts"));
__export(require("./utils"));
//# sourceMappingURL=index.js.map

@@ -6,3 +6,4 @@ "use strict";

get contents() {
return this.text.split('\n');
var _a;
return ((_a = this.text) !== null && _a !== void 0 ? _a : '').split('\n');
}

@@ -9,0 +10,0 @@ set contents(entries) {

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

get contents() {
const object = new this.SchemaClass(JSON.parse(this.text));
const object = new this.SchemaClass(JSON.parse(this.text || '{}'));
return schemaProxy(object, object => (this.contents = object));

@@ -26,0 +26,0 @@ }

import { GitIgnore } from './GitIgnore';
import { PackageJson } from './PackageJson';
import { TsconfigJson } from './TsconfigJson';
import { JestConfig } from './JestConfig';
import { Project } from './Project';
import { Workspace } from './Workspace';
export declare class Package {
directory: string;
private addDependencyQueue;
constructor(directory: string);

@@ -11,2 +15,18 @@ get name(): string;

get tsconfigJson(): TsconfigJson;
get jestConfig(): JestConfig;
/**
* Returns true if the package.json for this package has a workspaces entry.
*/
isRoot(): boolean;
/**
* Returns true if this package is constructed with the Workspace class.
*/
isWorkspace(): this is Workspace;
/**
* Returns true if this package is constructed with the Project class.
*/
isProject(): this is Project;
installQueue(): Promise<void>;
addDependency(name: string): void;
addDevDependency(name: string): void;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const path = require("path");
const utils_1 = require("../utils");
const GitIgnore_1 = require("./GitIgnore");
const PackageJson_1 = require("./PackageJson");
const TsconfigJson_1 = require("./TsconfigJson");
const JestConfig_1 = require("./JestConfig");
class Package {
constructor(directory) {
this.directory = directory;
this.addDependencyQueue = {
dependencies: [],
devDependencies: []
};
}
get name() {
return path_1.default.basename(this.directory);
return path.basename(this.directory);
}

@@ -26,4 +38,50 @@ get gitignore() {

}
get jestConfig() {
return new JestConfig_1.JestConfig(this.directory);
}
/**
* Returns true if the package.json for this package has a workspaces entry.
*/
isRoot() {
return !!this.packageJson.contents.workspaces;
}
/**
* Returns true if this package is constructed with the Workspace class.
*/
isWorkspace() {
return this.constructor.name === 'Workspace';
}
/**
* Returns true if this package is constructed with the Project class.
*/
isProject() {
return this.constructor.name === 'Project';
}
installQueue() {
return utils_1.asyncForEach(Object.keys(this.addDependencyQueue), (queue) => __awaiter(this, void 0, void 0, function* () {
if (!this.addDependencyQueue[queue].length) {
return;
}
const packages = this.addDependencyQueue[queue];
const flags = ['--exact'];
if (queue === 'devDependencies') {
flags.push('--dev');
}
if (this.isProject()) {
flags.push('--ignore-workspace-root-check');
}
yield utils_1.exec('yarn', ['add', ...packages, ...flags], {
cwd: this.directory
});
this.addDependencyQueue[queue] = [];
}));
}
addDependency(name) {
this.addDependencyQueue.dependencies.push(name);
}
addDevDependency(name) {
this.addDependencyQueue.devDependencies.push(name);
}
}
exports.Package = Package;
//# sourceMappingURL=Package.js.map

@@ -32,2 +32,3 @@ import { JsonFile } from './JsonFile';

workspaces?: string[];
mokr?: MokrOptions;
constructor(object: PackageJsonSchema);

@@ -66,2 +67,3 @@ }

interface PublishConfig {
access?: string;
registry?: string;

@@ -76,26 +78,9 @@ }

}
interface MokrOptions {
scoped?: boolean;
}
export declare class PackageJson extends JsonFile<PackageJsonSchema> {
directory: string;
constructor(directory: string);
addDependency(name: string, flags?: any[]): Promise<{
status: number;
stdout: string;
stderr: string;
}>;
addDevDependency(name: string): Promise<{
status: number;
stdout: string;
stderr: string;
}>;
addRootDependency(name: string): Promise<{
status: number;
stdout: string;
stderr: string;
}>;
addRootDevDependency(name: string): Promise<{
status: number;
stdout: string;
stderr: string;
}>;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const JsonFile_1 = require("./JsonFile");

@@ -16,18 +15,4 @@ class PackageJsonSchema {

}
addDependency(name, flags = []) {
return utils_1.exec('yarn', ['add', name, ...flags], {
cwd: this.directory
});
}
addDevDependency(name) {
return this.addDependency(name, ['--dev']);
}
addRootDependency(name) {
return this.addDependency(name, ['--ignore-workspace-root-check']);
}
addRootDevDependency(name) {
return this.addDependency(name, ['--ignore-workspace-root-check', '--dev']);
}
}
exports.PackageJson = PackageJson;
//# sourceMappingURL=PackageJson.js.map

@@ -0,7 +1,9 @@

import { Plugins } from '..';
import { Package } from './Package';
import { LernaJson } from './LernaJson';
export declare const DEFAULT_LICENSE = "MIT";
export declare const DEFAULT_INITIAL_VERSION = "0.0.1";
export declare const DEFAULT_INITIAL_VERSION = "0.0.0";
export declare const DEFAULT_WORKSPACES_DIRECTORY = "packages";
export declare type CreateProjectOptions = {
scoped: boolean;
license: string;

@@ -11,8 +13,9 @@ initialVersion: string;

};
declare type ProjectTemplate = (project: Project, options: CreateProjectOptions) => Promise<void>;
declare type ProjectTemplate = (project: Project, options: CreateProjectOptions, plugins: Plugins) => Promise<void>;
export declare class Project extends Package {
static find(directory: string): undefined | Project;
get scoped(): boolean;
get lernaJson(): LernaJson;
static find(directory: string): Project;
create(templateFn: ProjectTemplate, options?: Partial<CreateProjectOptions>): Promise<void>;
}
export {};

@@ -18,8 +18,10 @@ "use strict";

const pkg_up_1 = require("pkg-up");
const __1 = require("..");
const Package_1 = require("./Package");
const LernaJson_1 = require("./LernaJson");
exports.DEFAULT_LICENSE = 'MIT';
exports.DEFAULT_INITIAL_VERSION = '0.0.1';
exports.DEFAULT_INITIAL_VERSION = '0.0.0';
exports.DEFAULT_WORKSPACES_DIRECTORY = 'packages';
const defaultOptions = {
scoped: false,
license: exports.DEFAULT_LICENSE,

@@ -30,11 +32,20 @@ initialVersion: exports.DEFAULT_INITIAL_VERSION,

class Project extends Package_1.Package {
get lernaJson() {
return new LernaJson_1.LernaJson(this.directory);
}
static find(directory) {
const root = pkg_up_1.sync({ cwd: directory });
if (root !== null) {
const pkg = new Package_1.Package(path_1.default.dirname(root));
if (!pkg.isRoot()) {
// Not a root project, proceed to parent directory
return Project.find(path_1.default.dirname(path_1.default.dirname(root)));
}
return new Project(path_1.default.dirname(root));
}
}
get scoped() {
var _a;
return !!((_a = this.packageJson.contents.mokr) === null || _a === void 0 ? void 0 : _a.scoped);
}
get lernaJson() {
return new LernaJson_1.LernaJson(this.directory);
}
create(templateFn, options = {}) {

@@ -47,3 +58,3 @@ return __awaiter(this, void 0, void 0, function* () {

const optionsWithDefaults = Object.assign({}, defaultOptions, options);
yield templateFn(this, optionsWithDefaults);
yield templateFn(this, optionsWithDefaults, __1.plugins);
});

@@ -50,0 +61,0 @@ }

@@ -7,4 +7,4 @@ export declare class TextFile {

get exists(): boolean;
get text(): string;
set text(contents: string);
get text(): string | null;
set text(contents: string | null);
}

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

set text(contents) {
fs_1.default.writeFileSync(this.path, contents.trim() + '\n');
fs_1.default.writeFileSync(this.path, (contents !== null && contents !== void 0 ? contents : '').trim() + '\n');
}

@@ -26,0 +26,0 @@ }

@@ -0,5 +1,6 @@

import { Plugins } from '..';
import { Project } from './Project';
import { Package } from './Package';
export declare type CreateWorkspaceOptions = {};
declare type WorkspaceTemplate = (workspace: Workspace, options: CreateWorkspaceOptions) => Promise<void>;
declare type WorkspaceTemplate = (workspace: Workspace, options: CreateWorkspaceOptions, plugins: Plugins) => Promise<void>;
export declare class Workspace extends Package {

@@ -9,4 +10,5 @@ project: Project;

constructor(project: Project, directory: string);
get name(): string;
create(templateFn: WorkspaceTemplate, options?: CreateWorkspaceOptions): Promise<void>;
}
export {};

@@ -16,2 +16,4 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const __1 = require("..");
const Package_1 = require("./Package");

@@ -24,2 +26,6 @@ class Workspace extends Package_1.Package {

}
get name() {
const name = path_1.default.basename(this.directory);
return this.project.scoped ? `@${this.project.name}/${name}` : name;
}
create(templateFn, options = {}) {

@@ -31,3 +37,3 @@ return __awaiter(this, void 0, void 0, function* () {

fs_1.default.mkdirSync(this.directory, { recursive: true });
yield templateFn(this, options);
yield templateFn(this, options, __1.plugins);
});

@@ -34,0 +40,0 @@ }

import { Package } from '..';
export declare function githubActions(pack: Package): Promise<void>;
export declare function githubActions(pkg: Package): Promise<void>;

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

Object.defineProperty(exports, "__esModule", { value: true });
function githubActions(pack) {
function githubActions(pkg) {
return __awaiter(this, void 0, void 0, function* () { });

@@ -15,0 +15,0 @@ }

export * from './githubActions';
export * from './jest';
export * from './npmPackage';
export * from './npmRootPackage';
export * from './readme';
export * from './typescript';
export * from './lerna';
export * from './gitignore';

@@ -9,5 +9,6 @@ "use strict";

__export(require("./npmPackage"));
__export(require("./npmRootPackage"));
__export(require("./readme"));
__export(require("./typescript"));
__export(require("./lerna"));
__export(require("./gitignore"));
//# sourceMappingURL=index.js.map

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

import { Package } from '..';
export declare function jest(pack: Package): Promise<void>;
import { Project, Workspace } from '../parts';
export declare function jest(pkg: Project | Workspace): Promise<void>;

@@ -12,6 +12,19 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function jest(pack) {
return __awaiter(this, void 0, void 0, function* () { });
function jest(pkg) {
return __awaiter(this, void 0, void 0, function* () {
if (pkg.isProject()) {
pkg.jestConfig.text = `module.exports = {\n
preset: 'ts-jest',\n
testMatch: '**/*.test.(ts|tsx)'\n
}\n
`;
pkg.packageJson.contents.scripts = Object.assign(Object.assign({}, pkg.packageJson.contents.scripts), { test: 'lerna run test', 'watch:test': 'lerna run --parallel watch:test' });
pkg.addDevDependency('jest ts-jest');
}
else {
pkg.packageJson.contents.scripts = Object.assign(Object.assign({}, pkg.packageJson.contents.scripts), { test: 'jest', 'watch:test': 'jest --watch' });
}
});
}
exports.jest = jest;
//# sourceMappingURL=jest.js.map
import { Package, PackageJsonSchema } from '..';
export declare function npmPackage(pack: Package, extraContents: Partial<PackageJsonSchema>): Promise<void>;
export declare function npmPackage(pkg: Package, contents: Partial<PackageJsonSchema>): Promise<void>;

@@ -12,7 +12,20 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function npmPackage(pack, extraContents) {
function npmPackage(pkg, contents) {
return __awaiter(this, void 0, void 0, function* () {
pack.gitignore.contents = ['node_modules/'];
pack.packageJson.contents = Object.assign({ name: pack.name, version: '0.0.1' }, extraContents);
pack.packageJson.addDevDependency('@types/node typescript jest ts-jest');
if (pkg.isProject()) {
pkg.packageJson.contents = Object.assign({ private: true, scripts: {
publish: 'lerna publish',
start: 'lerna run --parallel start',
dev: 'stmux -w always -e ERROR -m beep,system -- [ [ "yarn watch:build" .. "yarn watch:test" ] : -s 1/3 -f "yarn start" ]'
} }, contents);
}
else if (pkg.isWorkspace()) {
pkg.packageJson.contents = Object.assign({}, contents);
if (pkg.project.scoped) {
pkg.packageJson.contents.publishConfig = {
access: 'public'
};
}
pkg.addDevDependency('@types/node');
}
});

@@ -19,0 +32,0 @@ }

import { PackageJsonSchema, Project } from '..';
export declare function npmRootPackage(project: Project, extraContents: Partial<PackageJsonSchema>): Promise<void>;
export declare function npmRootPackage(project: Project, contents: Partial<PackageJsonSchema>): Promise<void>;

@@ -12,13 +12,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function npmRootPackage(project, extraContents) {
function npmRootPackage(project, contents) {
return __awaiter(this, void 0, void 0, function* () {
project.gitignore.contents = ['node_modules/'];
project.packageJson.contents = Object.assign({ private: true }, extraContents);
project.lernaJson.contents = {
version: extraContents.version,
packages: extraContents.workspaces,
npmClient: 'yarn',
useWorkspaces: true
};
yield project.packageJson.addRootDevDependency('lerna');
project.packageJson.contents = Object.assign({ private: true }, contents);
});

@@ -25,0 +17,0 @@ }

import { Package } from '..';
export declare function readme(pack: Package): Promise<void>;
export declare function readme(pkg: Package): Promise<void>;

@@ -13,5 +13,5 @@ "use strict";

const __1 = require("..");
function readme(pack) {
function readme(pkg) {
return __awaiter(this, void 0, void 0, function* () {
new __1.TextFile(pack.directory, 'README.md').text = `# ${pack.name}`;
new __1.TextFile(pkg.directory, 'README.md').text = `# ${pkg.name}`;
});

@@ -18,0 +18,0 @@ }

import { Package } from '..';
export declare function typescript(pack: Package): Promise<void>;
export declare function typescript(pkg: Package): Promise<void>;

@@ -12,12 +12,27 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function typescript(pack) {
function typescript(pkg) {
return __awaiter(this, void 0, void 0, function* () {
pack.tsconfigJson.contents.compilerOptions = {
target: 'ES2015',
module: 'CommonJS',
esModuleInterop: true,
lib: ['ESNext'],
declaration: true,
sourceMap: true
};
if (pkg.isProject()) {
pkg.tsconfigJson.contents.compilerOptions = {
strict: true,
target: 'ES2015',
module: 'CommonJS',
esModuleInterop: true,
lib: ['ESNext'],
declaration: true,
sourceMap: true
};
pkg.packageJson.contents.scripts = Object.assign(Object.assign({}, pkg.packageJson.contents.scripts), { build: 'lerna run build', 'watch:build': 'lerna run --parallel watch:build' });
}
else {
pkg.tsconfigJson.contents = {
extends: '../../tsconfig.json',
compilerOptions: {
rootDir: 'src',
outDir: 'lib'
}
};
pkg.packageJson.contents.scripts = Object.assign(Object.assign({}, pkg.packageJson.contents.scripts), { prepublishOnly: 'yarn build', build: 'tsc', 'watch:build': 'tsc --watch' });
pkg.addDevDependency('typescript');
}
});

@@ -24,0 +39,0 @@ }

import { Project, CreateProjectOptions } from '../..';
export declare function typescript(project: Project, options: CreateProjectOptions): Promise<void>;
export declare function typescript(project: Project, { scoped, license, initialVersion: version, workspacesDirectory }: CreateProjectOptions): Promise<void>;

@@ -13,11 +13,23 @@ "use strict";

const __1 = require("../..");
function typescript(project, options) {
function typescript(project, { scoped, license, initialVersion: version, workspacesDirectory }) {
return __awaiter(this, void 0, void 0, function* () {
yield __1.plugins.npmRootPackage(project, {
version: options.initialVersion,
workspaces: [`${options.workspacesDirectory}/*`],
license: options.license
const workspaces = [`${workspacesDirectory}/*`];
yield __1.plugins.npmPackage(project, {
name: project.name,
version,
license,
workspaces,
mokr: {
scoped
}
});
yield __1.plugins.lerna(project, {
version,
workspaces
});
yield __1.plugins.typescript(project);
yield __1.plugins.readme(project);
yield __1.plugins.gitignore(project);
yield __1.plugins.jest(project);
yield project.installQueue();
});

@@ -24,0 +36,0 @@ }

@@ -15,5 +15,13 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
yield __1.plugins.npmPackage(workspace, options);
yield __1.plugins.npmPackage(workspace, {
name: workspace.name,
version: workspace.project.packageJson.contents.version,
license: workspace.project.packageJson.contents.license,
main: 'lib/index.js',
files: ['lib']
});
yield __1.plugins.typescript(workspace);
yield __1.plugins.readme(workspace);
yield __1.plugins.jest(workspace);
yield workspace.installQueue();
});

@@ -20,0 +28,0 @@ }

@@ -6,3 +6,3 @@ declare type Options = {

};
export declare function exec(cmd: string, args?: any[], { cwd, env, io }?: Options): Promise<{
export declare function exec(cmd: string, args?: string[], { cwd, env, io }?: Options): Promise<{
status: number;

@@ -9,0 +9,0 @@ stdout: string;

@@ -32,12 +32,16 @@ "use strict";

let stderr = '';
child.stdout.on('data', function (chunk) {
stdout += chunk;
});
child.stderr.on('data', function (chunk) {
stdout += chunk;
});
if (child.stdout) {
child.stdout.on('data', function (chunk) {
stdout += chunk;
});
}
if (child.stderr) {
child.stderr.on('data', function (chunk) {
stdout += chunk;
});
}
const status = yield childAwaiter(child);
const result = { status, stdout, stderr };
if (status !== 0) {
const error = new Error(`exec [${cmd}] returned with an error`);
const error = new Error(`exec [${cmd}] returned with an error - ${JSON.stringify(result)}`);
Object.assign(error, result);

@@ -44,0 +48,0 @@ throw error;

export * from './assertions';
export * from './exec';
export * from './asyncForeach';

@@ -8,2 +8,3 @@ "use strict";

__export(require("./exec"));
__export(require("./asyncForeach"));
//# sourceMappingURL=index.js.map
{
"name": "@mokr/core",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"description": "Core Mokr functions",

@@ -20,9 +20,9 @@ "repository": "https://github.com/hongaar/mokr",

"dependencies": {
"pkg-up": "^3.1.0"
"pkg-up": "3.1.0"
},
"devDependencies": {
"@types/node": "^13.7.1",
"jest": "^25.1.0",
"ts-jest": "^25.2.0",
"typescript": "^3.7.5"
"@types/node": "13.9.0",
"jest": "25.1.0",
"ts-jest": "25.2.0",
"typescript": "3.8.3"
},

@@ -32,3 +32,3 @@ "publishConfig": {

},
"gitHead": "306c434c44dbfe6c23bfd45232699f0e5bf926b8"
"gitHead": "ea2f4a28bba5fa9fa3f3288c7f80f05e117b0b47"
}

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

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

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