@omlet/cli
Advanced tools
Comparing version 0.0.1-alpha.29 to 0.0.1-b5963e.0
@@ -35,2 +35,3 @@ export declare enum LogLevel { | ||
mtype: "package" | "local"; | ||
package_name: string; | ||
} | ||
@@ -43,2 +44,3 @@ interface SymbolWithSource { | ||
id: ComponentId; | ||
name: string; | ||
} | ||
@@ -75,3 +77,5 @@ interface ComponentDependency { | ||
name: string; | ||
updatedAt?: Date; | ||
package_name: string; | ||
created_at?: Date; | ||
updated_at?: Date; | ||
tags: string[]; | ||
@@ -87,6 +91,6 @@ source: SymbolWithSource; | ||
repo: { | ||
scope: string | undefined; | ||
url: string | undefined; | ||
name: string; | ||
branch: string; | ||
name?: string | undefined; | ||
url?: string | undefined; | ||
branch?: string | undefined; | ||
scope?: string | undefined; | ||
}; | ||
@@ -93,0 +97,0 @@ components: Component[]; |
@@ -54,2 +54,19 @@ "use strict"; | ||
} | ||
const CHUNK_SIZE = 20; | ||
function getComponentsCreatedDates(components, workspaceSlug, projectRoot) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const previousComponentCreatedDates = yield getLatestComponentsCreatedDates(workspaceSlug); | ||
const previousComponentCreatedDateMap = Object.fromEntries(previousComponentCreatedDates.map(c => [c.definitionId, c.createdAt])); | ||
const componentCreatedDates = []; | ||
for (let i = 0; i < components.length; i += CHUNK_SIZE) { | ||
const componentChunk = components.slice(i, i + CHUNK_SIZE); | ||
const dates = yield Promise.all(componentChunk.map(component => { | ||
var _a; | ||
return (_a = previousComponentCreatedDateMap[getComponentId(component.source)]) !== null && _a !== void 0 ? _a : (0, repoUtils_1.getFileCreated)(component.source.source.path, projectRoot); | ||
})); | ||
componentCreatedDates.push(...dates); | ||
} | ||
return componentCreatedDates; | ||
}); | ||
} | ||
function createGlobMatcher(patterns) { | ||
@@ -66,3 +83,3 @@ if (patterns.length) { | ||
const id = getComponentId(e); | ||
return Object.assign(Object.assign({}, e), { id }); | ||
return Object.assign(Object.assign({}, e), { name: getComponentName(e), id }); | ||
} | ||
@@ -75,3 +92,3 @@ return { | ||
} | ||
function transformComponent(nativeComp, globMatchers, projectRoot) { | ||
function transformComponent(nativeComp, globMatchers, projectRoot, createdAt) { | ||
const sws = nativeComp.source; | ||
@@ -88,4 +105,3 @@ let updatedAt; | ||
} | ||
return (Object.assign(Object.assign({}, nativeComp), { id: getComponentId(sws), name: getComponentName(sws), updatedAt, | ||
tags, dependencies: nativeComp.dependencies.map(transformDependency), reverse_dependencies: nativeComp.reverse_dependencies.map(transformDependency) })); | ||
return (Object.assign(Object.assign({}, nativeComp), { id: getComponentId(sws), name: getComponentName(sws), package_name: sws.source.package_name, created_at: createdAt, updated_at: updatedAt, tags, dependencies: nativeComp.dependencies.map(transformDependency), reverse_dependencies: nativeComp.reverse_dependencies.map(transformDependency) })); | ||
} | ||
@@ -100,10 +116,11 @@ function parse(projectRoot, options) { | ||
exports.parse = parse; | ||
function runAnalysis(projectRoot, options) { | ||
function runAnalysis(projectRoot, workspaceSlug, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const extractedAliasMap = JSON.stringify(yield (0, repoUtils_1.extractAliasConfig)(projectRoot, { tsconfig: options.tsconfigPath })); | ||
const result = JSON.parse((0, binding_1.analyze)(projectRoot, options.inputPatterns, options.ignorePatterns, options.verbose, options.logLevel, LOG_FILE_PATH, extractedAliasMap)); | ||
const componentCreatedDates = yield getComponentsCreatedDates(result.components, workspaceSlug, projectRoot); | ||
const globMatchers = [["core", createGlobMatcher(options.corePatterns)]]; | ||
globMatchers.push(...options.tagPatterns.map(([tag, pattern]) => [tag, createGlobMatcher([pattern])])); | ||
return { | ||
components: result.components.map(c => transformComponent(c, globMatchers, projectRoot)), | ||
components: result.components.map((c, index) => transformComponent(c, globMatchers, projectRoot, componentCreatedDates[index])), | ||
exports: result.exports | ||
@@ -152,12 +169,22 @@ }; | ||
} | ||
function getLatestComponentsCreatedDates(workspaceSlug) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield apiRequest(`/api/workspaces/${workspaceSlug}/components/created`); | ||
return data; | ||
}); | ||
} | ||
function analyze(projectRoot, options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d; | ||
var _e, _f, _g, _h; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const workspace = yield getDefaultWorkspace(); | ||
const repoInfo = yield (0, repoUtils_1.getRepoInfo)(projectRoot); | ||
const repoScope = (_b = (_a = options.repo) === null || _a === void 0 ? void 0 : _a.scope) !== null && _b !== void 0 ? _b : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.scope; | ||
const repoName = (_d = (_c = options.repo) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.name; | ||
const repoUrl = (_f = (_e = options.repo) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.url; | ||
const branch = (_h = (_g = options.repo) === null || _g === void 0 ? void 0 : _g.branch) !== null && _h !== void 0 ? _h : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.branch; | ||
if (!repoName || !branch) { | ||
if (!options.repo) { | ||
options.repo = {}; | ||
} | ||
(_a = (_e = options.repo).scope) !== null && _a !== void 0 ? _a : (_e.scope = repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.scope); | ||
(_b = (_f = options.repo).name) !== null && _b !== void 0 ? _b : (_f.name = repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.name); | ||
(_c = (_g = options.repo).url) !== null && _c !== void 0 ? _c : (_g.url = repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.url); | ||
(_d = (_h = options.repo).branch) !== null && _d !== void 0 ? _d : (_h.branch = repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.branch); | ||
if (!options.repo.name || !options.repo.branch) { | ||
throw new error_1.CliError("Repository name and current branch are required", { | ||
@@ -170,10 +197,5 @@ context: { | ||
} | ||
console.log(`Running analysis on ${repoName}@${branch} (${projectRoot})`); | ||
const result = yield runAnalysis(projectRoot, options); | ||
const analysisData = Object.assign(Object.assign({}, result), { repo: { | ||
scope: repoScope, | ||
url: repoUrl, | ||
name: repoName, | ||
branch | ||
} }); | ||
console.log(`Running analysis on ${options.repo.name}@${options.repo.branch} (${projectRoot})`); | ||
const result = yield runAnalysis(projectRoot, workspace.slug, options); | ||
const analysisData = Object.assign(Object.assign({}, result), { repo: options.repo }); | ||
if (options.output) { | ||
@@ -183,4 +205,4 @@ console.log(`Writing results to ${options.output}`); | ||
} | ||
const analysis = yield postAnalysis(workspace, analysisData); | ||
const url = new URL(`/${workspace.slug}/${analysis.repoSlug}`, config_1.BASE_URL).toString(); | ||
yield postAnalysis(workspace, analysisData); | ||
const url = new URL(`/${workspace.slug}`, config_1.BASE_URL).toString(); | ||
console.log(`Analysis submitted successfully: ${url}`); | ||
@@ -187,0 +209,0 @@ return { |
@@ -8,2 +8,3 @@ export interface RepositoryInfo { | ||
export declare function getRepoInfo(repoPath: string): Promise<RepositoryInfo | undefined>; | ||
export declare function getFileCreated(filePath: string, cwd: string): Promise<Date | undefined>; | ||
export declare function getFileUpdated(filePath: string, cwd: string): Date | undefined; | ||
@@ -10,0 +11,0 @@ interface AliasConfig { |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extractAliasConfig = exports.getFileUpdated = exports.getRepoInfo = void 0; | ||
exports.extractAliasConfig = exports.getFileUpdated = exports.getFileCreated = exports.getRepoInfo = void 0; | ||
const child_process_1 = require("child_process"); | ||
@@ -96,2 +96,18 @@ const fs_1 = require("fs"); | ||
exports.getRepoInfo = getRepoInfo; | ||
const fileCreatedCache = {}; | ||
function getFileCreated(filePath, cwd) { | ||
return new Promise(resolve => { | ||
if (fileCreatedCache[filePath]) { | ||
return resolve(fileCreatedCache[filePath]); | ||
} | ||
(0, child_process_1.exec)(`git log --follow --format=%aI -- ${filePath} | tail -1`, { cwd }, (error, stdout) => { | ||
if (error) { | ||
return resolve(undefined); | ||
} | ||
fileCreatedCache[filePath] = new Date(stdout.trim()); | ||
resolve(fileCreatedCache[filePath]); | ||
}); | ||
}); | ||
} | ||
exports.getFileCreated = getFileCreated; | ||
const fileUpdatedCache = {}; | ||
@@ -98,0 +114,0 @@ function getFileUpdated(filePath, cwd) { |
{ | ||
"name": "@omlet/cli", | ||
"version": "0.0.1-alpha.29", | ||
"version": "0.0.1-b5963e.0", | ||
"bin": { | ||
@@ -5,0 +5,0 @@ "omlet": "bin/omlet" |
{ | ||
"name": "@omlet/cli", | ||
"version": "0.0.1-alpha.29", | ||
"version": "0.0.1-b5963e.0", | ||
"bin": { | ||
@@ -68,8 +68,8 @@ "omlet": "bin/omlet" | ||
"optionalDependencies": { | ||
"@omlet/cli-darwin-arm64": "0.0.1-alpha.29", | ||
"@omlet/cli-darwin-x64": "0.0.1-alpha.29", | ||
"@omlet/cli-linux-x64-gnu": "0.0.1-alpha.29", | ||
"@omlet/cli-linux-x64-musl": "0.0.1-alpha.29", | ||
"@omlet/cli-linux-arm64-gnu": "0.0.1-alpha.29", | ||
"@omlet/cli-linux-arm64-musl": "0.0.1-alpha.29" | ||
"@omlet/cli-darwin-arm64": "0.0.1-b5963e.0", | ||
"@omlet/cli-darwin-x64": "0.0.1-b5963e.0", | ||
"@omlet/cli-linux-x64-gnu": "0.0.1-b5963e.0", | ||
"@omlet/cli-linux-x64-musl": "0.0.1-b5963e.0", | ||
"@omlet/cli-linux-arm64-gnu": "0.0.1-b5963e.0", | ||
"@omlet/cli-linux-arm64-musl": "0.0.1-b5963e.0" | ||
}, | ||
@@ -76,0 +76,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54908
1214