本文整理匯總了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());