Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions commands/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path'
import fs from 'fs'
import ignore from 'ignore'
import parse from 'parse-gitignore'

export function getSeeds(baseSeed) {
return {
Expand All @@ -26,11 +28,20 @@ export function normalizeFolderPath(folderPath) {
return path.normalize(folderPath.endsWith(path.sep) ? folderPath.slice(0, -1) : folderPath)
}

export function getFiles(folderPath) {
export function getFiles(folderPath, includeGitIgnoredFiles=false) {

let files = []
let filters = ['.git/']

// if we don't want to include git ignored files, we add filters
if (!includeGitIgnoredFiles){
if (fs.existsSync('.gitignore')) {
filters.push(...parse(fs.readFileSync('.gitignore'))['patterns']);
}
}

if (fs.statSync(folderPath).isDirectory()) {
handleDirectory(folderPath, files)

handleDirectory(folderPath, files, filters)
files = files.map(file => {
file.filePath = file.filePath.replace(folderPath, '')
return file
Expand Down Expand Up @@ -66,17 +77,22 @@ export async function estimateTxsFees(archethic, transactions) {
return { refTxFees, filesTxFees }
}

function handleDirectory(entry, files) {
function handleDirectory(entry, files, filters ) {
const gitignore = ignore().add(filters)
if (fs.statSync(entry).isDirectory()) {
fs.readdirSync(entry).forEach(child => {
handleDirectory(entry + path.sep + child, files)
handleDirectory(entry + path.sep + child, files, filters)
});
} else {
handleFile(entry, files)
// check if file's pattern corresponds to gitignore patterns
const absolutePath = getAbsolutePath(entry)
if(!gitignore.ignores(absolutePath)){
handleFile(entry, files);
}
}
}

function handleFile(filePath, files) {
const data = fs.readFileSync(filePath)
files.push({ filePath, data })
}
}
12 changes: 10 additions & 2 deletions commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const builder = {
demandOption: true, // Required
type: 'string',
},

"include-git-ignored-files": {
describe: 'Upload files referenced in .gitignore',
demandOption: false,
type: 'boolean',
},
"ssl-certificate": {
describe: 'SSL certificate to link to the website',
demandOption: false,
Expand All @@ -56,6 +60,10 @@ const handler = async function(argv) {
sslKey
} = cli.loadSSL(argv['ssl-certificate'], argv['ssl-key'])

// Should include git ignored files
const includeGitIgnoredFiles = argv['include-git-ignored-files']

// Get the path
const folderPath = cli.normalizeFolderPath(argv.path)

// Get seeds
Expand Down Expand Up @@ -83,7 +91,7 @@ const handler = async function(argv) {
console.log(chalk.blue('Creating file structure and compress content...'))

const aeweb = new AEWeb(archethic)
const files = cli.getFiles(folderPath)
const files = cli.getFiles(folderPath, includeGitIgnoredFiles)

if (files.length === 0) throw 'folder "' + path.basename(folderPath) + '" is empty'

Expand Down
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"archethic": "^1.13.2",
"chalk": "^5.0.1",
"figlet": "^1.5.2",
"ignore": "^5.2.0",
"lodash": "^4.17.21",
"parse-gitignore": "^2.0.0",
"yargs": "^17.5.1",
"yesno": "^0.4.0"
},
Expand Down