Skip to content

Commit

Permalink
chore(Lint): lint scripts/**/*.jsx? with prettier and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Nov 1, 2023
1 parent b1b48e9 commit d29fe62
Show file tree
Hide file tree
Showing 29 changed files with 78 additions and 216 deletions.
37 changes: 8 additions & 29 deletions scripts/build/generate-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ function generateAPIAST(apiInfos) {

const apiAST = remark.parse(apiDocs);
apiAST.children = apiAST.children.filter(child => {
return !(
child.children &&
child.children[0] &&
child.children[0].type === 'linkReference'
);
return !(child.children && child.children[0] && child.children[0].type === 'linkReference');
});

return apiAST;
Expand All @@ -107,9 +103,7 @@ function orderProps(props) {
orderMap[name] = index * 10;
}
});
const orderedNames = names.sort(
(prev, next) => orderMap[prev] - orderMap[next]
);
const orderedNames = names.sort((prev, next) => orderMap[prev] - orderMap[next]);

return orderedNames.reduce((ret, name) => {
ret[name] = props[name];
Expand All @@ -118,16 +112,10 @@ function orderProps(props) {
}

function getAPIExtraAST(ast) {
const generateReg = key =>
new RegExp(`^<!--\\s*api-extra-${key}\\s*-->$`, 'i');
const startIndex = ast.children.findIndex(
child => child.type === 'html' && generateReg('start').test(child.value)
);
const generateReg = key => new RegExp(`^<!--\\s*api-extra-${key}\\s*-->$`, 'i');
const startIndex = ast.children.findIndex(child => child.type === 'html' && generateReg('start').test(child.value));
if (startIndex > -1) {
const endIndex = ast.children.findIndex(
child =>
child.type === 'html' && generateReg('end').test(child.value)
);
const endIndex = ast.children.findIndex(child => child.type === 'html' && generateReg('end').test(child.value));
if (endIndex > -1 && startIndex < endIndex) {
return ast.children.slice(startIndex, endIndex + 1);
}
Expand All @@ -147,23 +135,14 @@ function updateAST(ast, apiAST) {
);
if (apiIndex > -1) {
const toNextHeading2 =
ast.children
.slice(apiIndex + 1)
.findIndex(
child => child.type === 'heading' && child.depth === 2
) + 1;
ast.children.slice(apiIndex + 1).findIndex(child => child.type === 'heading' && child.depth === 2) + 1;

if (toNextHeading2 === 0) {
ast.children = ast.children
.slice(0, apiIndex)
.concat(apiAST.children);
ast.children = ast.children.slice(0, apiIndex).concat(apiAST.children);
} else {
ast.children = ast.children
.slice(0, apiIndex)
.concat(
apiAST.children,
ast.children.slice(apiIndex + toNextHeading2)
);
.concat(apiAST.children, ast.children.slice(apiIndex + toNextHeading2));
}
} else {
ast.children = ast.children.concat(apiAST.children);
Expand Down
17 changes: 7 additions & 10 deletions scripts/build/generate-css-entry-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ module.exports = function() {
corePaths.forEach(cPath => {
const cContent = fs.readFileSync(cPath, 'utf8');

const newPath = cPath.replace('src', 'lib').replace('core-temp', 'core2').replace('-def-default.css', '.css');

fs.outputFileSync(
newPath,
cContent
);
fs.outputFileSync(
newPath.replace('lib', 'es'),
cContent
);
const newPath = cPath
.replace('src', 'lib')
.replace('core-temp', 'core2')
.replace('-def-default.css', '.css');

fs.outputFileSync(newPath, cContent);
fs.outputFileSync(newPath.replace('lib', 'es'), cContent);
});

const indexContent = `@import "./index-noreset.css";`;
Expand Down
20 changes: 4 additions & 16 deletions scripts/build/generate-scss-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,15 @@ module.exports = function() {
})
.join('');
const componentName = path.basename(path.dirname(styleJsPath));
fs.writeFileSync(
path.join(cwd, 'lib', componentName, 'index.scss'),
indexScssContent
);
fs.writeFileSync(
path.join(cwd, 'es', componentName, 'index.scss'),
indexScssContent
);
fs.writeFileSync(path.join(cwd, 'lib', componentName, 'index.scss'), indexScssContent);
fs.writeFileSync(path.join(cwd, 'es', componentName, 'index.scss'), indexScssContent);
});

// 旧包中 lib/_components/@alife/next-core/lib 下的 index.scss 和 index-noreset.scss 很可能被用户使用,故保留该文件夹结构
const _corePath = path.resolve(cwd, 'lib/_components/@alife/next-core/lib');
fs.mkdirpSync(_corePath);
fs.writeFileSync(
path.join(_corePath, 'index.scss'),
'@import "../../../../core/reset.scss";\n'
);
fs.writeFileSync(
path.join(_corePath, 'index-noreset.scss'),
'@import "../../../../core/index-noreset.scss";\n'
);
fs.writeFileSync(path.join(_corePath, 'index.scss'), '@import "../../../../core/reset.scss";\n');
fs.writeFileSync(path.join(_corePath, 'index-noreset.scss'), '@import "../../../../core/index-noreset.scss";\n');

logger.success('Generate index.scss successfully!');
};
4 changes: 3 additions & 1 deletion scripts/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ async function run() {
fs.removeSync(path.join(esPath, 'core-temp'));
fs.removeSync(path.join(cwd, 'src/core-temp'));

const tempPaths = glob.sync(path.join(cwd, '@(lib|es)', '*', 'scss/@(scss-var-to-css-var|css-var-def-default).scss'));
const tempPaths = glob.sync(
path.join(cwd, '@(lib|es)', '*', 'scss/@(scss-var-to-css-var|css-var-def-default).scss')
);
tempPaths.forEach(p => fs.removeSync(p));

logger.success('Run build successfully!');
Expand Down
28 changes: 14 additions & 14 deletions scripts/build/scss2css.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ const { logger } = require('../utils');
const compileScss = function(all, s1, basePath, entry) {
let cssval = '';
try {

const content = fs.readFileSync(path.join(basePath, entry), 'utf-8');

const data = `${content}\n${all}.theScssCompileResultIwant{color:${s1};}`;
const result = sass.renderSync({
file: path.join(basePath, entry),
includePaths: [path.join(basePath, entry)],
outputStyle: "compressed",
outputStyle: 'compressed',
data,
});
const output = result.css.toString();

output.replace(/.*theScssCompileResultIwant{color:(.*)}/ig, (_, compileValue) => {
output.replace(/.*theScssCompileResultIwant{color:(.*)}/gi, (_, compileValue) => {
cssval = compileValue;
const temp = `${s1.replace('$', '--')}: ${compileValue};\n`
const temp = `${s1.replace('$', '--')}: ${compileValue};\n`;
logger.info(`${all}\n${temp}`);
});
} catch (error) {
Expand All @@ -44,35 +43,36 @@ const compileScss = function(all, s1, basePath, entry) {

// basePath 例如 path.join(cwd, 'lib/core/')
// entry 例如 index.scss
const scss2css = function (all, s1, s2, basePath, entry) {
const scss2css = function(all, s1, s2, basePath, entry) {
s2 = s2.replace('!default', '').trim();

let cssvar = '', newcContent = '';
let cssvar = '',
newcContent = '';
if (s2.match(/\$css-prefix/)) {
// 保留原状
} else if (s2.match(/[/()+]/ig)) {
} else if (s2.match(/[/()+]/gi)) {
const compileValue = compileScss(all, s1, basePath, entry);
newcContent = ` ${s1.replace('$', '--')}: ${compileValue};\n`;
} else if (s2.match(/[ ]/ig)) {
} else if (s2.match(/[ ]/gi)) {
const vs = s2.split(' ');
const nvs = vs.map(v => {
return v.match(/[$]/ig) ? `var(${v.replace('$', '--')})` : v;
return v.match(/[$]/gi) ? `var(${v.replace('$', '--')})` : v;
});
if (s2.match(/\*/ig)) {
if (s2.match(/\*/gi)) {
newcContent = ` ${s1.replace('$', '--')}: calc(${nvs.join(' ')});\n`;
} else {
newcContent = ` ${s1.replace('$', '--')}: ${nvs.join(' ')};\n`;
}
} else if (s2.match(/[$]/ig)) {
} else if (s2.match(/[$]/gi)) {
cssvar = `var(${s2.replace('$', '--')})`;
newcContent = ` ${s1.replace('$', '--')}: ${cssvar};\n`;
} else {
newcContent = ` ${s1.replace('$', '--')}: ${s2};\n`;
}
return newcContent;
}
};

module.exports = {
scss2css,
compileScss
}
compileScss,
};
5 changes: 1 addition & 4 deletions scripts/build/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ module.exports = function transform() {

const relativePaths = glob.sync('**/*.*', { cwd: srcPath });
relativePaths.forEach(relaticePath => {
const content = fs.readFileSync(
path.join(srcPath, relaticePath),
'utf8'
);
const content = fs.readFileSync(path.join(srcPath, relaticePath), 'utf8');
let libContent, esContent;
libContent = esContent = content;
if (PATTERN_ES6.test(relaticePath)) {
Expand Down
9 changes: 3 additions & 6 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ function updateVersionInCode() {
const packageInfo = require(packagePath);
const entryPath = path.join(cwd, 'index.js');
let entryContent = fs.readFileSync(entryPath, 'utf8');
entryContent = entryContent.replace(
/(next\.version = ')[\d.\w]+(';)/,
(all, s1, s2) => {
return `${s1}${packageInfo.version}${s2}`;
}
);
entryContent = entryContent.replace(/(next\.version = ')[\d.\w]+(';)/, (all, s1, s2) => {
return `${s1}${packageInfo.version}${s2}`;
});
fs.writeFileSync(entryPath, entryContent);

logger.success(`Update version in [${entryPath}] success`);
Expand Down
6 changes: 1 addition & 5 deletions scripts/check/build-sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ module.exports = function*() {
});
} catch (e) {
logger.error(
chalk.red(
`Try to build entry scss failed: ${e.message} line: ${
e.line
}, column: ${e.column} in ${e.file}`
)
chalk.red(`Try to build entry scss failed: ${e.message} line: ${e.line}, column: ${e.column} in ${e.file}`)
);
throw e;
}
Expand Down
4 changes: 1 addition & 3 deletions scripts/check/check-sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const runCommond = cmd => {

module.exports = function*() {
try {
logger.warn(
'> 使用 [email protected] 进行检查: 请保证本地node-sass版本为4.6.0 npm install -g [email protected]'
);
logger.warn('> 使用 [email protected] 进行检查: 请保证本地node-sass版本为4.6.0 npm install -g [email protected]');
yield runCommond('node-sass --version');
yield runCommond('node-sass index.scss > precss.css');

Expand Down
1 change: 0 additions & 1 deletion scripts/clear-dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ const path = require('path');
const distPath = path.join(process.cwd(), 'dist');

fs.emptyDirSync(distPath);

13 changes: 2 additions & 11 deletions scripts/create-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ co(function*() {
name: 'family',
type: 'list',
message: "Input the component's chinese name (e.g. 日期选择): ",
choices: [
'data-entry',
'general',
'navigation',
'data-display',
'feedback',
'util',
],
choices: ['data-entry', 'general', 'navigation', 'data-display', 'feedback', 'util'],
},
]);
const dashName = create.name;
Expand Down Expand Up @@ -106,7 +99,5 @@ co(function*() {
);
fs.writeFileSync(fusionJSPath, fusionJSContent);

logger.warn(
"Don't forget to write types/index.d.ts and English docs by hand!!"
);
logger.warn("Don't forget to write types/index.d.ts and English docs by hand!!");
});
5 changes: 1 addition & 4 deletions scripts/docs/configs/webpack/theme/demo-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ DemoPlugin.prototype.apply = function(compiler) {
chunk: chunk,
});
const files = chunk.files;
const js = this._cut(
_.find(files, file => path.extname(file) === '.js'),
assets
);
const js = this._cut(_.find(files, file => path.extname(file) === '.js'), assets);

assets[pathname] = {
source: () => {
Expand Down
8 changes: 1 addition & 7 deletions scripts/docs/export-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ module.exports = function*(options) {
const entryName = entries[i].name;
for (let j = 0; j < possibleNames.length; j++) {
const possibleName = possibleNames[j];
const possiblePath = path.join(
cwd,
'lib',
entryName,
'scss',
possibleName
);
const possiblePath = path.join(cwd, 'lib', entryName, 'scss', possibleName);
if (yield fs.exists(possiblePath)) {
exportVars.push(path.relative(cwd, possiblePath));
break;
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/generate-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function* buildCompiledDocs(cwd) {
family: apiMdParsed.meta.family,
});

let apiMdRenderedObj = JSON.parse(apiMdRendered);
const apiMdRenderedObj = JSON.parse(apiMdRendered);
apiMdRenderedObj.renderHtml = transformHTML(globalControls);
yield fs.writeFile(apiTo, `${JSON.stringify(apiMdRenderedObj)}`, 'utf8');
} else {
Expand Down
5 changes: 1 addition & 4 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ const { components } = require('./config');
const { logger, getComponentName } = require('./utils');

const cwd = process.cwd();
const hasEntry = component =>
['core', 'locale', 'mixin-ui-state', 'util', 'validate'].indexOf(
component
) === -1;
const hasEntry = component => ['core', 'locale', 'mixin-ui-state', 'util', 'validate'].indexOf(component) === -1;

const indexJSPath = path.join(cwd, 'src', 'index.js');
const indexJSContent = components
Expand Down
8 changes: 1 addition & 7 deletions scripts/order-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ const cwd = process.cwd();

const componentName = checkComponentName();

const varFilePath = path.join(
cwd,
'src',
componentName,
'scss',
'variable.scss'
);
const varFilePath = path.join(cwd, 'src', componentName, 'scss', 'variable.scss');
if (!fs.existsSync(varFilePath)) {
throw new Error(`Can not find the variable.scss: ${varFilePath}`);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/preview/loaders/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(content) {
this.addDependency(headerTplPath);
this.addDependency(indexTplPath);
this.addDependency(resourcePath);
let [demoInsertScript, demoMetas] = getDemos(demoPaths, lang, dir, this.context, resourcePath, comp.name);
const [demoInsertScript, demoMetas] = getDemos(demoPaths, lang, dir, this.context, resourcePath, comp.name);

const lines = content.split(/\n/g);
const endIndex = lines.findIndex(line => /^-{3,}/.test(line));
Expand Down
2 changes: 1 addition & 1 deletion scripts/preview/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function getEntry(entryPaths, componentName, mode) {
const entry = entryPaths.reduce((ret, entryPath) => {
const name = path.basename(entryPath, path.extname(entryPath));
const pathWithoutExt = path.join(path.dirname(entryPath), name);
let cssArr = [];
const cssArr = [];
// preview 不需要next样式默认值
// 通过 mode 判断引入的样式文件
// if (mode === 'css') {
Expand Down
1 change: 0 additions & 1 deletion scripts/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { checkComponentName } = require('../utils');

const scriptPath = path.join(__dirname, 'server.js');


const args = checkComponentName(false, true);

// 获取输入的 mode,css / scss,默认scss
Expand Down
Loading

0 comments on commit d29fe62

Please sign in to comment.