deploy-website
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -29,5 +29,5 @@ #!/usr/bin/env node | ||
const AWS = __importStar(require("./services/aws")); | ||
const path_1 = require("path"); | ||
const node_path_1 = require("node:path"); | ||
const github = async (directory) => { | ||
const basePath = (0, path_1.resolve)(process.cwd(), directory); | ||
const basePath = (0, node_path_1.resolve)(process.cwd(), directory); | ||
await GH.publish(basePath); | ||
@@ -39,3 +39,3 @@ }; | ||
AWS.readFile(p, data => { | ||
const Key = p.replace((0, path_1.resolve)(directory) + '/', ''); | ||
const Key = p.replace((0, node_path_1.resolve)(directory) + '/', ''); | ||
AWS.upload(Key, data); | ||
@@ -42,0 +42,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import type { PathLike, StatOptions } from 'fs'; | ||
import type { PathLike, StatOptions } from 'node:fs'; | ||
export declare const mkdir: (path: PathLike, options?: { | ||
@@ -3,0 +3,0 @@ recursive?: boolean; |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.copy = exports.isDirectory = exports.mkdir = void 0; | ||
const promises_1 = __importDefault(require("fs/promises")); | ||
const path_1 = __importDefault(require("path")); | ||
const promises_1 = __importDefault(require("node:fs/promises")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
// making directory; return Promise<boolean> | ||
@@ -47,6 +47,6 @@ const mkdir = async (path, options = { recursive: false }) => { | ||
files.forEach(file => { | ||
const src = path_1.default.resolve(base, file); | ||
const relative = path_1.default.relative(base, src); | ||
const target = path_1.default.join(dest, relative); | ||
const dirname = path_1.default.dirname(target); | ||
const src = node_path_1.default.resolve(base, file); | ||
const relative = node_path_1.default.relative(base, src); | ||
const target = node_path_1.default.join(dest, relative); | ||
const dirname = node_path_1.default.dirname(target); | ||
pairs.push({ | ||
@@ -53,0 +53,0 @@ src: src, |
@@ -7,8 +7,7 @@ /** | ||
*/ | ||
import { GithubOptions } from '../services/github'; | ||
import type { GithubOptions } from '../services/github'; | ||
/** | ||
* Create an object for executing git commands. | ||
* @param {string} cwd Repository directory. | ||
* @param {string} exe Git executable (full path if not already on path). | ||
* @constructor | ||
* @param cwd Repository directory. | ||
* @param exe Git executable (full path if not already on path). | ||
*/ | ||
@@ -29,7 +28,7 @@ export declare class Git { | ||
* Clone a repo into the given dir if it doesn't already exist. | ||
* @param {string} repo Repository URL. | ||
* @param {string} dir Target directory. | ||
* @param {string} branch Branch name. | ||
* @param {options} options All options. | ||
* @return {Promise<Git>} A promise. | ||
* @param repo Repository URL. | ||
* @param dir Target directory. | ||
* @param branch Branch name. | ||
* @param options All options. | ||
* @return A promise. | ||
*/ | ||
@@ -39,3 +38,3 @@ static clone(repo: string, dir: string, branch: string, options: GithubOptions): Promise<Git | undefined>; | ||
* Execute an arbitrary git command. | ||
* @param {string} var_args Arguments (e.g. 'remote', 'update'). | ||
* @param var_args Arguments (e.g. 'remote', 'update'). | ||
* @return {Promise} A promise. The promise will be resolved with this instance | ||
@@ -57,4 +56,4 @@ * or rejected with an error. | ||
* Hard reset to remote/branch | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @return {Promise} A promise. | ||
@@ -65,3 +64,3 @@ */ | ||
* Fetch from a remote. | ||
* @param {string} remote Remote alias. | ||
* @param remote Remote alias. | ||
* @return {Promise} A promise. | ||
@@ -72,4 +71,4 @@ */ | ||
* Checkout a branch (create an orphan if it doesn't exist on the remote). | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @return {Promise} A promise. | ||
@@ -92,3 +91,3 @@ */ | ||
* Commit (if there are any changes). | ||
* @param {string} message Commit message. | ||
* @param message Commit message. | ||
* @return {Promise} A promise. | ||
@@ -99,3 +98,3 @@ */ | ||
* Add tag | ||
* @param {string} name Name of tag. | ||
* @param name Name of tag. | ||
* @return {Promise} A promise. | ||
@@ -106,4 +105,4 @@ */ | ||
* Push a branch. | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @param {boolean} force Force push. | ||
@@ -115,3 +114,3 @@ * @return {Promise} A promise. | ||
* Get the URL for a remote. | ||
* @param {string} remote Remote alias. | ||
* @param remote Remote alias. | ||
* @return {Promise<string>} A promise for the remote URL. | ||
@@ -122,5 +121,5 @@ */ | ||
* Delete ref to remove branch history | ||
* @param {string} branch | ||
* @param branch | ||
*/ | ||
deleteRef(branch: string): Promise<this>; | ||
} |
@@ -13,10 +13,9 @@ "use strict"; | ||
exports.Git = void 0; | ||
const child_process_1 = __importDefault(require("child_process")); | ||
const fs_1 = require("fs"); | ||
const path_1 = __importDefault(require("path")); | ||
const node_child_process_1 = __importDefault(require("node:child_process")); | ||
const node_fs_1 = require("node:fs"); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const helpers_1 = require("../helpers"); | ||
/** | ||
* @constructor | ||
* @param {number} code Error code. | ||
* @param {string} message Error message. | ||
* @param code Error code. | ||
* @param message Error message. | ||
*/ | ||
@@ -31,10 +30,9 @@ class ProcessError extends Error { | ||
* Util function for handling spawned processes as promises. | ||
* @param {string} exe Executable. | ||
* @param {Array.<string>} args Arguments. | ||
* @param {string} cwd Working directory. | ||
* @return {Promise} A promise. | ||
* @param exe Executable. | ||
* @param args Arguments. | ||
* @param cwd Working directory. | ||
*/ | ||
const spawn = (exe, args, cwd = process.cwd()) => { | ||
return new Promise((resolve, reject) => { | ||
const child = child_process_1.default.spawn(exe, args, { cwd }); | ||
const child = node_child_process_1.default.spawn(exe, args, { cwd }); | ||
const buffer = []; | ||
@@ -61,5 +59,4 @@ child.stderr.on('data', chunk => { | ||
* Create an object for executing git commands. | ||
* @param {string} cwd Repository directory. | ||
* @param {string} exe Git executable (full path if not already on path). | ||
* @constructor | ||
* @param cwd Repository directory. | ||
* @param exe Git executable (full path if not already on path). | ||
*/ | ||
@@ -81,11 +78,10 @@ class Git { | ||
* Clone a repo into the given dir if it doesn't already exist. | ||
* @param {string} repo Repository URL. | ||
* @param {string} dir Target directory. | ||
* @param {string} branch Branch name. | ||
* @param {options} options All options. | ||
* @return {Promise<Git>} A promise. | ||
* @param repo Repository URL. | ||
* @param dir Target directory. | ||
* @param branch Branch name. | ||
* @param options All options. | ||
* @return A promise. | ||
*/ | ||
static async clone(repo, dir, branch, options) { | ||
const exists = (0, fs_1.existsSync)(dir); | ||
console.log('exists', exists); | ||
const exists = (0, node_fs_1.existsSync)(dir); | ||
if (exists) { | ||
@@ -95,5 +91,3 @@ return Promise.resolve(new Git(dir, options.git)); | ||
else { | ||
// console.log('mkdir', path.dirname(path.resolve(dir))) | ||
const directory = await (0, helpers_1.mkdir)(path_1.default.dirname(path_1.default.resolve(dir)), { recursive: true }); | ||
// console.log('directory:', directory) | ||
const directory = await (0, helpers_1.mkdir)(node_path_1.default.dirname(node_path_1.default.resolve(dir)), { recursive: true }); | ||
if (directory) { | ||
@@ -112,4 +106,2 @@ const args = [ | ||
]; | ||
console.log('repo', repo); | ||
console.log('args', args.join(' ')); | ||
return spawn(options.git, args) | ||
@@ -126,3 +118,3 @@ .catch(err => { | ||
* Execute an arbitrary git command. | ||
* @param {string} var_args Arguments (e.g. 'remote', 'update'). | ||
* @param var_args Arguments (e.g. 'remote', 'update'). | ||
* @return {Promise} A promise. The promise will be resolved with this instance | ||
@@ -153,4 +145,4 @@ * or rejected with an error. | ||
* Hard reset to remote/branch | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @return {Promise} A promise. | ||
@@ -163,3 +155,3 @@ */ | ||
* Fetch from a remote. | ||
* @param {string} remote Remote alias. | ||
* @param remote Remote alias. | ||
* @return {Promise} A promise. | ||
@@ -172,4 +164,4 @@ */ | ||
* Checkout a branch (create an orphan if it doesn't exist on the remote). | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @return {Promise} A promise. | ||
@@ -216,3 +208,3 @@ */ | ||
* Commit (if there are any changes). | ||
* @param {string} message Commit message. | ||
* @param message Commit message. | ||
* @return {Promise} A promise. | ||
@@ -225,3 +217,3 @@ */ | ||
* Add tag | ||
* @param {string} name Name of tag. | ||
* @param name Name of tag. | ||
* @return {Promise} A promise. | ||
@@ -234,4 +226,4 @@ */ | ||
* Push a branch. | ||
* @param {string} remote Remote alias. | ||
* @param {string} branch Branch name. | ||
* @param remote Remote alias. | ||
* @param branch Branch name. | ||
* @param {boolean} force Force push. | ||
@@ -248,9 +240,8 @@ * @return {Promise} A promise. | ||
* Get the URL for a remote. | ||
* @param {string} remote Remote alias. | ||
* @param remote Remote alias. | ||
* @return {Promise<string>} A promise for the remote URL. | ||
*/ | ||
getRemoteUrl(remote) { | ||
console.log('getRemoteUrl()', remote); | ||
// with ssh: git@github.com:lichtquelle/deploy-website_dev.git | ||
// with https: https://github.com/lichtquelle/deploy-website_dev.git | ||
// with ssh: git@github.com:user/repo.git | ||
// with https: https://github.com/user/repo.git | ||
return this.exec('config', '--get', 'remote.' + remote + '.url') | ||
@@ -280,3 +271,3 @@ .then(git => { | ||
* Delete ref to remove branch history | ||
* @param {string} branch | ||
* @param branch | ||
*/ | ||
@@ -283,0 +274,0 @@ deleteRef(branch) { |
@@ -10,5 +10,5 @@ "use strict"; | ||
exports.invalidate = exports.upload = exports.readFile = exports.getFiles = void 0; | ||
const node_fs_1 = __importDefault(require("node:fs")); | ||
const s3_1 = __importDefault(require("aws-sdk/clients/s3")); | ||
const cloudfront_1 = __importDefault(require("aws-sdk/clients/cloudfront")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const mime_1 = __importDefault(require("mime")); | ||
@@ -43,3 +43,3 @@ const Bucket = process.env.BUCKET || ''; | ||
const readFile = (path, cb) => { | ||
fs_1.default.readFile(path, (err, data) => { | ||
node_fs_1.default.readFile(path, (err, data) => { | ||
if (err) { | ||
@@ -46,0 +46,0 @@ console.log(err, err.stack); |
@@ -40,2 +40,3 @@ /** | ||
user?: GithubUser; | ||
tag?: string; | ||
} | ||
@@ -42,0 +43,0 @@ export declare const defaults: GithubOptions; |
@@ -16,8 +16,8 @@ "use strict"; | ||
const git_1 = require("../libraries/git"); | ||
const promises_1 = __importDefault(require("fs/promises")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = __importDefault(require("util")); | ||
const promises_1 = __importDefault(require("node:fs/promises")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const node_util_1 = __importDefault(require("node:util")); | ||
const globby_1 = __importDefault(require("globby")); | ||
const helpers_1 = require("../helpers"); | ||
const fs_1 = require("fs"); | ||
const node_fs_1 = require("node:fs"); | ||
exports.defaults = { | ||
@@ -38,10 +38,10 @@ dest: '.', | ||
}; | ||
const log = util_1.default.debuglog('gh-pages'); | ||
const verbose = util_1.default.debuglog('gh-pages-verbose'); | ||
const log = node_util_1.default.debuglog('gh-pages'); | ||
const verbose = node_util_1.default.debuglog('gh-pages-verbose'); | ||
function getCacheDir() { | ||
let cache = (0, find_cache_dir_1.default)({ name: 'gh-pages' }); | ||
if (!cache) { | ||
cache = path_1.default.join(process.cwd(), '.cache/gh-pages'); | ||
if (!(0, fs_1.existsSync)(cache)) | ||
(0, fs_1.mkdirSync)(cache, { recursive: true }); | ||
cache = node_path_1.default.join(process.cwd(), '.cache/gh-pages'); | ||
if (!(0, node_fs_1.existsSync)(cache)) | ||
(0, node_fs_1.mkdirSync)(cache, { recursive: true }); | ||
} | ||
@@ -94,3 +94,3 @@ return cache; | ||
.filter(async (file) => { | ||
return await !(0, helpers_1.isDirectory)(path_1.default.join(basePath, file)); | ||
return await !(0, helpers_1.isDirectory)(node_path_1.default.join(basePath, file)); | ||
}); | ||
@@ -103,7 +103,5 @@ if (!Array.isArray(files) || files.length === 0) { | ||
const userPromise = options.user ? Promise.resolve(options.user) : git_1.Git.getUser(); | ||
verbose('ONE'); | ||
const user = await userPromise; | ||
getRepo(options) | ||
.then(async (repo) => { | ||
verbose('TWO'); | ||
repoUrl = repo; | ||
@@ -114,3 +112,3 @@ const prettyName = (0, filenamify_url_1.default)(repo.replace(/[:@]/gm, '')); | ||
verbose('prettyName', prettyName); | ||
const clone = path_1.default.join(cacheDir, prettyName); | ||
const clone = node_path_1.default.join(cacheDir, prettyName); | ||
log('Cloning %s into %s', repo, clone); | ||
@@ -121,3 +119,2 @@ const git = (await git_1.Git.clone(repo, clone, options.branch, options)); | ||
.then(async (git) => { | ||
verbose('THREE'); | ||
const url = await git.getRemoteUrl(options.remote); | ||
@@ -138,3 +135,2 @@ if (url !== repoUrl) { | ||
.then(git => { | ||
verbose('FOUR'); | ||
// only required if someone mucks with the checkout between builds | ||
@@ -162,4 +158,4 @@ log('Cleaning'); | ||
log('Removing files'); | ||
const files = await (0, globby_1.default)([options.remove, '!.git'], { cwd: path_1.default.join(git.cwd, options.dest), dot: true }); | ||
const paths = files.map(file => path_1.default.join(options.dest, file)); | ||
const files = await (0, globby_1.default)([options.remove, '!.git'], { cwd: node_path_1.default.join(git.cwd, options.dest), dot: true }); | ||
const paths = files.map(file => node_path_1.default.join(options.dest, file)); | ||
if (files.length > 0) | ||
@@ -172,3 +168,3 @@ return git.rm(...paths); | ||
log('Copying files'); | ||
await (0, helpers_1.copy)(files, basePath, path_1.default.join(git.cwd, options.dest)); | ||
await (0, helpers_1.copy)(files, basePath, node_path_1.default.join(git.cwd, options.dest)); | ||
return git; | ||
@@ -198,16 +194,17 @@ }) | ||
}) | ||
// .then(git => { | ||
// if (options.tag) { | ||
// log('Tagging') | ||
// return git.tag(options.tag).catch(error => { | ||
// // tagging failed probably because this tag already exists | ||
// log(error) | ||
// log('Tagging failed, continuing') | ||
// return git | ||
// }) | ||
// } else { | ||
// return git | ||
// } | ||
// }) | ||
.then(git => { | ||
if (options.tag) { | ||
log('Tagging'); | ||
return git.tag(options.tag).catch(error => { | ||
// tagging failed probably because this tag already exists | ||
log(error); | ||
log('Tagging failed, continuing'); | ||
return git; | ||
}); | ||
} | ||
else { | ||
return git; | ||
} | ||
}) | ||
.then(git => { | ||
if (options.push) { | ||
@@ -214,0 +211,0 @@ log('Pushing'); |
{ | ||
"name": "deploy-website", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Deploy your static website to AWS S3 or GitHub Pages.", | ||
@@ -39,5 +39,5 @@ "main": "lib/index.js", | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/node": "^15.6.1", | ||
"@types/node": "^18.11.18", | ||
"typescript": "^4.4.3" | ||
} | ||
} |
@@ -19,3 +19,10 @@ # Deploy Website | ||
``` | ||
Your workflow probably also needs some additional permission. | ||
_https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs_ | ||
```yml | ||
permissions: | ||
contents: write | ||
``` | ||
### Deploy to AWS S3 | ||
@@ -42,5 +49,1 @@ | ||
``` | ||
### Example | ||
The example (https://github.com/lichtquelle/deploy-website/blob/main/.github/workflows/test.yml) will deploy /dist to the gh-pages branch and upload /dist to and s3 bucket. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
48
5
0
32704
886