Skip to content

Commit

Permalink
Grok Tools: Publish: publish all to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ssSavenko committed Oct 28, 2024
1 parent 1dbfc25 commit 719efcb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 54 deletions.
1 change: 1 addition & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Features

* Replaced publishAll by publuish variables
* Added global.d.ts file

## 4.13.31 (2024-10-15)
Expand Down
18 changes: 2 additions & 16 deletions tools/bin/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { publishAll } from "./publish-all";
import { testAll } from "./test-all";

const HELP = `
Expand Down Expand Up @@ -118,27 +117,15 @@ Options:
Running \`grok publish\` is the same as running \`grok publish defaultHost --build --debug\`
`;

const HELP_PUBLISHALL = `
Usage: grok publishAll
Upload all packages
Options:
[--host] [--release] [--link-package] [--skip-build]
--host Host alias as in the config file
--release Publish cureent version as release version
--skip-build Skip the package build step
--link-package Link local packages
`;

const HELP_CHECK = `
Usage: grok check
Options:
[-r | --recursive]
--recursive Check all packages in the current directory
--all Publish all available packages
--refresh Publish all available already loaded packages
Check package content (function signatures, import statements of external modules, etc.)
`;
Expand Down Expand Up @@ -226,7 +213,6 @@ export const help = {
init: HELP_INIT,
link: HELP_LINK,
publish: HELP_PUBLISH,
publishAll: HELP_PUBLISHALL,
test: HELP_TEST,
testAll: HELP_TESTALL,
help: HELP,
Expand Down
28 changes: 0 additions & 28 deletions tools/bin/commands/publish-all.ts

This file was deleted.

43 changes: 37 additions & 6 deletions tools/bin/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import yaml from 'js-yaml';
import { checkImportStatements, checkFuncSignatures, extractExternals, checkPackageFile, checkChangelog } from './check';
import * as utils from '../utils/utils';
import { Indexable } from '../utils/utils';
import { loadPackages } from "../utils/test-utils";
import * as color from '../utils/color-utils';

const { exec } = require('child_process');
Expand All @@ -18,19 +19,22 @@ const grokDir = path.join(os.homedir(), '.grok');
const confPath = path.join(grokDir, 'config.yaml');
const confTemplateDir = path.join(path.dirname(path.dirname(__dirname)), 'config-template.yaml');
const confTemplate = yaml.load(fs.readFileSync(confTemplateDir, { encoding: 'utf-8' }));
const curDir = process.cwd();
let curDir = process.cwd();
const packDir = path.join(curDir, 'package.json');
const packageFiles = [
'src/package.ts', 'src/detectors.ts', 'src/package.js', 'src/detectors.js',
'src/package-test.ts', 'src/package-test.js', 'package.js', 'detectors.js',
];
const config = yaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' })) as utils.Config;

export async function processPackage(debug: boolean, rebuild: boolean, host: string, devKey: string, packageName: any, suffix?: string) {
// Get the server timestamps
let timestamps: Indexable = {};
let url = `${host}/packages/dev/${devKey}/${packageName}`;
if (debug) {
try {
console.log(url);

timestamps = await (await fetch(url + '/timestamps')).json();
if (timestamps['#type'] === 'ApiError') {
color.error(timestamps.message);
Expand Down Expand Up @@ -199,7 +203,33 @@ export async function processPackage(debug: boolean, rebuild: boolean, host: str
return 0;
}

export function publish(args: PublishArgs) {
export async function publish(args: PublishArgs) {

if (args.refresh || args.all) {
if (path.basename(curDir) !== 'packages')
curDir = path.dirname(curDir);

let host = config.default;
if (args['_'].length === 2)
host = args['_'][1];
utils.setHost(host, config);

let baseUrl = config['servers'][host]['url'];
let url = `${baseUrl}/info/packages`;

let packagesToLoad =['all']
console.log(url);
if (args.refresh)
packagesToLoad = Object.keys(await (await fetch(url)).json());
console.log('Loading packages:');
await loadPackages(curDir, packagesToLoad.join(' '), host, false, false, false, args.release);
}
else {
await publishPackage(args);
}
}

async function publishPackage(args: PublishArgs) {
const nOptions = Object.keys(args).length - 1;
const nArgs = args['_'].length;

Expand All @@ -222,7 +252,6 @@ export function publish(args: PublishArgs) {
if (!fs.existsSync(grokDir)) fs.mkdirSync(grokDir);
if (!fs.existsSync(confPath)) fs.writeFileSync(confPath, yaml.dump(confTemplate));

const config = yaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' })) as utils.Config;
let host = config.default;
const urls = utils.mapURL(config);
if (nArgs === 2) host = args['_'][1];
Expand Down Expand Up @@ -264,10 +293,10 @@ export function publish(args: PublishArgs) {
console.error(`Standard Error: ${stderr}`);
return;
}
if(!args.suffix && stdout)
args.suffix = stdout.toString().substring(0,8);
if (!args.suffix && stdout)
args.suffix = stdout.toString().substring(0, 8);
});
await utils.delay(100);
await utils.delay(100);
code = await processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
} catch (error) {
console.error(error);
Expand All @@ -288,4 +317,6 @@ interface PublishArgs {
release?: boolean,
key?: string,
suffix?: string,
all?: boolean,
refresh?: boolean
}
1 change: 0 additions & 1 deletion tools/bin/grok.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const commands = {
publish: require('./commands/publish').publish,
test: require('./commands/test').test,
testall: require('./commands/test-all').testAll,
publishall: require('./commands/publish-all').publishAll,
};

const command = argv['_'][0];
Expand Down
5 changes: 3 additions & 2 deletions tools/bin/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export async function loadPackages(packagesDir: string, packagesToLoad?: string,
let hostString = host === undefined ? `` : `${host}`;
if (packagesToLoad !== "all") {
for (let pacakgeName of (packagesToLoad ?? "").split(' ')) {
packagesToRun.set(spaceToCamelCase(pacakgeName).toLocaleLowerCase(), false);
if((pacakgeName ?? '').length !== 0)
packagesToRun.set(spaceToCamelCase(pacakgeName).toLocaleLowerCase(), false);
}
}

Expand All @@ -167,7 +168,7 @@ export async function loadPackages(packagesDir: string, packagesToLoad?: string,

try {
const packageJsonData = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), { encoding: 'utf-8' }));
const packageFriendlyName = packagesToRun.get(spaceToCamelCase(packageJsonData["friendlyName"] ?? packageJsonData["name"].split("/")[1]).toLocaleLowerCase() ?? "");
const packageFriendlyName = packagesToRun.get(spaceToCamelCase(packageJsonData["friendlyName"] ?? packageJsonData["name"].split("/")[1] ?? packageJsonData["name"]?? '').toLocaleLowerCase() ?? "");

if (utils.isPackageDir(packageDir) && (packageFriendlyName !== undefined || packagesToLoad === "all")) {
try {
Expand Down
3 changes: 2 additions & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@babel/plugin-transform-runtime": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "7.15.0",
"@datagrok-misc/eslint-plugin-config": "^1.0.0",
"@types/ignore-walk": "^4.0.3",
"@types/inquirer": "^8.2.10",
"@types/js-yaml": "^4.0.9",
Expand All @@ -60,4 +61,4 @@
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
}
}
}

0 comments on commit 719efcb

Please sign in to comment.