Skip to content

Commit

Permalink
Changed whitespace to respect with original authors preferences, remo…
Browse files Browse the repository at this point in the history
…ved some unneeded items.
  • Loading branch information
uncleflo committed May 20, 2021
1 parent a4b6bd1 commit 009eef3
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 264 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ For now this is only a wrapper around `git clone`. After you pull down a repo yo

* Instead of exposing your password for the `quickbase-cli.config.js` file you can rely on an environment variable called `QUICKBASE_CLI_PASSWORD`. If you have that variable defined and leave the `password` empty when prompted the `qb deploy` command will use it instead. Always practice safe passwords.

* The same can also be done with username (using `QUICKBASE_CLI_USERNAME`), user token (using `QUICKBASE_CLI_USERTOKEN`, sort of an Admin token) and/or app token (using `QUICKBASE_CLI_APPTOKEN`).
* The same can also be done with username (using `QUICKBASE_CLI_USERNAME`), user token (using `QUICKBASE_CLI_USERTOKEN`) and/or app token (using `QUICKBASE_CLI_APPTOKEN`).

* ~~Moves are being made to add cool shit like a build process, global defaults, awesome starter templates, and pulling down existing code files from QuickBase. They're not out yet, so for now you're on your own.~~

Expand Down
152 changes: 76 additions & 76 deletions bin/qb-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const readFile = util.promisify(fs.readFile);
const stat = util.promisify(fs.stat);

program
.option('-w, --watch', 'deploy files on change')
.option(
'-x --replace',
'replace css and js file paths inside html file with their QuickBase url'
)
.parse(process.argv);
.option('-w, --watch', 'deploy files on change')
.option(
'-x --replace',
'replace css and js file paths inside html file with their QuickBase url'
)
.parse(process.argv);

const sourceArg = program.args[0] || '.';
const configPath = require('../lib/find-config')(sourceArg);
Expand All @@ -31,98 +31,98 @@ const api = new ApiClient(config);
qbDeploy(sourceArg);

if (program.watch) {
console.log(`Watching for file changes in ${sourceArg}`);

watch(sourceArg, {}).on('change', fileName => {
console.log(`\nChange detected in ${fileName}`);
program.replace
? qbDeploy(sourceArg)
: qbDeploy(fileName);
});
console.log(`Watching for file changes in ${sourceArg}`);

watch(sourceArg, {}).on('change', fileName => {
console.log(`\nChange detected in ${fileName}`);
program.replace
? qbDeploy(sourceArg)
: qbDeploy(fileName);
});
}


async function qbDeploy(source) {
console.log('Uploading files to QuickBase...');

const stats = await fs.statSync(source);
const isFile = stats.isFile();

//We authenticate here, before we make a series of asynchronous api calls for each file
api.authenticateIfNeeded().then((authType) => {
if (isFile) {
return uploadToQuickbase(source)
.then(res =>
console.log(`Successfully uploaded to QuickBase:\n=> ${source}`)
)
.catch(err => console.error(err));
}

if (!isFile) {
getFiles(source).then(files => {
const uploadPromises = program.replace
? files.map(file => replaceUrlsAndUpload(file, files))
: files.map(file => uploadToQuickbase(file));

return Promise.all(uploadPromises)
.then(res =>
console.log(
`Successfully uploaded to QuickBase:\n=> ${files.join('\n=> ')}`
)
)
.catch(err => console.error(err));
});
}

}).catch((errorDesc) => console.error(errorDesc));
console.log('Uploading files to QuickBase...');

const stats = await fs.statSync(source);
const isFile = stats.isFile();

//We authenticate here, before we make a series of asynchronous api calls for each file
api.authenticateIfNeeded().then((authType) => {
if (isFile) {
return uploadToQuickbase(source)
.then(res =>
console.log(`Successfully uploaded to QuickBase:\n=> ${source}`)
)
.catch(err => console.error(err));
}

if (!isFile) {
getFiles(source).then(files => {
const uploadPromises = program.replace
? files.map(file => replaceUrlsAndUpload(file, files))
: files.map(file => uploadToQuickbase(file));

return Promise.all(uploadPromises)
.then(res =>
console.log(
`Successfully uploaded to QuickBase:\n=> ${files.join('\n=> ')}`
)
)
.catch(err => console.error(err));
});
}

}).catch((errorDesc) => console.error(errorDesc));

}


function uploadToQuickbase(file, fileContents) {
let fileName = path.basename(file);
let codePageName;
let fileName = path.basename(file);
let codePageName;

if (!fileContents) {
fileContents = fs.readFileSync(file, 'utf-8');
}
if (!fileContents) {
fileContents = fs.readFileSync(file, 'utf-8');
}

if (config.appName) {
codePageName = `${config.appName}-${fileName}`;
} else {
codePageName = fileName;
}
if (config.appName) {
codePageName = `${config.appName}-${fileName}`;
} else {
codePageName = fileName;
}

return api.uploadPage(codePageName, fileContents);
return api.uploadPage(codePageName, fileContents);
}


async function replaceUrlsAndUpload(file, allFiles) {
let fileContents = await readFile(file, 'utf-8');
let fileContents = await readFile(file, 'utf-8');

allFiles.forEach(assetFile => {
if (file !== assetFile) {
const fileName = path.basename(assetFile);
const regex = new RegExp(`("|')[^"]*${fileName}("|')`, 'g');
allFiles.forEach(assetFile => {
if (file !== assetFile) {
const fileName = path.basename(assetFile);
const regex = new RegExp(`("|')[^"]*${fileName}("|')`, 'g');

fileContents = fileContents.replace(
regex,
generateCustomPageUrl(path.basename(assetFile))
);
}
});
fileContents = fileContents.replace(
regex,
generateCustomPageUrl(path.basename(assetFile))
);
}
});

return uploadToQuickbase(file, fileContents);
return uploadToQuickbase(file, fileContents);
}


function generateCustomPageUrl(fileName) {
const suffix = config.appName
? `${config.appName}-${fileName}`
: `${fileName}`;
const suffix = config.appName
? `${config.appName}-${fileName}`
: `${fileName}`;

return `"https://${config.realm}.quickbase.com/db/${
config.dbid
}?a=dbpage&pagename=${suffix}"`;
return `"https://${config.realm}.quickbase.com/db/${
config.dbid
}?a=dbpage&pagename=${suffix}"`;
}
8 changes: 3 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
</head>
<body>
<h1>Hello, world</h1>
<p>This is a page, that should be deployed using quickbase-cli to quickbase, with styling and scripts properly referenced..!</p>
<p class="check_css">If this paragraph is bold, CSS files are properly referenced!</p>
<p class="check_js">If this paragraph is bold, JS files are properly referenced!</p>
<p><em>Florian M.</em></p>

<p>This is a page, that should be deployed using quickbase-cli to quickbase, with styling and scripts properly referenced.</p>
<p class="check_css">If this paragraph is bold, CSS files are properly referenced.</p>
<p class="check_js">If this paragraph is bold, JS files are properly referenced.</p>
<script src="static/bundle.js"></script>
</body>
</html>
Loading

0 comments on commit 009eef3

Please sign in to comment.