Skip to content

Commit

Permalink
ci(): migrate scripts to es6 modules (#8266)
Browse files Browse the repository at this point in the history
* convert to modules

* rename cmd
  • Loading branch information
ShaMan123 authored Sep 11, 2022
1 parent 268d092 commit 8663b2c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
},
"license": "MIT",
"scripts": {
"cli": "node ./scripts/index.mjs",
"changelog": "auto-changelog -o change-output.md --unreleased-only",
"build": "node ./scripts build",
"build": "npm run cli -- build",
"build:fast": "npm run build -- -f",
"fabric": "node ./scripts",
"dev": "node ./scripts dev",
"start": "node ./scripts start",
"export": "node ./scripts website export",
"dev": "npm run cli -- dev",
"start": "npm run cli -- start",
"export": "npm run cli -- website export",
"build-tests": "rollup -c ./rollup.test.config.js",
"test:unit-browser": "npm run test -- -s unit -p 8080 -l -c ",
"test:visual-browser": "npm run test -- -s visual -p 8080 -l -c ",
"test": "node ./scripts test",
"test": "npm run cli -- test",
"test:coverage": "nyc --silent qunit test/node_test_setup.js test/lib test/unit",
"test:visual:coverage": "nyc --silent --no-clean qunit test/node_test_setup.js test/lib test/visual",
"coverage:report": "nyc report --reporter=lcov --reporter=text",
Expand Down
46 changes: 26 additions & 20 deletions scripts/index.js → scripts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,31 @@



const fs = require('fs-extra');
const os = require('os');
const _ = require('lodash');
const path = require('path');
const cp = require('child_process');
const inquirer = require('inquirer');
const fuzzy = require('fuzzy');
const chalk = require('chalk');
const moment = require('moment');
const Checkbox = require('inquirer-checkbox-plus-prompt');
const commander = require('commander');
const killPort = require('kill-port');

// const rollup = require('rollup');
// const loadConfigFile = require('rollup/loadConfigFile');
import chalk from 'chalk';
import cp from 'child_process';
import * as commander from 'commander';
import fs from 'fs-extra';
import fuzzy from 'fuzzy';
import inquirer from 'inquirer';
import Checkbox from 'inquirer-checkbox-plus-prompt';
import killPort from 'kill-port';
import _ from 'lodash';
import moment from 'moment';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import os from 'os';
import { listFiles, transform as transformFiles } from './transform_files.mjs';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// import rollup from 'rollup';
// import loadConfigFile from 'rollup/loadConfigFile';

const program = new commander.Command();

const { transform: transformFiles, listFiles } = require('./transform_files');



const wd = path.resolve(__dirname, '..');
Expand All @@ -41,7 +47,7 @@ const websiteDir = path.resolve(wd, '../fabricjs.com');
if (!fs.existsSync(dumpsPath)) {
fs.mkdirSync(dumpsPath);
}
const package = require(path.resolve(wd, 'package.json'));


function execGitCommand(cmd) {
return cp.execSync(cmd, { cwd: wd }).toString()
Expand Down Expand Up @@ -170,7 +176,7 @@ function build(options = {}) {
}

function startWebsite() {
if (require(path.resolve(websiteDir, 'package.json')).name !== 'fabricjs.com') {
if (JSON.parse(fs.readFileSync(path.resolve(websiteDir, 'package.json'))).name !== 'fabricjs.com') {
console.log(chalk.red('Could not locate fabricjs.com directory'));
}
const args = ['run', 'start:dev'];
Expand Down Expand Up @@ -391,7 +397,7 @@ function writeCLIFile(tests) {
}

function readCLIFile() {
return fs.existsSync(CLI_CACHE) ? require(CLI_CACHE) : [];
return fs.existsSync(CLI_CACHE) ? JSON.parse(fs.readFileSync(CLI_CACHE)) : [];
}

function createChoiceData(type, file) {
Expand Down Expand Up @@ -500,7 +506,7 @@ async function runIntreactiveTestSuite(options) {
program
.name('fabric.js')
.description('fabric.js DEV CLI tools')
.version(package.version)
.version(process.env.npm_package_version)
.showSuggestionAfterError();

program
Expand Down
25 changes: 13 additions & 12 deletions scripts/transform_files.js → scripts/transform_files.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env node
const fs = require('fs-extra');
const _ = require('lodash');
const path = require('path');
const chalk = require('chalk');
import chalk from 'chalk';
import fs from 'fs-extra';
import _ from 'lodash';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const wd = path.resolve(__dirname, '..');

Expand Down Expand Up @@ -119,8 +123,8 @@ function findClassBase(raw, regex) {
return [getNSFromVariableName(raw, first), ...rest].join('.');
}) || [];
const rawObject = findObject(raw, '{', '}', result.index);
const NS = namespace.slice(0, namespace.lastIndexOf('.'));
const { fabric } = require(wd);
// const NS = namespace.slice(0, namespace.lastIndexOf('.'));
// const { fabric } = require(wd);
// const klass = fabric.util.resolveNamespace(NS === 'fabric' ? null : NS)[name];
return {
name,
Expand All @@ -132,8 +136,7 @@ function findClassBase(raw, regex) {
index: result.index,
value: match
},
...rawObject,
// klass
...rawObject
};
}

Expand Down Expand Up @@ -342,7 +345,7 @@ function resolveDest(dir, file, { type, overwriteExisitingFiles, ext }) {
name => path.resolve(dir, `${name}.${ext}`);
}

function listFiles() {
export function listFiles() {
const paths = [];
classDirs.forEach(klsDir => {
const dir = path.resolve(srcDir, klsDir);
Expand Down Expand Up @@ -375,7 +378,7 @@ function listFiles() {
return paths;
}

function transform(options = {}) {
export function transform(options = {}) {
options = _.defaults(options, { overwriteExisitingFiles: true, ext: 'js', createIndex: true, useExports: true });

const result = listFiles()
Expand Down Expand Up @@ -404,5 +407,3 @@ function transform(options = {}) {
errors.map(console.error);
}
}

module.exports = { transform, listFiles };

0 comments on commit 8663b2c

Please sign in to comment.