-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from DefangLabs/revert-137-jordan/deduplicate…
…-samples Revert "deduplicate samples from docs site in favour of mktg site"
- Loading branch information
Showing
12 changed files
with
405 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Samples | ||
description: Sample projects to help you launch services faster with Defang. | ||
sidebar_position: 600 | ||
--- | ||
|
||
import {Button, ButtonGroup, FormGroup, FormLabel} from "@mui/material" | ||
|
||
# Samples | ||
|
||
Check out our sample projects here to get some inspiration and get a sense of how Defang works. | ||
|
||
import Samples from "../src/components/Samples"; | ||
|
||
<Samples /> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const YAML = require('yaml'); | ||
|
||
const samplesDir = process.argv[2]; | ||
|
||
// categories are directories in the current directory (i.e. we're running in samples/ and we might have a samples/ruby/ directory) | ||
const directories = fs.readdirSync(samplesDir).filter(file => fs.statSync(path.join(samplesDir, file)).isDirectory()); | ||
|
||
let jsonArray = []; | ||
|
||
directories.forEach((sample) => { | ||
const directoryName = sample; | ||
console.log(`@@ Adding ${sample}`); | ||
let readme; | ||
try { | ||
readme = fs.readFileSync(path.join(samplesDir, sample, 'README.md'), 'utf8'); | ||
} catch (error) { | ||
readme = `# ${sample}`; | ||
} | ||
|
||
// The readme should contain lines that start with the following: | ||
// Title: | ||
// Short Description: | ||
// Tags: | ||
// Languages: | ||
// | ||
// We want to extract the title, short description, tags, and languages from the readme. Tags and languages are comma separated lists. | ||
const title = readme.match(/Title: (.*)/)[1]; | ||
const shortDescription = readme.match(/Short Description: (.*)/)[1]; | ||
const tags = readme.match(/Tags: (.*)/)[1].split(',').map(tag => tag.trim()); | ||
const languages = readme.match(/Languages: (.*)/)[1].split(',').map(language => language.trim()); | ||
|
||
let configs = []; | ||
try { | ||
composeFile = fs.readFileSync(path.join(samplesDir, sample, 'compose.yaml'), 'utf8'); | ||
compose = YAML.parse(composeFile); | ||
|
||
for (var name in compose.services) { | ||
service = compose.services[name] | ||
if (Array.isArray(service.environment)) { | ||
service.environment.forEach(env => { | ||
if (!env.includes("=")) { | ||
configs.push(env); | ||
} | ||
}); | ||
} else { | ||
for (var name in service.environment) { | ||
value = service.environment[name]; | ||
if (value === null || value === undefined || value === "") { | ||
configs.push(name); | ||
} | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
// Ignore if the sample doesn't have a compose file | ||
if (error.code != 'ENOENT') { | ||
console.log(`failed to parese compose for configs for sample`, sample, error); | ||
} | ||
} | ||
|
||
const sampleSummary = { | ||
name: directoryName, | ||
category: languages?.[0], | ||
readme, | ||
directoryName, | ||
title, | ||
shortDescription, | ||
tags, | ||
languages, | ||
}; | ||
if (configs.length > 0) { | ||
sampleSummary.configs = configs; | ||
} | ||
jsonArray.push(sampleSummary); | ||
|
||
console.log(`@@ Added ${sample}`); | ||
}); | ||
|
||
const stringified = JSON.stringify(jsonArray, null, 2); | ||
|
||
// fs.writeFileSync(path.join(__dirname, '..', 'samples.json'), stringified); | ||
|
||
// we're going to open up the ../docs/samples.md file and replce [] with the stringified JSON | ||
|
||
// const samplesMd = path.join(__dirname, '..', 'docs', 'samples.md'); | ||
// let samplesMdContents = fs.readFileSync(samplesMd, 'utf8'); | ||
// samplesMdContents += `<Samples samples={${stringified}} />`; | ||
// fs.writeFileSync(samplesMd, samplesMdContents); | ||
|
||
// save the json to the samples.json file in static | ||
fs.writeFileSync(path.join(__dirname, '..', 'static', 'samples-v2.json'), stringified); |
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
Oops, something went wrong.