Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jul 12, 2024
1 parent c7ef94d commit dd7149b
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 86 deletions.
3 changes: 1 addition & 2 deletions examples/bitcoin_psbt/scripts/bitcoin/transaction_count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execSync } = require('child_process');
import { execSync } from 'child_process';

const CLI = '.bitcoin/bin/bitcoin-cli -conf=$(pwd)/.bitcoin.conf';

Expand Down
6 changes: 2 additions & 4 deletions scripts/add_metadata_to_dfx_json.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

const targetDirectory = process.argv[2] || '.'; // Use the provided directory or default to the current directory

Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/add_example_dependency.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Get the current directory name
const currentDirectory = path.basename(process.cwd());
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/change_to_custom_candid_gen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Path to the dfx.json file
const dfxJsonPath = path.join(process.cwd(), 'dfx.json');
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/clean_package.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Directories to be removed
const directoriesToRemove = ['node_modules', '.azle', '.dfx'];
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/copy_generated_candid_from_example.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Helper function to copy a file from src to dest
const copyFile = (src, dest) => {
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/delete_tests_file.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Path to the tests.ts file
const testsFilePath = path.join(process.cwd(), 'test', 'tests.ts');
Expand Down
11 changes: 5 additions & 6 deletions scripts/class_migration/do_all_packages.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { exec } = require('child_process');
#!/usr/bin/env node

import { exec } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';

// Get the current directory name
const currentDirectory = process.cwd();
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/modify_pretest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Path to the pretest.ts file
const pretestFilePath = path.join(process.cwd(), 'test', 'pretest.ts');
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/name_package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Get the current directory name
const currentDirectory = path.basename(process.cwd());
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/update_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Get the current directory name
const currentDirectory = path.basename(process.cwd());
Expand Down
6 changes: 2 additions & 4 deletions scripts/class_migration/update_ts_config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Path to the tsconfig.json file
const tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
Expand Down
9 changes: 3 additions & 6 deletions scripts/class_migration/update_typescript.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { exec } = require('child_process');
import { exec } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';

const tsVersion = '^5.2.2';

Expand Down
12 changes: 2 additions & 10 deletions scripts/file_generator/bin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#!/usr/bin/env node

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('ts-node').register({
transpileOnly: true,
ignore: [`node_modules/(?!azle)`],
compilerOptions: {
module: 'commonjs',
allowJs: true
}
});
require('./main.ts');
import 'tsx';
import('./main.ts');
12 changes: 2 additions & 10 deletions scripts/hash_file/bin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#!/usr/bin/env node

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('ts-node').register({
transpileOnly: true,
ignore: [`node_modules/(?!azle)`],
compilerOptions: {
module: 'commonjs',
allowJs: true
}
});
require('./main.ts');
import 'tsx';
import('./main.ts');
6 changes: 2 additions & 4 deletions scripts/reorder_dfx_json.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs-extra');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs-extra';
import * as path from 'path';

// Helper function to reorder keys in an object.
const reorderKeys = (obj, order) => {
Expand Down
6 changes: 2 additions & 4 deletions scripts/simplify_tsconfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs-extra');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs-extra';
import * as path from 'path';

// Read directory.
const dirPath = './examples/motoko_examples'; // Replace with the path to the directory containing folders with tsconfig.json files
Expand Down
76 changes: 76 additions & 0 deletions scripts/tsx_migration/ts_node_to_tsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import * as fs from 'fs';
import * as path from 'path';

// Path to the package.json file
const packageJsonPath = path.join(process.cwd(), 'package.json');

// Helper function to sort an object by its keys
const sortObjectByKeys = (obj) => {
return Object.keys(obj)
.sort()
.reduce((result, key) => {
result[key] = obj[key];
return result;
}, {});
};

// Read and parse package.json
fs.readFile(packageJsonPath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading package.json file: ${err}`);
return;
}

let packageJson;
try {
packageJson = JSON.parse(data);
} catch (parseErr) {
console.error(`Error parsing package.json: ${parseErr}`);
return;
}

const tsxVersion = '^4.15.7';
let tsNodeRemoved = false;

// Check and update dependencies
if (packageJson.dependencies && packageJson.dependencies['ts-node']) {
delete packageJson.dependencies['ts-node'];
packageJson.dependencies['tsx'] = tsxVersion;
packageJson.dependencies = sortObjectByKeys(packageJson.dependencies);
tsNodeRemoved = true;
}

// Check and update devDependencies
if (packageJson.devDependencies && packageJson.devDependencies['ts-node']) {
delete packageJson.devDependencies['ts-node'];
packageJson.devDependencies['tsx'] = tsxVersion;
packageJson.devDependencies = sortObjectByKeys(
packageJson.devDependencies
);
tsNodeRemoved = true;
}

if (!tsNodeRemoved) {
console.log('ts-node not found in dependencies or devDependencies.');
return;
}

// Write the updated package.json back to the file
fs.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
'utf8',
(writeErr) => {
if (writeErr) {
console.error(
`Error writing updated package.json: ${writeErr}`
);
return;
}

console.log('package.json successfully updated.');
}
);
});
6 changes: 2 additions & 4 deletions scripts/update_dfx_json_main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
import * as fs from 'fs';
import * as path from 'path';

// Helper function to update the canister definition
function updateCanister(canister) {
Expand Down

0 comments on commit dd7149b

Please sign in to comment.