+
diff --git a/manifest.json b/manifest.json
index 9a089ec..261d45f 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,5 +1,5 @@
{
- "version": "3.2.2",
+ "version": "3.3.0",
"manifest_version": 2,
"default_locale": "en",
"name": "__MSG_appName__",
diff --git a/src/gas-api.js b/src/gas-api.js
index 8db002e..44a7cbd 100644
--- a/src/gas-api.js
+++ b/src/gas-api.js
@@ -5,10 +5,14 @@ class Gas {
const changed = $('.diff-file:checked').toArray().map(e => e.value);
const updatePromises = changed.filter(f => code.scm[f])
.map((file) => {
- const match = file.match(/(.*?)\.(gs|html)$/);
+ const match = file.match(/(.*?)\.(gs|html|json)$/);
if (!match || !match[1] || !match[2]) {
- showAlert('Unknow Error', LEVEL_ERROR);
+ showAlert('Unsupported file type.', LEVEL_ERROR);
return;
+ }
+ if (match[2] === 'json' && match[1] !== 'appsscript') {
+ showAlert('Unsupported file type', LEVEL_ERROR);
+ return;
}
const name = match[1];
const type = match[2];
diff --git a/src/gas-hub.js b/src/gas-hub.js
index 7e820fb..347c031 100644
--- a/src/gas-hub.js
+++ b/src/gas-hub.js
@@ -46,7 +46,17 @@ function initContext() {
context.id = match[2];
return new Promise((resolve, reject) => {
- chrome.storage.sync.get(['scm', 'token', 'user', 'baseUrl', 'bindRepo', 'bindBranch', 'bindType', 'bindPattern'], (item) => {
+ chrome.storage.sync.get([
+ 'scm',
+ 'token',
+ 'user',
+ 'baseUrl',
+ 'bindRepo',
+ 'bindBranch',
+ 'bindType',
+ 'bindPattern',
+ 'bindConfig'
+ ], (item) => {
if (!item.token) {
reject(new Error('need login'));
}
@@ -55,8 +65,11 @@ function initContext() {
context.bindBranch = item.bindBranch || {};
context.bindType = item.bindType || {};
context.bindPattern = item.bindPattern || {};
- context.filetype = context.bindType[context.id] || '.gs';
- context.ignorePattern = (context.bindPattern[context.id] || []).map(p => new RegExp(p));
+ context.bindConfig = item.bindConfig || {};
+ context.config = context.bindConfig[context.id] || {};
+ context.config.filetype = context.config.filetype || context.bindType[context.id] || '.gs';
+ context.config.ignorePattern = context.config.ignorePattern || context.bindPattern[context.id] || [];
+ context.config.manifestEnabled = context.config.manifestEnabled || false;
context.gist = context.bindRepo[context.id] && context.bindRepo[context.id].gist;
resolve(scm);
});
@@ -204,20 +217,19 @@ function initPageEvent() {
})
$(document).on('click', '#config-button', () => {
- $('#filetype').val(context.filetype);
- const pattern = context.bindPattern[context.id] || [];
- $('#ignore-pattern').val(pattern.join(';'));
+ $('#filetype').val(context.config.filetype);
+ $('#manage-manifest').prop("checked", context.config.manifestEnabled);
+ $('#ignore-pattern').val(context.config.ignorePattern.join(';'));
changeModalState('config', true);
});
$(document).on('click', '#save-config', () => {
- context.filetype = $('#filetype').val();
- context.bindType[context.id] = context.filetype;
- let pattern = $('#ignore-pattern').val().split(';').filter(p => p !== '');
- context.bindPattern[context.id] = pattern;
+ context.config.filetype = $('#filetype').val();
+ context.config.manifestEnabled = $('#manage-manifest').prop( "checked" );
+ context.config.ignorePattern = $('#ignore-pattern').val().split(';').filter(p => p !== '');
+ context.bindConfig[context.id] = context.config;
try {
- context.ignorePattern = pattern.map(p => new RegExp(p));
- chrome.storage.sync.set({ bindType: context.bindType, bindPattern: context.bindPattern });
+ chrome.storage.sync.set({ bindConfig: context.bindConfig });
changeModalState('config', false);
} catch (err) {
showAlert(err.message, LEVEL_ERROR);
@@ -275,8 +287,11 @@ function initPageEvent() {
function prepareCode() {
return Promise.all([gas.getGasCode(), scm.getCode()])
.then((data) => {
- const re = new RegExp(`\\${context.filetype}$`);
+ const re = new RegExp(`\\${context.config.filetype}$`);
const files = $('.item').toArray().reduce((hash, e) => {
+ if (context.config.manifestEnabled && e.innerText === 'appsscript.json') {
+ hash['appsscript'] = 'appsscript.json';
+ }
const match = e.innerText.match(/(.*?)\.(gs|html)$/);
if (!match || !match[1] || !match[2]) return hash;
hash[match[1]] = match[0];
@@ -313,8 +328,11 @@ function showDiff(code, type) {
})
.concat(gasFiles)
.filter(file => {
- for (let i = 0; i < context.ignorePattern.length; i ++) {
- let p = context.ignorePattern[i];
+ if (context.config.manifestEnabled && file === 'appsscript.json') {
+ return true;
+ }
+ for (let i = 0; i < context.config.ignorePattern.length; i ++) {
+ let p = new RegExp(context.config.ignorePattern[i]);
if (p.test(file)) return false;
}
const match = file.match(/(.*?)\.(gs|html)$/);
@@ -325,6 +343,9 @@ function showDiff(code, type) {
if (!oldCode[file]) {
mode = 'new file mode 100644';
} else if (!newCode[file]) {
+ if (file === 'appsscript.json') {
+ return diff; //can not delete manifest file
+ }
mode = 'deleted file mode 100644';
}
let fileDiff = JsDiff.createPatch(file, oldCode[file] || '', newCode[file] || '');
diff --git a/src/scm/bitbucket.js b/src/scm/bitbucket.js
index 15bc381..a298516 100644
--- a/src/scm/bitbucket.js
+++ b/src/scm/bitbucket.js
@@ -80,7 +80,7 @@ class Bitbucket {
push(code){
const changed = $('.diff-file:checked').toArray().map(elem => elem.value);
const files = changed.filter(f => code.gas[f]).map(f => {
- return { name: f.replace(/\.gs$/, context.filetype), content: code.gas[f] }
+ return { name: f.replace(/\.gs$/, context.config.filetype), content: code.gas[f] }
});
const deleteFiles = changed.filter(f => !code.gas[f]);
const comment = $('#commit-comment').val();
@@ -287,7 +287,7 @@ class Bitbucket {
}).map(dir => {
return `${dir.links.self.href}?access_token=${data.token}`;
})
- const re = new RegExp(`(\\${context.filetype}|\\.html)$`);
+ const re = new RegExp(`(\\${context.config.filetype}|\\.html${context.config.manifestEnabled ? '|^appsscript.json' : ''})$`);
const files = response.values.filter(src => {
return src.type === 'commit_file' && re.test(src.path);
});
diff --git a/src/scm/github.js b/src/scm/github.js
index db79ed6..4d68878 100644
--- a/src/scm/github.js
+++ b/src/scm/github.js
@@ -23,7 +23,6 @@ class Github {
pushToRepo(code) {
const changed = $('.diff-file:checked').toArray().map(elem => elem.value);
- const unchanged = Object.keys(code.gas).filter((f) => changed.indexOf(f) < 0 );
const promises = changed.filter(f => code.gas[f]).map((file) => {
const payload = {
content: code.gas[file],
@@ -41,7 +40,7 @@ class Github {
data: JSON.stringify(payload)
})
.then(response => {
- return {file: file.replace(/\.gs$/, context.filetype), blob: response};
+ return {file: file.replace(/\.gs$/, context.config.filetype), blob: response};
})
});
if (changed.length === 0) {
@@ -65,7 +64,6 @@ class Github {
}
)
.then(baseTree => {
- const re = new RegExp(`(\\${context.filetype}|\\.html)$`);
const tree = responses[0].map((data) => {
return {
path: data.file,
@@ -75,7 +73,7 @@ class Github {
}
})
.concat(baseTree.tree.filter((t) => {
- return (t.type != 'tree') && (!re.test(t.path) || unchanged.indexOf(t.path) >= 0);
+ return (t.type != 'tree') && (changed.indexOf(t.path) < 0);
}));
return {
tree: tree
@@ -156,7 +154,7 @@ class Github {
files: {}
};
files.forEach(file => {
- payload.files[file.replace(/\.gs$/, context.filetype)] = {
+ payload.files[file.replace(/\.gs$/, context.config.filetype)] = {
content: code.gas[file]
};
});
@@ -222,7 +220,7 @@ class Github {
);
})
.then(response => {
- const re = new RegExp(`(\\${context.filetype}|\\.html)$`);
+ const re = new RegExp(`(\\${context.config.filetype}|\\.html${context.config.manifestEnabled ? '|^appsscript.json' : ''})$`);
const promises = response.tree.filter((tree) => {
return tree.type === 'blob' && re.test(tree.path);
})