Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create efx doesnt upload tsconfig template to npm v6 #949

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,069 changes: 1,701 additions & 1,368 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 0 additions & 45 deletions packages/create-efx/.npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/create-efx/bin/create-efx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /usr/bin/env node

require('../lib/index');
require('../lib/index.js');
18 changes: 11 additions & 7 deletions packages/create-efx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
"name": "create-efx",
"version": "6.1.9",
"description": "Initializer to create new EFX element",
"main": "lib/index",
"main": "./lib/index.js",
"bin": {
"create-efx": "bin/create-efx"
"create-efx": "./bin/create-efx"
},
"files": [
"bin",
"lib",
"template",
"CHANGELOG.md"
],
"repository": {
"type": "git",
"url": "[email protected]:Refinitiv/refinitiv-ui.git",
Expand All @@ -24,16 +30,14 @@
},
"dependencies": {
"chalk": "^4.1.2",
"fast-glob": "^3.2.5",
"fs-extra": "^10.1.0",
"minimist": "^1.2.6",
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
"minimist": "^1.2.8",
"prompts": "^2.4.2",
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/fs-extra": "^9.0.13",
"@types/node": "^18.11.17",
"@types/prompts": "^2.0.14"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-efx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chalk from 'chalk';
import fs from 'fs';
import fsExtra from 'fs-extra';
import minimist, { ParsedArgs } from 'minimist';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import prompts from 'prompts';

import {
Expand Down
31 changes: 16 additions & 15 deletions packages/create-efx/src/utils/renamer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fg from 'fast-glob';
import fs from 'fs-extra';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import replacer from './replacer.js';

Expand Down Expand Up @@ -33,19 +33,19 @@ const renameFiles = async function (root: string, newName: string, templateName:

const renameElementFile = new Promise<void>((resolve, reject) => {
try {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
entries.forEach(async (entry) => {
let fileExt = path.extname(entry.name);
entries.forEach((entry) => {
let extension = path.extname(entry.name);
if (entry.name.includes('.test')) {
fileExt = '.test' + fileExt;
extension = '.test' + extension;
}
const oldFilename = path.join(root, entry.path);
const newFilename = oldFilename.replace(entry.name, `${newName}${fileExt}`);
await fs.rename(oldFilename, newFilename);
const newFilename = oldFilename.replace(entry.name, `${newName}${extension}`);

fs.renameSync(oldFilename, newFilename);
});
resolve();
} catch (err) {
reject(err);
} catch (error) {
reject(error);
}
});

Expand All @@ -54,17 +54,18 @@ const renameFiles = async function (root: string, newName: string, templateName:
const suffixEntries = await fg([`.*${suffix}`, `*${suffix}`], { cwd: root, objectMode: true });
const removeSuffix = new Promise<void>((resolve, reject) => {
try {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
suffixEntries.forEach(async (suffixEntry: { path: string }, index) => {
suffixEntries.forEach((suffixEntry: { path: string }, index) => {
const oldFilename = path.join(root, suffixEntry.path);
const newFilename = oldFilename.substring(0, oldFilename.indexOf(suffix));
await fs.rename(oldFilename, newFilename);

fs.renameSync(oldFilename, newFilename);

if (index === suffixEntries.length - 1) {
resolve();
}
});
} catch (err) {
reject(err);
} catch (error) {
reject(error);
}
});

Expand Down
33 changes: 15 additions & 18 deletions packages/create-efx/src/utils/replacer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fg from 'fast-glob';
import fs from 'fs-extra';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

/**
* Find and replace all texts in a single file
Expand All @@ -14,24 +14,21 @@ const singleReplace = async (filePath: string, oldNames: string[], newNames: str
return new Promise<void>((resolve, reject) => {
const currentFile = path.join(cwd, filePath);

fs.readFile(currentFile, 'utf8', (err, data) => {
if (err) {
reject(err);
fs.readFile(currentFile, 'utf8', (error, content) => {
if (error) {
reject(error);
return;
}
let result;
let newData = data;

let fileContent = content;
newNames.forEach((newName, index) => {
newData = newData.replace(new RegExp(oldNames[index], 'g'), newName);
fileContent = fileContent.replace(new RegExp(oldNames[index], 'g'), newName);
});
// eslint-disable-next-line prefer-const
result = Promise.resolve(newData);

void result.then((out) => {
fs.writeFile(currentFile, out, 'utf8', (err) => {
if (err) {
reject(err);
void Promise.resolve(fileContent).then((out) => {
fs.writeFile(currentFile, out, 'utf8', (error) => {
if (error) {
reject(error);
} else {
resolve();
}
Expand All @@ -57,11 +54,11 @@ const groupReplace = async (oldNames: string[], newNames: string[], cwd: string)
files.forEach(function (file) {
promises.push(singleReplace(file, oldNames, newNames, cwd));
});
void Promise.all(promises).then(function (res) {
resolve(res);
void Promise.all(promises).then(function (result) {
resolve(result);
});
} catch (err) {
reject(err);
} catch (error) {
reject(error);
}
}).then(() => {
return {
Expand Down