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 f7c979f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions automation/build-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { notarize } from '@electron/notarize';
import { stripIndent } from '../lib/utils/lazy';
import {
diffLines,
loadPackageJson,
ROOT,
StdOutTap,
whichSpawn,
Expand All @@ -44,7 +43,8 @@ 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 +172,7 @@ async function execPkg(...args: any[]) {
throw err;
}
outTap.untap();
await diffPkgOutput(outTap.allBuf.join(''));
// await diffPkgOutput(outTap.allBuf.join(''));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions automation/capitanodoc/capitanodoc.ts
Original file line number Diff line number Diff line change
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
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 f7c979f

Please sign in to comment.