Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojacobi committed Jul 16, 2024
1 parent 6059f60 commit 7d6bd66
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 66 deletions.
17 changes: 8 additions & 9 deletions automation/build-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@ import { promisify } from 'util';
import { notarize } from '@electron/notarize';

import { stripIndent } from '../lib/utils/lazy';
import {
diffLines,
loadPackageJson,
ROOT,
StdOutTap,
whichSpawn,
} from './utils';
import { diffLines, ROOT, StdOutTap, whichSpawn } from './utils';
import { filterCliOutputForTests, monochrome } from '../tests/helpers';

const execFileAsync = promisify(execFile);
const execAsync = promisify(exec);

export const packageJSON = loadPackageJson();
import pjson from '../package.json' with { type: 'json' };
export const packageJSON = pjson;
export const version = 'v' + packageJSON.version;
const arch = process.arch;

Expand Down Expand Up @@ -172,7 +167,11 @@ async function execPkg(...args: any[]) {
throw err;
}
outTap.untap();
await diffPkgOutput(outTap.allBuf.join(''));
try {
await diffPkgOutput(outTap.allBuf.join(''));
} catch (err) {
console.error('diff on pkg warnings', err);
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions automation/capitanodoc/capitanodoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import * as path from 'path';
import { MarkdownFileParser } from './utils';
import { MarkdownFileParser } from './utils.js';
import { GlobSync } from 'glob';

/**
Expand Down Expand Up @@ -82,13 +82,13 @@ const commandHeadings: { [key: string]: string } = {
};

// Fetch all available commands
const allCommandsPaths = new GlobSync('build/commands/**/*.js', {
ignore: 'build/commands/internal/**',
const allCommandsPaths = new GlobSync('build/lib/commands/**/*.js', {
ignore: 'build/lib/commands/internal/**',
}).found;

// Throw error if any commands found outside of command directories
const illegalCommandPaths = allCommandsPaths.filter((commandPath: string) =>
/^build\/commands\/[^/]+\.js$/.test(commandPath),
/^build\/lib\/commands\/[^/]+\.js$/.test(commandPath),
);

if (illegalCommandPaths.length !== 0) {
Expand Down
8 changes: 4 additions & 4 deletions automation/capitanodoc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/
import * as path from 'path';
import { getCapitanoDoc } from './capitanodoc';
import type { Category, Document, OclifCommand } from './doc-types';
import * as markdown from './markdown';
import { stripIndent } from '../../lib/utils/lazy';
import { getCapitanoDoc } from './capitanodoc.js';
import type { Category, Document, OclifCommand } from './doc-types.js';
import * as markdown from './markdown.js';
import { stripIndent } from '../../lib/utils/lazy.js';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

Expand Down
2 changes: 1 addition & 1 deletion automation/capitanodoc/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Parser } from '@oclif/core';
import * as ent from 'ent';
import ent from 'ent';
import _ from 'lodash';

import { getManualSortCompareFunction } from '../../lib/utils/helpers';
Expand Down
20 changes: 0 additions & 20 deletions automation/capitanodoc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

import type { OptionDefinition } from 'capitano';
import * as ent from 'ent';
import * as fs from 'fs';
import * as readline from 'readline';

Expand All @@ -32,24 +30,6 @@ export function getOptionSignature(signature: string) {
return `${getOptionPrefix(signature)}${signature}`;
}

export function parseCapitanoOption(option: OptionDefinition): string {
let result = getOptionSignature(option.signature);

if (Array.isArray(option.alias)) {
for (const alias of option.alias) {
result += `, ${getOptionSignature(alias)}`;
}
} else if (typeof option.alias === 'string') {
result += `, ${getOptionSignature(option.alias)}`;
}

if (option.parameter) {
result += ` <${option.parameter}>`;
}

return ent.encode(result);
}

export class MarkdownFileParser {
constructor(public mdFilePath: string) {}

Expand Down
4 changes: 0 additions & 4 deletions automation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ export function diffLines(str1: string, str2: string): string {
return diffStr;
}

export function loadPackageJson() {
return require(path.join(ROOT, 'package.json'));
}

/**
* Error handling wrapper around the npm `which` package:
* "Like the unix which utility. Finds the first instance of a specified
Expand Down
40 changes: 20 additions & 20 deletions bin/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ process.on('SIGINT', function () {
});

// Modify package.json oclif paths from build/ -> lib/, or vice versa
// function modifyOclifPaths(revert) {
// const packageJsonPath = path.join(rootDir, 'package.json');
function modifyOclifPaths(revert) {
const packageJsonPath = path.join(rootDir, 'package.json');

// const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
// const packageObj = JSON.parse(packageJson);
const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
const packageObj = JSON.parse(packageJson);

// if (!packageObj.oclif) {
// return;
// }
if (!packageObj.oclif) {
return;
}

// let oclifSectionText = JSON.stringify(packageObj.oclif);
// if (!revert) {
// oclifSectionText = oclifSectionText.replace(/\/build\//g, '/lib/');
// } else {
// oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/');
// }
let oclifSectionText = JSON.stringify(packageObj.oclif);
if (!revert) {
oclifSectionText = oclifSectionText.replace(/\/build\/lib\//g, '/lib/');
} else {
oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/lib/');
}

// packageObj.oclif = JSON.parse(oclifSectionText);
// fs.writeFileSync(
// packageJsonPath,
// `${JSON.stringify(packageObj, null, 2)}\n`,
// 'utf8',
// );
// }
packageObj.oclif = JSON.parse(oclifSectionText);
fs.writeFileSync(
packageJsonPath,
`${JSON.stringify(packageObj, null, 2)}\n`,
'utf8',
);
}
2 changes: 1 addition & 1 deletion lib/auth/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as bodyParser from 'body-parser';
import bodyParser from 'body-parser';
import { EventEmitter } from 'events';
import express from 'express';
import type { Socket } from 'net';
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export default class VersionCmd extends Command {
public async run() {
const { flags: options } = await this.parse(VersionCmd);
const versions: JsonVersions = {
'balena-cli': (await import('../../../package.json')).default.version,
'balena-cli': (
await import('../../../package.json', { with: { type: 'json' } })
).default.version,
'Node.js':
process.version && process.version.startsWith('v')
? process.version.slice(1)
Expand Down
4 changes: 3 additions & 1 deletion lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ See: https://git.io/JRHUW#deprecation-policy`,
];
globalOps[0][0] = globalOps[0][0].padEnd(usageLength);

const { deprecationPolicyNote, reachingOut } = await import('./utils/messages.js');
const { deprecationPolicyNote, reachingOut } = await import(
'./utils/messages.js'
);

return [
bold('USAGE'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"build": "npm run build:src && npm run catch-uncommitted",
"build:t": "npm run lint && npm run build:fast && npm run build:test",
"build:src": "npm run lint && npm run build:fast && npm run build:test && npm run build:doc && npm run build:completion",
"build:pages": "mkdirp ./build/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/auth/pages/success.ejs",
"build:pages": "mkdirp ./build/lib/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/lib/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/lib/auth/pages/success.ejs",
"build:fast": "npm run build:pages && tsc && npx oclif manifest",
"build:test": "tsc -P ./tsconfig.dev.json --noEmit",
"build:doc": "ts-node --transpile-only automation/capitanodoc/index.ts > docs/balena-cli.md",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"removeComments": true,
"sourceMap": true,
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"typeRoots": [
"./node_modules/@types",
Expand Down

0 comments on commit 7d6bd66

Please sign in to comment.