-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1d135a
commit ecb7298
Showing
12 changed files
with
9,951 additions
and
10,967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"endOfLine": "auto", | ||
"htmlWhitespaceSensitivity": "css", | ||
"insertPragma": false, | ||
"jsxBracketSameLine": false, | ||
"jsxSingleQuote": false, | ||
"printWidth": 100, | ||
"proseWrap": "preserve", | ||
"quoteProps": "as-needed", | ||
"requirePragma": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"tabWidth": 4, | ||
"trailingComma": "es5", | ||
"useTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,88 @@ | ||
const gulp = require("gulp"); | ||
const path = require("path"); | ||
const execSync = require("child_process").execSync; | ||
const fs = require("fs-extra"); | ||
const { isDir } = require("./utils"); | ||
const babelLoader = require("./loaders/babel"); | ||
const eslintLoader = require("./loaders/eslint"); | ||
const tsLoader = require("./loaders/typescript"); | ||
const cssLoader = require("./loaders/css"); | ||
const log = require("./logger"); | ||
|
||
let hasInstall = false; | ||
|
||
function hasInstallDeps() { | ||
if (hasInstall) return true; | ||
|
||
const pkgFile = process.cwd() + "/package.json"; | ||
let pkg = {}; | ||
if (fs.existsSync(pkgFile)) { | ||
pkg = require(pkgFile); | ||
} | ||
const allDeps = Object.assign({}, pkg.dependencies, pkg.devDependencies); | ||
|
||
hasInstall = "gulp-sass" in allDeps; | ||
|
||
return hasInstall; | ||
} | ||
|
||
function installDeps() { | ||
if (hasInstall) return; | ||
hasInstall = true; | ||
|
||
log("安装依赖 gulp-sass ..."); | ||
cmd = `npm install --save-dev gulp-sass@4.0.2`; | ||
try { | ||
execSync(cmd); | ||
} catch (e) { | ||
log("依赖安装失败,请自行安装 gulp-sass"); | ||
process.exit(0); | ||
} | ||
log("安装完成"); | ||
} | ||
|
||
function checkFileIfNeedInstall(file) { | ||
return /\.scss$/.test(file); | ||
} | ||
|
||
module.exports = async function compile(file, options) { | ||
const ignore = | ||
options.ignore || | ||
function() { | ||
return false; | ||
}; | ||
const absPath = path.resolve(options.appSrc, file); | ||
const outFile = path.resolve(options.outDir, file); | ||
let outDir = options.outDir; | ||
|
||
if (isDir(absPath)) { | ||
await fs.ensureDir(outFile); | ||
return Promise.resolve(file); | ||
} | ||
|
||
outDir = path.dirname(outFile); | ||
|
||
return new Promise(resolve => { | ||
let stream = gulp.src(absPath, { | ||
cwd: options.appSrc, | ||
allowEmpty: true | ||
}); | ||
|
||
if (!ignore(file)) { | ||
stream = eslintLoader(stream, options); | ||
stream = cssLoader(stream, options); | ||
stream = tsLoader(stream, options); | ||
stream = babelLoader(stream, options); | ||
} | ||
stream = stream.pipe(gulp.dest(outDir)); | ||
|
||
stream.on("finish", () => { | ||
resolve(file); | ||
}); | ||
stream.on("error", () => { | ||
resolve(file); | ||
}); | ||
}); | ||
const ignore = | ||
options.ignore || | ||
function() { | ||
return false; | ||
}; | ||
const absPath = path.resolve(options.appSrc, file); | ||
const outFile = path.resolve(options.outDir, file); | ||
let outDir = options.outDir; | ||
|
||
if (isDir(absPath)) { | ||
await fs.ensureDir(outFile); | ||
return Promise.resolve(file); | ||
} | ||
|
||
if (checkFileIfNeedInstall(file) && !hasInstallDeps()) { | ||
installDeps(); | ||
} | ||
|
||
outDir = path.dirname(outFile); | ||
|
||
return new Promise(resolve => { | ||
let stream = gulp.src(absPath, { | ||
cwd: options.appSrc, | ||
allowEmpty: true, | ||
}); | ||
|
||
if (!ignore(file)) { | ||
stream = eslintLoader(stream, options); | ||
stream = cssLoader(stream, options); | ||
stream = babelLoader(stream, options); | ||
} | ||
stream = stream.pipe(gulp.dest(outDir)); | ||
|
||
stream.on("finish", () => { | ||
resolve(file); | ||
}); | ||
stream.on("error", () => { | ||
resolve(file); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.