mirror of
https://gitee.com/WeBank/fes.js.git
synced 2024-11-29 18:28:09 +08:00
This commit is contained in:
parent
7c01ee979e
commit
457e624dbe
@ -32,5 +32,6 @@ export default await antfu({
|
||||
multilineDetection: 'brackets',
|
||||
},
|
||||
],
|
||||
'no-console': 'off',
|
||||
},
|
||||
});
|
||||
|
@ -2,30 +2,30 @@
|
||||
"name": "@fesjs/create-fes-app",
|
||||
"version": "3.0.4",
|
||||
"description": "create a app base on fes.js",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"lib",
|
||||
"bin",
|
||||
"templates/**/*"
|
||||
],
|
||||
"bin": {
|
||||
"create-fes-app": "bin/create-fes-app.js"
|
||||
},
|
||||
"author": "qlin",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/WeBankFinTech/fes.js#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/WeBankFinTech/fes.js.git",
|
||||
"directory": "packages/create-fes-app"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/WeBankFinTech/fes.js/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"fes"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"author": "qlin",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/WeBankFinTech/fes.js/issues"
|
||||
"main": "lib/index.js",
|
||||
"bin": {
|
||||
"create-fes-app": "bin/create-fes-app.js"
|
||||
},
|
||||
"homepage": "https://github.com/WeBankFinTech/fes.js#readme",
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
"templates/**/*"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { chalk, yParser } from '@fesjs/utils';
|
||||
import { existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
|
||||
const args = yParser(process.argv.slice(2), {
|
||||
alias: {
|
||||
@ -9,9 +9,9 @@ const args = yParser(process.argv.slice(2), {
|
||||
help: ['h'],
|
||||
force: ['f'],
|
||||
merge: ['m'],
|
||||
proxy: ['x']
|
||||
proxy: ['x'],
|
||||
},
|
||||
boolean: ['version', 'help', 'merge', 'force']
|
||||
boolean: ['version', 'help', 'merge', 'force'],
|
||||
});
|
||||
|
||||
if (args._.length > 1) {
|
||||
@ -25,7 +25,8 @@ if (args.version && !args._[0]) {
|
||||
: '';
|
||||
const { name, version } = require('../package.json');
|
||||
console.log(`${name}@${version}${local}`);
|
||||
} else if (args.help && !args._[0]) {
|
||||
}
|
||||
else if (args.help && !args._[0]) {
|
||||
console.log(`
|
||||
Usage: create-fes-app <name>
|
||||
|
||||
@ -36,11 +37,12 @@ Options:
|
||||
-m, --merge Merge target directory if it exists
|
||||
-x, --proxy <proxyUrl> Use specified proxy when creating project
|
||||
`);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
require('.')
|
||||
.default({
|
||||
cwd: process.cwd(),
|
||||
args
|
||||
args,
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Create failed, ${err.message}`);
|
||||
|
@ -1,12 +1,13 @@
|
||||
import path from 'path';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { chalk } from '@fesjs/utils';
|
||||
import validateProjectName from 'validate-npm-package-name';
|
||||
import fs from 'fs-extra';
|
||||
import inquirer from 'inquirer';
|
||||
import validateProjectName from 'validate-npm-package-name';
|
||||
|
||||
import { clearConsole } from './utils';
|
||||
import AppGenerator from './generator/App';
|
||||
import PluginGenerator from './generator/Plugin';
|
||||
import { clearConsole } from './utils';
|
||||
|
||||
export default async ({ cwd, args }) => {
|
||||
if (args.proxy) {
|
||||
@ -20,20 +21,21 @@ export default async ({ cwd, args }) => {
|
||||
const result = validateProjectName(name);
|
||||
if (!result.validForNewPackages) {
|
||||
console.error(chalk.red(`Invalid project name: "${name}"`));
|
||||
result.errors &&
|
||||
result.errors.forEach((err) => {
|
||||
console.error(chalk.red.dim(`Error: ${err}`));
|
||||
});
|
||||
result.warnings &&
|
||||
result.warnings.forEach((warn) => {
|
||||
console.error(chalk.red.dim(`Warning: ${warn}`));
|
||||
});
|
||||
result.errors
|
||||
&& result.errors.forEach((err) => {
|
||||
console.error(chalk.red.dim(`Error: ${err}`));
|
||||
});
|
||||
result.warnings
|
||||
&& result.warnings.forEach((warn) => {
|
||||
console.error(chalk.red.dim(`Warning: ${warn}`));
|
||||
});
|
||||
throw new Error('Process exited');
|
||||
}
|
||||
if (fs.pathExistsSync(targetDir) && !args.merge) {
|
||||
if (args.force) {
|
||||
await fs.remove(targetDir);
|
||||
} else if (inCurrent) {
|
||||
}
|
||||
else if (inCurrent) {
|
||||
clearConsole();
|
||||
const { ok } = await inquirer.prompt([
|
||||
{
|
||||
@ -45,7 +47,8 @@ export default async ({ cwd, args }) => {
|
||||
if (!ok) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
clearConsole();
|
||||
const { action } = await inquirer.prompt([
|
||||
{
|
||||
@ -98,7 +101,8 @@ export default async ({ cwd, args }) => {
|
||||
console.log('$ pnpm i');
|
||||
console.log('$ pnpm dev');
|
||||
console.log();
|
||||
} else if (template === 'plugin') {
|
||||
}
|
||||
else if (template === 'plugin') {
|
||||
const generator = new PluginGenerator({
|
||||
cwd,
|
||||
args,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import readline from 'readline';
|
||||
import process from 'node:process';
|
||||
import readline from 'node:readline';
|
||||
|
||||
export const clearConsole = (title) => {
|
||||
export function clearConsole(title) {
|
||||
if (process.stdout.isTTY) {
|
||||
const blank = '\n'.repeat(process.stdout.rows);
|
||||
console.log(blank);
|
||||
@ -10,4 +11,4 @@ export const clearConsole = (title) => {
|
||||
console.log(title);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
// 关闭 import 规则
|
||||
/* eslint import/no-extraneous-dependencies: 0 */
|
||||
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const path = require('path');
|
||||
const merge = require('deepmerge');
|
||||
const chokidar = require('chokidar');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const process = require('node:process');
|
||||
const chalk = require('chalk');
|
||||
const chokidar = require('chokidar');
|
||||
const merge = require('deepmerge');
|
||||
const fse = require('fs-extra');
|
||||
const argv = require('yargs-parser')(process.argv.slice(2));
|
||||
|
||||
const pkg = require('../package.json');
|
||||
const compiler = require('./compiler');
|
||||
const randomColor = require('./randomColor');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const ESM_OUTPUT_DIR = 'es';
|
||||
const NODE_CJS_OUTPUT_DIR = 'lib';
|
||||
@ -76,10 +77,12 @@ function transformFile(filePath, outputPath, config, log) {
|
||||
const type = config.target === 'browser' ? ESM_OUTPUT_DIR : NODE_CJS_OUTPUT_DIR;
|
||||
log(`Transform to ${type} for ${config.target === 'browser' ? chalk.yellow(shortFilePath) : chalk.blue(shortFilePath)}`);
|
||||
fse.outputFileSync(outputPath, transformedCode);
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fse.copySync(filePath, outputPath);
|
||||
}
|
||||
}
|
||||
@ -92,10 +95,12 @@ function compilerPkg(codeDir, outputDir, config, log) {
|
||||
const fileStats = fs.lstatSync(filePath);
|
||||
if (config.copy.includes(file)) {
|
||||
fse.copySync(filePath, outputFilePath);
|
||||
} else if (fileStats.isDirectory(filePath) && !/__tests__/.test(file)) {
|
||||
}
|
||||
else if (fileStats.isDirectory(filePath) && !/__tests__/.test(file)) {
|
||||
fse.ensureDirSync(outputFilePath);
|
||||
compilerPkg(filePath, outputFilePath, config, log);
|
||||
} else if (fileStats.isFile(filePath)) {
|
||||
}
|
||||
else if (fileStats.isFile(filePath)) {
|
||||
transformFile(filePath, outputFilePath, config, log);
|
||||
}
|
||||
});
|
||||
@ -112,11 +117,13 @@ function watchFile(dir, outputDir, config, log) {
|
||||
const outputPath = changeFile.replace(dir, outputDir);
|
||||
const stat = fs.lstatSync(changeFile);
|
||||
log(`[${event}] ${shortChangeFile}`);
|
||||
if (config.resolveCopy.some((item) => changeFile.startsWith(item))) {
|
||||
if (config.resolveCopy.some(item => changeFile.startsWith(item))) {
|
||||
fse.copySync(changeFile, outputPath);
|
||||
} else if (stat.isFile()) {
|
||||
}
|
||||
else if (stat.isFile()) {
|
||||
transformFile(changeFile, outputPath, config, log);
|
||||
} else if (stat.isDirectory()) {
|
||||
}
|
||||
else if (stat.isDirectory()) {
|
||||
compilerPkg(changeFile, outputPath, config);
|
||||
}
|
||||
});
|
||||
|
@ -27,7 +27,8 @@ module.exports = function (pkg) {
|
||||
cache[pkg] = str;
|
||||
if (index === colors.length - 1) {
|
||||
index = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
import {} from '@fesjs/fes';
|
||||
declare module "@fesjs/fes" {
|
||||
interface PluginBuildConfig {
|
||||
|
||||
}
|
||||
|
||||
interface PluginRuntimeConfig {
|
||||
|
||||
}
|
||||
declare module '@fesjs/fes' {
|
||||
interface PluginBuildConfig {}
|
||||
|
||||
interface PluginRuntimeConfig {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user