fs#writeFile TypeScript Examples
The following examples show how to use
fs#writeFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: jsonHelper.ts From amplication with Apache License 2.0 | 6 votes |
static write: (
path: string,
packageJson: JsonObject,
space?: string | number
) => Promise<boolean> = (
path: string,
packageJson: JsonObject,
space: string | number = 2
) => {
return new Promise<boolean>((resolve, reject) => {
const data = new Uint8Array(
Buffer.from(JSON.stringify(packageJson, null, space))
);
writeFile(path, data, err => {
if (err) {
reject(err);
}
resolve(true);
});
});
};
Example #2
Source File: package.json.ts From aurelia-mdc-web with MIT License | 6 votes |
/**
* Stringifies and writes out the content of a package.json file
*
* @param pkg - The package.json as an object
*/
export async function savePackageJson(pkg: Package): Promise<void> {
const path = 'package.json';
return new Promise<void>((resolve, reject) => {
const str = JSON.stringify(pkg, null, 2);
writeFile(path, str, { encoding: 'utf8' }, (err) => {
if (err) {
reject(err);
}
resolve();
});
});
}
Example #3
Source File: locations.ts From Swordfish with Eclipse Public License 1.0 | 6 votes |
setLocation(window: string, x: number, y: number): void {
let point: Point = new Point(x, y);
this.locations.set(window, point);
let text: string = '{';
this.locations.forEach((value: Point, key: string) => {
text = text + '\"' + key + '\": {\"x\":' + value.x + ', \"y\":' + value.y + '},';
});
text = text.substring(0, text.length - 1) + '}'
let json = JSON.parse(text);
writeFile(this.file, JSON.stringify(json), (err: Error) => {
if (err) throw err;
});
}
Example #4
Source File: data.service.ts From tabby with MIT License | 6 votes |
writeData() {
if(Object.keys(this.data['weeks']).length === 0) {
this.data['currentWeek'] = '';
this._data.next(this.data);
}
writeFile(this.app.getPath('userData') + '/data.json', JSON.stringify(this.data), (err) => {
if(err !== null) console.log(err);
});
}
Example #5
Source File: data.service.ts From tabby with MIT License | 6 votes |
writeDefaultData() {
let defaultData: object = {
"accentColor": "#0366FC",
"language": "en",
"darkMode": false,
"currentWeek": "",
"weeks": {},
"tasks": []
}
writeFile(this.app.getPath('userData') + '/data.json', JSON.stringify(defaultData), (err) => {
if(err !== null) console.log(err);
});
}
Example #6
Source File: set_env.ts From Elastos.Essentials.App with MIT License | 5 votes |
writeFile('./src/environments/environment.prod.ts', prodEnvironmentFile, function (err) {
if (err) {
throw console.error(err);
} else {
console.log(`environment.prod.ts file generated`);
}
});
Example #7
Source File: RestyaboardUtils.ts From vscode-restyaboard-viewer with MIT License | 5 votes |
async showCard(card: RestyaboardCard): Promise<void> {
if (!card) {
vscode.window.showErrorMessage("No card selected or invalid card.");
return;
}
let Cardcomments: any = await this.getcardComments(card.id, card.board_id, card.list_id);
const cardMembers: string = this.showCardMembersAsString(card.cards_users);
const cardLabels: string = this.showCardLabelsAsString(card.cards_labels);
const checklistItems: string = this.showChecklistsAsMarkdown(card.cards_checklists);
const commentItems: string = this.showCommentsAsMarkdown(Cardcomments);
const cardCoverImageUrl = !!card.attachments && card.attachments.length > 0 ? card.attachments[0].url : "";
const cardContentAndHeaders = [
{ header: "URL", content: card.url },
{ header: "Title", content: card.name },
{ header: "Board Name", content: card.board_name },
{ header: "List Name", content: card.list_name },
{ header: "Members", content: cardMembers },
{ header: "Labels", content: cardLabels },
{ header: "Description", content: card.description },
{ header: "Checklists", content: checklistItems },
{ header: "Comments", content: commentItems },
];
if(card.due_date){
cardContentAndHeaders.push( { header: "Due Date", content: card.due_date });
}
let cardContent: string = "";
// cardContent += "| Board Name | List Name |\n| ------------- | ------------- |\n| "+card.board_name+" | "+card.list_name+" |\n";
cardContentAndHeaders.map(({ header, content }) => {
cardContent += this.showMarkdownDecorated(header, content);
});
cardContent += cardCoverImageUrl ? `<img src="${cardCoverImageUrl}" alt="Image not found" />` : "";
// Write temp markdown file at user's vs code default settings directory
writeFile(this.tempRestyaboardFile, cardContent, err => {
if (err) {
vscode.window.showErrorMessage(`Error writing to temp file: ${err}`);
}
console.info(`✍ Writing to file: ${this.tempRestyaboardFile}`);
});
// open markdown file and preview view
let viewColumn: vscode.ViewColumn =
vscode.workspace.getConfiguration(SETTING_PREFIX, null).get(SETTING_CONFIG.VIEW_COLUMN) ||
SETTING_CONFIG.DEFAULT_VIEW_COLUMN;
if (!(VSCODE_VIEW_COLUMN.indexOf(viewColumn) > -1)) {
vscode.window.showInformationMessage(`Invalid ${SETTING_PREFIX}.viewColumn ${viewColumn} specified`);
viewColumn = SETTING_CONFIG.DEFAULT_VIEW_COLUMN;
}
const doc = await vscode.workspace.openTextDocument(this.tempRestyaboardFile);
await vscode.window.showTextDocument(doc, viewColumn, false);
await vscode.commands.executeCommand("markdown.showPreview");
vscode.commands.executeCommand("markdown.preview.toggleLock");
}
Example #8
Source File: file.ts From hubble-contracts with MIT License | 5 votes |
writeFileAsync = promisify(writeFile)
Example #9
Source File: create-rss.ts From blog with GNU General Public License v3.0 | 5 votes |
writeFileAsync = promisify(writeFile)
Example #10
Source File: index.ts From vscode-gcode with MIT License | 5 votes |
tailorGrammar = (function() {
function updateGrammar(themeName: string) {
const json = getJson(themeName);
writeFile(grammarFile, json, () => commands.executeCommand('workbench.action.reloadWindow'));
// console.log(`G-Code grammar file has been tailored to the '${themeName}' theme.`);
}
function tailoredForTheme() {
const grammar = JSON.parse(readFileSync(grammarFile, 'utf8'));
const rtn = grammar.themeName == undefined ? '' : grammar.themeName;
// console.log(`G-Code grammar is tailored to the '${rtn}' theme.`);
return rtn.toString();
}
function doUpdate(force: boolean){
const themeName = (workspace.getConfiguration().get('workbench.colorTheme') as string);
if(force == true || tailoredForTheme() != themeName){
if (isThemeSupported(themeName)) {
// console.log(`The '${themeName}' theme is supported, prompt user to update grammar`);
if(force == true) {
updateGrammar(themeName);
}
else {
window.showInformationMessage(`Tailor G-Code grammer to the '${themeName}' theme?`, 'Yes', 'Not now').then(value => {
if (value == 'Yes') { updateGrammar(themeName) } else {console.log('User declined to tailor the grammar.');};
});
}
}
else {
// console.log(`G-Code grammar cannot be tailored to the '${themeName}' theme. This theme is not supported.`);
window.showInformationMessage(`G-Code grammer cannot be tailored to the '${themeName}' theme, this theme is not supported by the G-Code extension.`, 'Okay');
}
}
else {
// console.log(`G-Code grammar is already tailored to the '${themeName}' theme.`)
}
}
return {
"conditionally": function(){
doUpdate(false)
},
"force": function(){
doUpdate(true);
}
}
})()
Example #11
Source File: edit.ts From ironfish with Mozilla Public License 2.0 | 5 votes |
writeFileAsync = promisify(writeFile)
Example #12
Source File: index.ts From write-file-action with Apache License 2.0 | 5 votes |
writeFileAsync = promisify(writeFile)
Example #13
Source File: set_env.ts From Elastos.Essentials.App with MIT License | 5 votes |
writeFile('./src/environments/environment.ts', devEnvironmentFile, function (err) {
if (err) {
throw console.error(err);
} else {
console.log(`environment.ts file generated`);
}
});
Example #14
Source File: writeTsConfig.ts From engine with MIT License | 5 votes |
pWriteFile = promisify(writeFile)
Example #15
Source File: writePackageJson.ts From engine with MIT License | 5 votes |
pWriteFile = promisify(writeFile)
Example #16
Source File: writeGitIgnore.ts From engine with MIT License | 5 votes |
pWriteFile = promisify(writeFile)
Example #17
Source File: sort-words.ts From programmer-fa with MIT License | 5 votes |
writeFilePromisified = promisify(writeFile)
Example #18
Source File: FileStorage.ts From beacon-sdk with MIT License | 5 votes |
export function writeLocalFile(json: JsonObject): Promise<void> {
return new Promise((resolve: (_: void) => void): void => {
const fileContent: string = JSON.stringify(json)
writeFile(file, fileContent, { encoding: 'utf8' }, () => {
resolve()
})
})
}
Example #19
Source File: new-trongate-module.command.ts From trongate-vscode with MIT License | 4 votes |
async function createTrongateModuleTemplate(
moduleName: string,
targetDirectory: string,
isViewTemplate: string,
viewFileName: string,
GLOBAL_SETTINGS: any
) {
// The moduleName has been validated - this means no space and all lowercases
/* upperModuleName is the name for controller php file,
therefore the first letter needs to be uppercase */
const upperModuleName = makeFirstLetterGoUpper(moduleName);
await createDirectory(`${targetDirectory}/controllers`);
await createDirectory(`${targetDirectory}/views`);
await createDirectory(`${targetDirectory}/assets`);
if (isViewTemplate == "yes") {
await createDirectory(`${targetDirectory}/assets/css`);
await createDirectory(`${targetDirectory}/assets/js`);
}
// const isSuperModule = GLOBAL_SETTINGS['superModule']
// 1. check workspace - engine/ config/ modules -> pass -> this is a trongate project
// 2. trigger language server
// 3. communicate
const targetControllerPath = `${targetDirectory}/controllers/${upperModuleName}.php`;
let targetViewPath;
let targetCSSPath;
let targetJSPath;
if (isViewTemplate == "yes") {
targetViewPath = `${targetDirectory}/views/${viewFileName}.php`;
targetCSSPath = `${targetDirectory}/assets/css/custom.css`;
targetJSPath = `${targetDirectory}/assets/js/custom.js`;
}
const targetApiPath = `${targetDirectory}/assets/api.json`;
if (existsSync(targetControllerPath)) {
throw Error(`Module ${moduleName} already exists`);
}
await Promise.all([
writeFile(
targetControllerPath,
getTongateControllerTemplate(GLOBAL_SETTINGS, moduleName, viewFileName),
"utf8",
(error) => {
console.log(error);
}
),
// Write JS File
isViewTemplate === "yes" &&
writeFile(
targetJSPath,
"// Add your JavaScript here",
"utf8",
(error) => {
console.log(error);
}
),
// Write View File
isViewTemplate === "yes" &&
writeFile(
targetViewPath,
getTrongateViewTemplate(moduleName, GLOBAL_SETTINGS),
"utf8",
(error) => {
console.log(error);
}
),
// Write CSS File
isViewTemplate === "yes" &&
writeFile(targetCSSPath, getTrongateModuleCss(), "utf8", (error) => {
console.log(error);
}),
// Write Assets file
writeFile(targetApiPath, getTrongateAssets(moduleName), "utf8", (error) => {
console.log(error);
}),
]).catch((err) => {
console.log(err);
});
}