Convert scripts to Node
ADD
scripts/_constants.cjs
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+const path = require('path');
+
+exports.root = path.join(__dirname, '..');
+exports.packages = path.join(exports.root, 'packages', '@romejs');
+exports.generatorsFolder = path.join(
+ exports.packages,
+ 'js-generator',
+ 'generators',
+);
+exports.analysisFolder = path.join(
+ exports.packages,
+ 'js-analysis',
+ 'evaluators',
+);
+exports.astFolder = path.join(exports.packages, 'js-ast');
+exports.argv = process.argv.slice(2);

RENAME
scripts/ast/_utils.cjs
scripts/_utils.cjs
* LICENSE file in the root directory of this source tree.
*/
+const child = require('child_process');
const path = require('path');
const fs = require('fs');
-exports.write = function write(loc, content) {
+exports.unlink = function(loc) {
+ if (!fs.existsSync(loc)) {
+ return;
+ }
+
+ const stats = fs.lstatSync(loc);
+ if (stats.isFile()) {
+ fs.unlinkSync(loc);
+ } else if (stats.isDirectory()) {
+ for (const filename of fs.readdirSync(loc)) {
+ exports.unlink(path.join(loc, filename));
+ }
+ fs.rmdirSync(loc);
+ }
+};
+
+exports.exec = function(cmd, args) {
+ const res = child.spawnSync(cmd, args, {
+ stdio: 'inherit',
+ });
+ if (res.status !== 0) {
+ process.exit(1);
+ }
+};
+
+exports.execNode = function(args) {
+ exports.exec(process.execPath, [...process.execArgv, ...args]);
+};
+
+exports.write = function(loc, content) {
console.log('Wrote', loc);
fs.mkdirSync(path.dirname(loc), {recursive: true});
fs.writeFileSync(loc, content);

DELETE
scripts/ast/_constants.cjs
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-const path = require('path');
-
-const root = path.join(__dirname, '..', '..');
-const packages = path.join(root, 'packages', '@romejs');
-const generatorsFolder = path.join(packages, 'js-generator', 'generators');
-const analysisFolder = path.join(packages, 'js-analysis', 'evaluators');
-const astFolder = path.join(packages, 'js-ast');
-
-module.exports = {
- root,
- packages,
- generatorsFolder,
- analysisFolder,
- astFolder,
-};

MODIFY
scripts/ast/add.cjs
scripts/ast/add.cjs
@@ -12,9 +12,9 @@ const {
generatorsFolder,
analysisFolder,
astFolder,
-} = require('./_constants.cjs');
+} = require('../_constants.cjs');
-const {write, getBuilderName} = require('./_utils.cjs');
+const {write, getBuilderName} = require('../_utils.cjs');
const nodeType = process.argv[2];
const category = process.argv[3];

MODIFY
scripts/ast/remove.cjs
scripts/ast/remove.cjs
@@ -18,7 +18,7 @@ const {
generatorsFolder,
analysisFolder,
astFolder,
-} = require('./_constants.cjs');
+} = require('../_constants.cjs');
fs.unlinkSync(path.join(generatorsFolder, filename + '.ts'));
fs.unlinkSync(path.join(analysisFolder, filename + '.ts'));

MODIFY
scripts/ast/rename.cjs
scripts/ast/rename.cjs
@@ -29,7 +29,7 @@ const {
generatorsFolder,
analysisFolder,
astFolder,
-} = require('./_constants.cjs');
+} = require('../_constants.cjs');
rename(
path.join(generatorsFolder, fromType + '.ts'),

MODIFY
scripts/ast/update.cjs
scripts/ast/update.cjs
const path = require('path');
const fs = require('fs');
-const {write, getBuilderName} = require('./_utils.cjs');
+const {write, getBuilderName} = require('../_utils.cjs');
const {
generatorsFolder,
analysisFolder,
astFolder,
-} = require('./_constants.cjs');
+} = require('../_constants.cjs');
let defs = [];

MODIFY
scripts/build-release
scripts/build-release
-#!/bin/bash
+#!/usr/bin/env node
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
-set -e
+const {root, argv} = require('./_constants.cjs');
+const {execNode} = require('./_utils.cjs');
+const path = require('path');
+const PKG_ROOT = path.join(root, 'packages/rome');
-CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-ROME_ROOT="$CURR_DIR/.."
-PKG_ROOT="$ROME_ROOT/packages/rome"
-
-"$ROME_ROOT/scripts/dev-rome" bundle "$PKG_ROOT" $1
+execNode([path.join(__dirname, 'dev-rome'), 'bundle', PKG_ROOT, ...argv]);

