本文整理汇总了TypeScript中path-exists.sync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sync函数的具体用法?TypeScript sync怎么用?TypeScript sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sync函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hasJSConfig
export function hasJSConfig(): boolean {
if (!workspace || !workspace.rootPath) {
return false;
}
return pathExists.sync(path.join(workspace.rootPath, "jsconfig.json"));
}
示例2: Promise
return new Promise((resolve, reject) => {
let source: string;
let javaHome: string = process.env.JDK_HOME;
if (javaHome) {
source = 'The JDK_HOME environment variable';
} else {
javaHome = process.env.JAVA_HOME;
source = 'The JAVA_HOME environment variable';
}
if (javaHome) {
javaHome = expandHomeDir(javaHome);
if (!pathExists.sync(javaHome)) {
reject(source + ' points to a missing folder');
}
return resolve(javaHome);
}
// No settings, let's try to detect as last resort.
findJavaHome((err, home) => {
if (err) {
reject('Java runtime could not be located');
} else {
resolve(home);
}
});
});
示例3: appendJSConfig
export function appendJSConfig(data): boolean {
if (!workspace || !workspace.rootPath) {
return false;
}
let jscPath = path.join(workspace.rootPath, "jsconfig.json");
let newJsc;
let mergedJsc;
let currentJsc;
// Check first if a jsconfig.json exists
if (pathExists.sync(jscPath)) {
// Merge
try {
currentJsc = JSON.parse(fs.readFileSync(jscPath, "utf8"));
mergedJsc = merge(currentJsc, data);
} catch (e) {
console.log(e);
}
}
// Write new config
try {
newJsc = mergedJsc || jsConfig;
fs.writeFileSync(jscPath, JSON.stringify(newJsc), "utf8");
} catch (e) {
return false;
}
}
示例4: hasFile
export function hasFile(file: string): boolean {
if (!workspace || !workspace.rootPath) {
return false;
}
return pathExists.sync(path.join(workspace.rootPath, file));
}
示例5: writeSetting
export function writeSetting(data) {
let currentConfig, mergedConfig, newConfig;
// Check first if a jsconfig.json exists
if (pathExists.sync(configPath)) {
// Merge
try {
currentConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
mergedConfig = merge(currentConfig, data);
} catch (e) {
console.log(e);
}
}
// Write new config
try {
newConfig = mergedConfig || data;
fs.writeFileSync(configPath, JSON.stringify(newConfig), "utf8");
return true;
} catch (e) {
return false;
}
}
示例6: appendVSCIgnore
export function appendVSCIgnore(ignoreItems: Array<string>): Boolean {
if (!ignoreItems || ignoreItems.length === 0 || !workspace || !workspace.rootPath) {
return false;
}
let vsciPath = path.join(workspace.rootPath, ".vscodeignore");
let eol = EOL || (process.platform === "win32" ? "\r\n" : "\n");
// Let"s first see if the file already exists - and if so,
// which items we have to fill in
if (pathExists.sync(vsciPath)) {
let vsciBuffer = fs.readFileSync(vsciPath);
let vsciContent = vsciBuffer.toString().split(/\r?\n/);
// If there"s anything in that file, we"ll need to add a newline
if (vsciContent.length > 0) {
ignoreItems.unshift("");
}
// Compare items to ignore and the current .vscodeignore items
for (let i = 0; i < vsciContent.length; i++) {
for (let ii = 0; ii < ignoreItems.length; ii++) {
if (vsciContent[i] === ignoreItems[ii]) {
ignoreItems.splice(ii, 1);
}
}
}
}
// Now, let"s append the .vscodeignore
let ignoreContent = ignoreItems.join(eol);
try {
fs.appendFileSync(vsciPath, ignoreContent, "utf8");
return true;
} catch (e) {
return false;
}
}
示例7: Date
let ioSocket: any;
const options: Idefaults = {
port: 6767,
secret: new Date().getTime() + "xxx",
password: 'admindocker'
}
if (pathExists.sync("./conf.json")) merge(options, require("./conf.json"))
app.all("/*", function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.use(cors());