@zappar/zapworks-cli
Advanced tools
Comparing version 0.6.17 to 0.7.0
@@ -178,2 +178,11 @@ "use strict"; | ||
: mergedConfig.version === storedConfig.version ? 'history' : 'userinput'; | ||
function consoleOutputForSource(source) { | ||
switch (source) { | ||
case 'cli': return '(from command line)'; | ||
case 'packagejson': return '(from package.json)'; | ||
case 'userinput': return '(from user input)'; | ||
case 'history': return '(remembered from last time)'; | ||
default: return ''; | ||
} | ||
} | ||
console.log(''); | ||
@@ -219,6 +228,6 @@ console.log(chalk.bold('= Summary =')); | ||
case 'train': | ||
training_1.trainImage(options.training); | ||
training_1.default(options.training); | ||
break; | ||
case 'zppclean': | ||
zpp_1.crush(options.zppClean.input); | ||
zpp_1.default(options.zppClean.input); | ||
break; | ||
@@ -232,6 +241,6 @@ case 'serve': | ||
case 'upload': | ||
deployments_1.upload(options.deployment); | ||
await deployments_1.upload(options.deployment); | ||
break; | ||
case 'publish': | ||
deployments_1.publish(options.deployment); | ||
await deployments_1.publish(options.deployment); | ||
break; | ||
@@ -263,10 +272,1 @@ case 'logout': | ||
exports.cli = cli; | ||
function consoleOutputForSource(source) { | ||
switch (source) { | ||
case 'cli': return '(from command line)'; | ||
case 'packagejson': return '(from package.json)'; | ||
case 'userinput': return '(from user input)'; | ||
case 'history': return '(remembered from last time)'; | ||
} | ||
return ''; | ||
} |
@@ -6,5 +6,5 @@ "use strict"; | ||
const path = require("path"); | ||
const configStore = new ConfigStore("zappar-zapworks-cli"); | ||
const configStore = new ConfigStore('zappar-zapworks-cli'); | ||
function getStoredConfig(rootDirectory) { | ||
let key = "SavedConfig:" + path.resolve(rootDirectory); | ||
const key = `SavedConfig:${path.resolve(rootDirectory)}`; | ||
return configStore.get(key) || {}; | ||
@@ -19,4 +19,4 @@ } | ||
delete config.directory; | ||
configStore.set("SavedConfig:" + path.resolve(rootDirectory), config); | ||
configStore.set(`SavedConfig:${path.resolve(rootDirectory)}`, config); | ||
} | ||
exports.setStoredConfig = setStoredConfig; |
@@ -35,3 +35,3 @@ "use strict"; | ||
} | ||
throw new Error("Unable to upload: " + error.errorDescription); | ||
throw new Error(`Unable to upload: ${error.errorDescription}`); | ||
} | ||
@@ -48,2 +48,3 @@ finally { | ||
catch (ex) { | ||
console.log(ex); | ||
return; | ||
@@ -50,0 +51,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { DeploymentProject } from "../spec"; | ||
import { DeploymentProject } from '../spec'; | ||
export interface PackageConfig { | ||
@@ -3,0 +3,0 @@ location: string | undefined; |
@@ -13,7 +13,7 @@ "use strict"; | ||
async function getPackageConfig() { | ||
let ret = { | ||
const ret = { | ||
location: undefined, | ||
config: {} | ||
config: {}, | ||
}; | ||
let search = await findPackageJSON(); | ||
const search = await findPackageJSON(); | ||
if (!search.fileLocation) | ||
@@ -23,4 +23,4 @@ return ret; | ||
try { | ||
let contents = await fs_1.promises.readFile(path.join(search.fileLocation, "package.json")); | ||
let json = JSON.parse(contents.toString()); | ||
const contents = await fs_1.promises.readFile(path.join(search.fileLocation, 'package.json')); | ||
const json = JSON.parse(contents.toString()); | ||
if (!json) | ||
@@ -30,5 +30,6 @@ return ret; | ||
} | ||
catch (ex) { } | ||
catch (ex) { | ||
} | ||
return ret; | ||
} | ||
exports.getPackageConfig = getPackageConfig; |
/// <reference types="node" /> | ||
import * as zw from '../../zw-client/src/index'; | ||
import * as zw from '@zappar/zw-api-client'; | ||
interface APIParameters { | ||
@@ -9,5 +9,5 @@ projectId: string; | ||
export default class zwClient { | ||
zwClient: zw.NodeClient; | ||
zwClient: zw.Client; | ||
constructor(); | ||
getZwClient: () => zw.NodeClient; | ||
getZwClient: () => zw.Client; | ||
uploadCDN: (zipBuffer: Buffer) => Promise<string>; | ||
@@ -14,0 +14,0 @@ publishCDN: (parameters: APIParameters) => Promise<zw.ProjectResponse>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const zw = require("../../zw-client/src/index"); | ||
const zw = require("@zappar/zw-api-client"); | ||
const chalk_1 = require("chalk"); | ||
const cliProgress = require('cli-progress'); | ||
class zwClient { | ||
constructor() { | ||
this.getZwClient = () => new zw.NodeClient({ | ||
this.getZwClient = () => new zw.Client({ | ||
clientId: 'IwCeeCsCp77du7ZfccPuaDnMA2Ec3o42mNL9CdLB', | ||
@@ -12,4 +14,19 @@ env: zw.Environment.Prod, | ||
this.uploadCDN = async (zipBuffer) => { | ||
let started = false; | ||
const progressBar = new cliProgress.Bar({ | ||
format: `Uploading |${chalk_1.cyan('{bar}')}| {percentage}%`, | ||
}, cliProgress.Presets.rect); | ||
const uploadData = await this.zwClient.zml.uploadFile(zipBuffer, zw.IFileType.UARPackage, (ev) => { | ||
console.log(ev); | ||
if (typeof ev === 'number') { | ||
if (!started) { | ||
console.log(''); | ||
progressBar.start(100, 0); | ||
started = true; | ||
} | ||
const scaleModifier = 1000000; | ||
const value = ev > 0.1 ? ev * 100 : ev * scaleModifier; | ||
progressBar.update(Number(value.toFixed(2))); | ||
if (ev === 1) | ||
progressBar.stop(); | ||
} | ||
}); | ||
@@ -16,0 +33,0 @@ return uploadData.key; |
@@ -40,3 +40,3 @@ "use strict"; | ||
const certFilename = writeTempFile(cert.cert); | ||
let port = settings.port || 8080; | ||
const port = settings.port || 8080; | ||
for (let attempt = 0; attempt < 20; attempt += 1) { | ||
@@ -43,0 +43,0 @@ try { |
@@ -17,2 +17,3 @@ export declare type Training = { | ||
}; | ||
export declare type sourceType = undefined | 'cli' | 'packagejson' | 'userinput' | 'history'; | ||
export declare type DeploymentProject = { | ||
@@ -38,2 +39,5 @@ version: string; | ||
}; | ||
export declare type ZPPClean = { | ||
input: string; | ||
}; | ||
export declare type Options = { | ||
@@ -50,5 +54,2 @@ skipPrompts?: boolean; | ||
}; | ||
export declare type ZPPClean = { | ||
input: string; | ||
}; | ||
export declare type Question = { | ||
@@ -55,0 +56,0 @@ type: string; |
import { Training as TrainingSettings } from './spec'; | ||
export declare function trainImage(settings: TrainingSettings): Promise<void>; | ||
declare function trainImage(settings: TrainingSettings): Promise<void>; | ||
export default trainImage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.trainImage = void 0; | ||
const imagetraining_1 = require("@zappar/imagetraining"); | ||
@@ -16,3 +15,3 @@ const chalk = require("chalk"); | ||
maxHeight: settings.maxHeight, | ||
excludePreview: settings.excludePreview | ||
excludePreview: settings.excludePreview, | ||
}); | ||
@@ -29,2 +28,2 @@ let finalPath = settings.output; | ||
} | ||
exports.trainImage = trainImage; | ||
exports.default = trainImage; |
/// <reference types="node" /> | ||
import * as tmp from 'tmp'; | ||
import FileInDirectoryBFS from './fs-dfs'; | ||
declare const cliProgress: any; | ||
export default class Archive extends FileInDirectoryBFS { | ||
tmpobj: tmp.FileResult; | ||
progressBar: typeof cliProgress; | ||
constructor(path: string); | ||
zip(): Promise<string | Buffer>; | ||
destroy(): void; | ||
static formatBytes: (bytes: number, decimals?: number) => string; | ||
private displayProgress; | ||
private isEmpty; | ||
private getAllDirFiles; | ||
} | ||
export {}; |
@@ -8,11 +8,11 @@ "use strict"; | ||
const fs_dfs_1 = require("./fs-dfs"); | ||
const cliProgress = require('cli-progress'); | ||
class Archive extends fs_dfs_1.default { | ||
constructor(path) { | ||
super(path, ['index.html', 'index.htm']); | ||
this.displayProgress = (p) => { | ||
const completed = p.entries.processed; | ||
const target = p.entries.total; | ||
const progress = Math.ceil((completed / target) * 100); | ||
process.stdout.write('\x1B[0G'); | ||
process.stdout.write(`${chalk_1.bold((progress))}% ${Archive.formatBytes(p.fs.processedBytes)}/${Archive.formatBytes(p.fs.totalBytes)} `); | ||
this.displayProgress = (processed, totalNumberOfFiles) => { | ||
if (processed === 1) { | ||
this.progressBar.start(totalNumberOfFiles, 0); | ||
} | ||
this.progressBar.update(processed); | ||
}; | ||
@@ -29,4 +29,25 @@ this.isEmpty = (path) => { | ||
}; | ||
this.getAllDirFiles = (dirPath, arrayOfFiles) => { | ||
const files = fs.readdirSync(dirPath); | ||
let directories = 0; | ||
arrayOfFiles = arrayOfFiles || []; | ||
files.forEach((file) => { | ||
if (fs.statSync(`${dirPath}/${file}`).isDirectory()) { | ||
directories += 1; | ||
arrayOfFiles = this.getAllDirFiles(`${dirPath}/${file}`, arrayOfFiles).files; | ||
} | ||
else { | ||
arrayOfFiles.push(file); | ||
} | ||
}); | ||
return { | ||
files: arrayOfFiles, | ||
directories, | ||
}; | ||
}; | ||
this.directory = path; | ||
this.tmpobj = tmp.fileSync({ prefix: 'zappar-', postfix: '.zip' }); | ||
this.progressBar = new cliProgress.Bar({ | ||
format: `Compressing |${chalk_1.cyan('{bar}')}| {percentage}% | ETA: {eta}s | {value}/{total}`, | ||
}, cliProgress.Presets.rect); | ||
} | ||
@@ -39,2 +60,4 @@ async zip() { | ||
} | ||
const { directories, files } = this.getAllDirFiles(this.directory, []); | ||
const totalNumberOfFiles = directories + files.length; | ||
const output = fs.createWriteStream(`${this.tmpobj.name}`); | ||
@@ -44,6 +67,7 @@ const archive = archiver('zip', { zlib: { level: 9 } }); | ||
archive.on('error', (err) => reject(chalk_1.red(err))); | ||
archive.on('progress', this.displayProgress); | ||
archive.on('progress', (p) => this.displayProgress(p.entries.processed, totalNumberOfFiles)); | ||
archive.directory(this.directory, false); | ||
output.on('close', () => { | ||
console.log('\n'); | ||
this.progressBar.stop(); | ||
console.log(''); | ||
resolve(output.path); | ||
@@ -60,10 +84,1 @@ }); | ||
exports.default = Archive; | ||
Archive.formatBytes = (bytes, decimals = 2) => { | ||
if (bytes === 0) | ||
return '0 Bytes'; | ||
const k = 1024; | ||
const dm = decimals < 0 ? 0 : decimals; | ||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; | ||
const i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
return `${parseFloat((bytes / (k ** i)).toFixed(dm)).toFixed(decimals)} ${sizes[i]}`; | ||
}; |
@@ -13,5 +13,5 @@ "use strict"; | ||
console.log(chalk_1.underline(chalk_1.yellow(`Update available:${notifier.update.latest}`))); | ||
console.log(`run ${chalk_1.blue('npm update -g zapworks')} to update`); | ||
console.log(`run ${chalk_1.blue('npm update -g @zappar/zapworks-cli')} to update`); | ||
} | ||
} | ||
exports.default = checkForUpdates; |
@@ -1,1 +0,2 @@ | ||
export declare function crush(inputPath: string): Promise<void>; | ||
declare function crush(inputPath: string): Promise<void>; | ||
export default crush; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.crush = void 0; | ||
const utils_1 = require("../zpp/src/zpputils/utils"); | ||
const path = require("path"); | ||
const unusedFilename = require("unused-filename"); | ||
const chalk_1 = require("chalk"); | ||
const index_1 = require("../modules/zpp/src/zpputils/index"); | ||
async function crush(inputPath) { | ||
let outputPath = path.join(path.dirname(inputPath), path.basename(inputPath, path.extname(inputPath)) + "_cleaned" + path.extname(inputPath)); | ||
let outputPath = path.join(path.dirname(inputPath), `${path.basename(inputPath, path.extname(inputPath))}_cleaned${path.extname(inputPath)}`); | ||
outputPath = await unusedFilename(outputPath); | ||
let inputSymbol = await utils_1.symbolReaderForPath(inputPath); | ||
let outputSymbol = await utils_1.symbolWriterForPath(outputPath); | ||
const inputSymbol = await index_1.symbolReaderForPath(inputPath); | ||
const outputSymbol = await index_1.symbolWriterForPath(outputPath); | ||
await outputSymbol.copyFrom(inputSymbol); | ||
await outputSymbol.save(); | ||
console.log("Cleaned ZPP saved at:", chalk_1.greenBright(outputPath)); | ||
console.log('Cleaned ZPP saved at:', chalk_1.greenBright(outputPath)); | ||
} | ||
exports.crush = crush; | ||
exports.default = crush; |
{ | ||
"name": "@zappar/zapworks-cli", | ||
"version": "0.6.17", | ||
"version": "0.7.0", | ||
"description": "A command-line utility to help you build and publish augmented reality experiences with ZapWorks", | ||
@@ -13,3 +13,7 @@ "main": "out/cli.js", | ||
"start": "node bin/zapworks", | ||
"test-train": "node bin/zapworks train src/tests/image.jpg ." | ||
"train": "node bin/zapworks train", | ||
"build": "node_modules/.bin/tsc", | ||
"build:zpp": "cd modules/zpp && npm run build", | ||
"publish": "node_modules/.bin/tsc && node bin/zapworks publish", | ||
"crush": "node_modules/.bin/tsc && node bin/zapworks zppclean" | ||
}, | ||
@@ -29,24 +33,22 @@ "files": [ | ||
"dependencies": { | ||
"@openid/appauth": "^1.3.0", | ||
"@zappar/imagetraining": "^1.0.1", | ||
"@zappar/imagetraining": "^1.0.2", | ||
"@zappar/zw-api-client": "^1.0.2", | ||
"archiver": "^5.2.0", | ||
"arg": "^5.0.0", | ||
"chalk": "^4.1.0", | ||
"cli-progress": "^3.9.0", | ||
"configstore": "^5.0.1", | ||
"debug": "^4.3.1", | ||
"del": "^6.0.0", | ||
"esm": "^3.2.25", | ||
"events": "^3.3.0", | ||
"extract-zip": "^2.0.1", | ||
"form-data": "^3.0.0", | ||
"fs-extra": "^9.0.1", | ||
"fs-extra": "^10.0.0", | ||
"inquirer": "^7.3.3", | ||
"is-directory": "^0.3.1", | ||
"jszip": "^3.5.0", | ||
"jszip": "^3.6.0", | ||
"local-web-server": "^4.2.1", | ||
"node-fetch": "^2.6.1", | ||
"open": "^7.3.1", | ||
"promise-fs": "^2.1.1", | ||
"qrcode-terminal": "^0.12.0", | ||
"selfsigned": "^1.10.8", | ||
"sharp": "^0.23.0", | ||
"tmp": "^0.2.1", | ||
@@ -61,9 +63,8 @@ "unused-filename": "^2.1.0", | ||
"@types/del": "^4.0.0", | ||
"@types/fs-extra": "^9.0.6", | ||
"@types/events": "^3.0.0", | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/inquirer": "^7.3.1", | ||
"@types/node": "^14.14.20", | ||
"@types/node-fetch": "^2.5.7", | ||
"@types/nodegit": "^0.26.12", | ||
"@types/promise-fs": "^2.1.1", | ||
"@types/sharp": "^0.27.1", | ||
"@types/tmp": "^0.2.0", | ||
@@ -76,5 +77,4 @@ "@types/update-notifier": "^5.0.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
@@ -17,5 +17,5 @@ # ZapWorks CLI | ||
Once installed you can use the CLI on your command line with thusly: | ||
```sh | ||
$ zapworks ... | ||
``` | ||
zapworks ... | ||
``` | ||
@@ -27,9 +27,9 @@ ## Usage | ||
Zappar's set of Universal SDKs let you track and attach content to images in 3D space. To do so, the SDKs need a file that contains an optimized description of the image, called a *target file*. To generate a target file from an image, use the CLI's `train` command: | ||
```sh | ||
$ zapworks train myImage.png | ||
``` | ||
zapworks train myImage.png | ||
``` | ||
The CLI can train PNG or JPEG images, and they should be at least 300px in each dimension to be effective. The command will output a new file, in this case `myImage.zpt`, in the current directory. You can sent the output to a different location if you like: | ||
```sh | ||
$ zapworks train myImage.png -o myFolder/target.zpt | ||
``` | ||
zapworks train myImage.png -o myFolder/target.zpt | ||
``` | ||
@@ -43,15 +43,15 @@ You might like to check out the following ZapWorks Docs article: [What Makes a Good Tracking Image?](https://docs.zap.works/best-practices/projects/what-makes-good-tracking-image/) | ||
To serve your current folder from a terminal, run the following command: | ||
```sh | ||
$ zapworks serve | ||
``` | ||
zapworks serve | ||
``` | ||
That will start a server and give you URL that you can use to access the current folder over HTTPS. If you'd like to serve a different folder, that's easy too: | ||
```sh | ||
$ zapworks serve myDistFolder/ | ||
``` | ||
zapworks serve myDistFolder/ | ||
``` | ||
If you'd like to access the site from other devices on your local network, e.g. your mobile phone, pass the `--lan` parameter: | ||
```sh | ||
$ zapworks serve --lan | ||
``` | ||
zapworks serve --lan | ||
``` | ||
@@ -61,3 +61,3 @@ With this parameter, the CLI will output a link that should work for devices on your local network, and a QR code containing the same URL that you may like to scan on a mobile device to get up and running quickly. | ||
Note - if you're using `webpack` to bundle your project (which we do recommend), you may not need this tool :-) The [`webpack-dev-server`](https://webpack.js.org/configuration/dev-server/) package can serve your content on your local network over HTTPS if you set the following options in your `webpack` configuration: | ||
``` | ||
```js | ||
module.exports = { | ||
@@ -71,2 +71,12 @@ //... | ||
}; | ||
``` | ||
``` | ||
### Clean ZapWorks Studio Symbols | ||
You may clean .zpp files using: | ||
```sh | ||
$ zapworks zppclean mySymbol.zpp | ||
``` | ||
This command takes a ZPP file (the file format of ZapWorks Studio) and produces a new file without unnecessary or redundant data. |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
23
18
78
1
85834
72
2170
+ Added@zappar/zw-api-client@^1.0.2
+ Addedcli-progress@^3.9.0
+ Addedevents@^3.3.0
+ Added@sindresorhus/is@4.6.0(transitive)
+ Added@szmarczak/http-timer@4.0.6(transitive)
+ Added@types/cacheable-request@6.0.3(transitive)
+ Added@types/http-cache-semantics@4.0.4(transitive)
+ Added@types/keyv@3.1.4(transitive)
+ Added@types/responselike@1.0.3(transitive)
+ Added@zappar/zw-api-client@1.0.2(transitive)
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addedcacheable-request@7.0.4(transitive)
+ Addedcli-progress@3.12.0(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedfs-extra@10.1.0(transitive)
+ Addedgot@11.8.6(transitive)
+ Addedhttp2-wrapper@1.0.3(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addednormalize-url@6.1.0(transitive)
+ Addedp-cancelable@2.1.1(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@2.0.1(transitive)
- Removed@openid/appauth@^1.3.0
- Removedesm@^3.2.25
- Removedform-data@^3.0.0
- Removedopen@^7.3.1
- Removedsharp@^0.23.0
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedat-least-node@1.0.0(transitive)
- Removedchownr@1.1.4(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolor@3.2.1(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removeddecompress-response@4.2.1(transitive)
- Removeddetect-libc@1.0.3(transitive)
- Removedesm@3.2.25(transitive)
- Removedexpand-template@2.0.3(transitive)
- Removedfs-extra@9.1.0(transitive)
- Removedgauge@2.7.4(transitive)
- Removedgithub-from-package@0.0.0(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedmimic-response@2.1.0(transitive)
- Removedmkdirp-classic@0.5.3(transitive)
- Removednan@2.19.0(transitive)
- Removednapi-build-utils@1.0.2(transitive)
- Removednode-abi@2.30.1(transitive)
- Removednoop-logger@0.1.1(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedprebuild-install@5.3.6(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsharp@0.23.4(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@3.1.1(transitive)
- Removedsimple-swizzle@0.2.2(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedtar@5.0.11(transitive)
- Removedtar-fs@2.1.1(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedwhich-pm-runs@1.1.0(transitive)
Updated@zappar/imagetraining@^1.0.2
Updatedfs-extra@^10.0.0
Updatedjszip@^3.6.0