MODIFY
scripts/commit-rome
scripts/commit-rome
-#!/bin/bash
+#!/usr/bin/env node
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
-set -e
+const {root} = require('./_constants.cjs');
+const {execNode, unlink} = require('./_utils.cjs');
+const path = require('path');
+const fs = require('fs');
+const os = require('os');
-CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-ROME_ROOT="$CURR_DIR/.."
+const TEMP_DIR = path.join(os.tmpdir(), 'vendor-rome');
-cd "$ROME_ROOT"
+execNode([path.join(__dirname, 'build-release'), TEMP_DIR]);
-TEMP_DIR=$(mktemp -d)
+const VENDOR_ROME = path.join(root, 'scripts/vendor/rome.cjs');
+fs.copyFileSync(path.join(TEMP_DIR, 'bin/rome/index.js'), VENDOR_ROME);
+fs.copyFileSync(
+ path.join(TEMP_DIR, 'bin/rome/index.js.map'),
+ `${VENDOR_ROME}.map`,
+);
-"$ROME_ROOT/scripts/build-release" "$TEMP_DIR"
-rm -rf /tmp/rome-*
-
-VENDOR_ROME="$ROME_ROOT/scripts/vendor/rome.cjs"
-cp "$ROME_ROOT/scripts/vendor/COPYRIGHT_HEADER" "$VENDOR_ROME"
-cat "$TEMP_DIR/bin/rome/index.js" >"$VENDOR_ROME"
-mv "$TEMP_DIR/bin/rome/index.js.map" "$VENDOR_ROME.map"
-rm -rf "$TEMP_DIR"
+unlink(TEMP_DIR);

MODIFY
scripts/dev-rome
scripts/dev-rome
-#!/bin/bash
+#!/usr/bin/env node
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
-set -e
+const {root, argv} = require('./_constants.cjs');
+const {unlink, execNode} = require('./_utils.cjs');
+const path = require('path');
+const fs = require('fs');
-CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-ROME_ROOT="$CURR_DIR/.."
-DEV_FOLDER="/tmp/rome-dev"
-export ROME_CACHE=0
+const DEV_FOLDER = '/tmp/rome-dev';
-rm -rf "$DEV_FOLDER"
-mkdir "$DEV_FOLDER"
+process.env.ROME_CACHE = '0';
-echo "Building trunk"
-"$ROME_ROOT/scripts/vendor-rome" bundle "$ROME_ROOT/packages/@romejs/cli/bin/rome.ts" "$DEV_FOLDER"
+unlink(DEV_FOLDER);
+fs.mkdirSync(DEV_FOLDER);
-echo "Executing trunk"
-"$CURR_DIR/node" "$DEV_FOLDER/index.js" $@
+console.log('Building trunk');
+execNode([
+ path.join(__dirname, 'vendor/rome.cjs'),
+ 'bundle',
+ path.join(root, 'packages/@romejs/cli/bin/rome.ts'),
+ DEV_FOLDER,
+]);
+
+console.log('Executing trunk');
+execNode([path.join(DEV_FOLDER, 'index.js'), ...argv]);

DELETE
scripts/node
-#!/bin/bash
-
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-
-NODE_VERSION=$(node --version)
-NODE_VERSION=${NODE_VERSION%%.*}
-
-if [[ ${NODE_VERSION:1} -ge 12 ]]; then
- node --no-warnings --max_old_space_size=4096 $@
-else
- echo "Expected a Node version later than v12 but got $NODE_VERSION"
- exit 1
-fi
-

MODIFY
scripts/prettier-check
scripts/prettier-check
-#!/bin/bash
+#!/usr/bin/env node
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
-./node_modules/.bin/prettier --check "packages/**/*.ts" --ignore-path ./scripts/.prettierignore
+const {root} = require('./_constants.cjs');
+const {execNode} = require('./_utils.cjs');
+const path = require('path');
+
+execNode([
+ path.join(root, 'node_modules/.bin/prettier'),
+ '--check',
+ 'packages/**/*.ts',
+ '--ignore-path',
+ path.join(__dirname, '.prettierignore'),
+]);

MODIFY
scripts/prettier-format
scripts/prettier-format
-#!/bin/bash
+#!/usr/bin/env node
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
-./node_modules/.bin/prettier --write "packages/**/*.ts" --ignore-path ./scripts/.prettierignore
+const {root} = require('./_constants.cjs');
+const {execNode} = require('./_utils.cjs');
+const path = require('path');
+
+execNode([
+ path.join(root, 'node_modules/.bin/prettier'),
+ '--write',
+ 'packages/**/*.ts',
+ '--ignore-path',
+ path.join(__dirname, '.prettierignore'),
+]);

DELETE
scripts/ts-vscode
-#!/bin/sh
-
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-
-OUT=$(./node_modules/.bin/tsc --noEmit)
-MATCH_LINES=$(echo "$OUT" | grep -E ".(tsx|ts)\(")
-ERRORED_FILES=$(echo "$MATCH_LINES" | cut -f1 -d"(" | uniq)
-if [ "$ERRORED_FILES" = "" ]; then
- echo "No errors"
-else
- echo "$ERRORED_FILES"
- code $ERRORED_FILES
- tsc --noEmit
-fi

Convert scripts to Node