web-backset.cn/apps/server/script/new.page.js
2023-02-11 13:21:06 +08:00

43 lines
998 B
JavaScript

/* eslint-disable @typescript-eslint/no-var-requires */
const { mkdir, writeFile } = require('fs/promises');
const inquirer = require('inquirer');
const { join } = require('path');
const less = () => `@import '../../less/common.less';
@import '../../less/var.less';
`;
const ts = (name) => `import './index.less';
console.log('${name}');
`;
const ejs = (name) => `<!DOCTYPE html>
<html lang="en">
<head>
<%- include('../_layout/base') -%>
<title>new page: <%= name %></title>
</head>
<body>
<p>${name}</p>
</body>
</html>
`;
inquirer
.prompt([
{
type: 'input',
name: 'name',
message: '输入页面文件夹名称',
},
])
.then(async (res) => {
const { name } = res;
const targetDir = join(process.cwd(), 'src/view/pages', name);
await mkdir(targetDir);
await writeFile(`${targetDir}/index.ts`, ts(name));
await writeFile(`${targetDir}/index.ejs`, ejs(name));
await writeFile(`${targetDir}/index.less`, less());
});