From 21aa14f0642ff70ae89d8abe78c0503c5073e532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Tue, 2 Feb 2021 15:57:43 +0100 Subject: [PATCH] remove ext.ts --- build/ext.js | 244 ------------------------------------------------- build/ext.ts | 252 --------------------------------------------------- package.json | 3 +- 3 files changed, 1 insertion(+), 498 deletions(-) delete mode 100644 build/ext.js delete mode 100644 build/ext.ts diff --git a/build/ext.js b/build/ext.js deleted file mode 100644 index 077ca3c22e1..00000000000 --- a/build/ext.js +++ /dev/null @@ -1,244 +0,0 @@ -"use strict"; -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } -var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var g = generator.apply(thisArg, _arguments || []), i, q = []; - return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; - function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } - function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } - function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } - function fulfill(value) { resume("next", value); } - function reject(value) { resume("throw", value); } - function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } -}; -var __asyncValues = (this && this.__asyncValues) || function (o) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var m = o[Symbol.asyncIterator], i; - return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); - function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } - function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getExtensions = void 0; -const fs_1 = require("fs"); -const path = require("path"); -const util_1 = require("util"); -const cp = require("child_process"); -const commander_1 = require("commander"); -const storage_blob_1 = require("@azure/storage-blob"); -const mkdirp = require("mkdirp"); -const plimit = require("p-limit"); -const colors = require("colors"); -const byline = require("byline"); -const stream_1 = require("stream"); -const rimraf = require("rimraf"); -const zip = require('gulp-vinyl-zip'); -const vfs = require("vinyl-fs"); -const rootPath = path.resolve(path.join(__dirname, '..')); -const vsixsPath = path.join(rootPath, '.build', 'vsix'); -const extensionsPath = path.join(rootPath, '.build', 'extensions'); -var ExtensionType; -(function (ExtensionType) { - ExtensionType["Grammar"] = "grammar"; - ExtensionType["Theme"] = "theme"; - ExtensionType["Misc"] = "misc"; -})(ExtensionType || (ExtensionType = {})); -class Prefixer extends stream_1.Transform { - constructor(prefix) { - super(); - this.prefix = prefix; - } - _transform(line, _encoding, callback) { - callback(null, `${this.prefix} ${line}\n`); - } -} -async function spawn(cmd, argsOrOpts, _opts = {}) { - return new Promise((c, e) => { - var _a; - const opts = (_a = (Array.isArray(argsOrOpts) ? _opts : argsOrOpts)) !== null && _a !== void 0 ? _a : {}; - const stdio = opts.prefix ? 'pipe' : 'inherit'; - const child = Array.isArray(argsOrOpts) - ? cp.spawn(cmd, argsOrOpts, Object.assign({ stdio, env: process.env }, opts)) - : cp.spawn(cmd, Object.assign({ stdio, env: process.env }, opts)); - if (opts.prefix) { - child.stdout.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stdout); - child.stderr.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stderr); - } - child.on('close', code => code === 0 ? c() : e(`Returned ${code}`)); - }); -} -async function exec(cmd, opts = {}) { - return new Promise((c, e) => { - cp.exec(cmd, Object.assign({ env: process.env }, opts), (err, stdout) => err ? e(err) : c(opts.trim ? stdout.trim() : stdout)); - }); -} -function getExtensionType(packageJson) { - var _a, _b, _c; - if (packageJson.main) { - return "misc" /* Misc */; - } - else if (((_a = packageJson.contributes) === null || _a === void 0 ? void 0 : _a.themes) || ((_b = packageJson.contributes) === null || _b === void 0 ? void 0 : _b.iconThemes)) { - return "theme" /* Theme */; - } - else if ((_c = packageJson.contributes) === null || _c === void 0 ? void 0 : _c.grammars) { - return "grammar" /* Grammar */; - } - else { - return "misc" /* Misc */; - } -} -async function getExtension(extensionPath) { - const packageJsonPath = path.join(extensionPath, 'package.json'); - const packageJson = JSON.parse(await fs_1.promises.readFile(packageJsonPath, 'utf8')); - const type = getExtensionType(packageJson); - const { name, version } = packageJson; - const vsixName = `${name}-${version}.vsix`; - return { - name, - version, - sourcePath: extensionPath, - installPath: path.join(extensionsPath, name), - type, - vsixPath: path.join(vsixsPath, vsixName) - }; -} -function getExtensions() { - return __asyncGenerator(this, arguments, function* getExtensions_1() { - const extensionsPath = path.join(rootPath, 'extensions'); - const children = yield __await(fs_1.promises.readdir(extensionsPath)); - for (const child of children) { - try { - const extension = yield __await(getExtension(path.join(extensionsPath, child))); - if (extension.type !== "theme" /* Theme */ && extension.type !== "grammar" /* Grammar */) { - continue; - } - yield yield __await(extension); - } - catch (err) { - if (/ENOENT|ENOTDIR/.test(err.message)) { - continue; - } - throw err; - } - } - }); -} -exports.getExtensions = getExtensions; -async function each([cmd, ...args], opts) { - var e_1, _a; - try { - for (var _b = __asyncValues(getExtensions()), _c; _c = await _b.next(), !_c.done;) { - const extension = _c.value; - if (opts.type && extension.type !== opts.type) { - continue; - } - console.log(`👉 ${extension.name}`); - await spawn(cmd, args, { cwd: extension.sourcePath }); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) await _a.call(_b); - } - finally { if (e_1) throw e_1.error; } - } -} -async function extractExtension(extension) { - await util_1.promisify(rimraf)(extension.installPath); - await new Promise((c, e) => { - zip.src(extension.vsixPath) - .pipe(new stream_1.Transform({ - objectMode: true, - transform(file, _, cb) { - if (/^extension\//.test(file.relative)) { - file.base += '/extension'; - cb(null, file); - } - else { - cb(); - } - } - })) - .pipe(vfs.dest(extension.installPath)) - .on('error', e) - .on('end', () => c()); - }); -} -async function runExtensionCI(extension, service) { - const vsixName = `${extension.name}-${extension.version}.vsix`; - const commit = await exec(`git log -1 --format="%H" -- ${extension.sourcePath}`, { trim: true }); - const container = service.getContainerClient('extensions'); - const blobName = `${commit}/${vsixName}`; - const blob = container.getBlobClient(blobName); - const prefix = `📦 ${colors.green(extension.name)}`; - try { - await blob.downloadToFile(extension.vsixPath); - console.log(`${prefix} Downloaded from cache ${colors.grey(`(${blobName})`)}`); - } - catch (err) { - if (err.statusCode !== 404) { - throw err; - } - console.log(`${prefix} Cache miss ${colors.grey(`(${blobName})`)}`); - console.log(`${prefix} Building...`); - await spawn(`yarn install --no-progress`, { prefix, shell: true, cwd: extension.sourcePath }); - await spawn(`vsce package --yarn -o ${vsixsPath}`, { prefix, shell: true, cwd: extension.sourcePath }); - if (service.credential instanceof storage_blob_1.AnonymousCredential) { - console.log(`${prefix} Skiping publish VSIX to cache (anonymous access only)`); - } - else { - const blockBlob = await blob.getBlockBlobClient(); - await blockBlob.uploadFile(extension.vsixPath); - console.log(`${prefix} Successfully uploaded VSIX to cache`); - } - } - await extractExtension(extension); -} -async function ci() { - var e_2, _a; - const { 'AZURE_STORAGE_ACCOUNT_2': account, 'AZURE_STORAGE_KEY_2': key } = process.env; - if (!account) { - throw new Error('Missing env: AZURE_STORAGE_ACCOUNT_2'); - } - const creds = key ? new storage_blob_1.StorageSharedKeyCredential(account, key) : new storage_blob_1.AnonymousCredential(); - const service = new storage_blob_1.BlobServiceClient(`https://${account}.blob.core.windows.net`, creds); - await mkdirp(vsixsPath); - const limit = plimit(10); - const promises = []; - try { - for (var _b = __asyncValues(getExtensions()), _c; _c = await _b.next(), !_c.done;) { - const extension = _c.value; - promises.push(limit(() => runExtensionCI(extension, service))); - } - } - catch (e_2_1) { e_2 = { error: e_2_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) await _a.call(_b); - } - finally { if (e_2) throw e_2.error; } - } - await Promise.all(promises); -} -if (require.main === module) { - commander_1.program.version('0.0.1'); - commander_1.program - .command('each ') - .option('-t, --type ', 'Specific type only') - .description('Run a command in each extension repository') - .allowUnknownOption() - .action(each); - commander_1.program - .command('ci') - .description('Run CI build steps for extensions') - .action(ci); - commander_1.program.parseAsync(process.argv).catch(err => { - console.error(err); - process.exit(1); - }); -} diff --git a/build/ext.ts b/build/ext.ts deleted file mode 100644 index 19d2d54c026..00000000000 --- a/build/ext.ts +++ /dev/null @@ -1,252 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { promises as fs } from 'fs'; -import * as path from 'path'; -import { promisify } from 'util'; -import * as cp from 'child_process'; -import { program } from 'commander'; -import { AnonymousCredential, BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob'; -import * as mkdirp from 'mkdirp'; -import * as plimit from 'p-limit'; -import * as colors from 'colors'; -import * as byline from 'byline'; -import { Transform, TransformCallback } from 'stream'; -import * as rimraf from 'rimraf'; -const zip = require('gulp-vinyl-zip'); -import * as vfs from 'vinyl-fs'; -import * as File from 'vinyl'; - -const rootPath = path.resolve(path.join(__dirname, '..')); -const vsixsPath = path.join(rootPath, '.build', 'vsix'); -const extensionsPath = path.join(rootPath, '.build', 'extensions'); - -const enum ExtensionType { - Grammar = 'grammar', - Theme = 'theme', - Misc = 'misc' -} - -interface IExtension { - readonly name: string; - readonly version: string; - readonly sourcePath: string; - readonly installPath: string; - readonly type: ExtensionType; - readonly vsixPath: string; -} - -// const exists = (path) => fs.stat(path).then(() => true, () => false); - -// const controlFilePath = path.join(os.homedir(), '.vscode-oss-dev', 'extensions', 'control.json'); - -// async function readControlFile() { -// try { -// return JSON.parse(await fs.readFile(controlFilePath, 'utf8')); -// } catch (err) { -// return {}; -// } -// } - -// async function writeControlFile(control) { -// await mkdirp(path.dirname(controlFilePath)); -// await fs.writeFile(controlFilePath, JSON.stringify(control, null, ' ')); -// } - -interface SpawnOptions extends cp.SpawnOptions { - readonly prefix?: string; -} - -class Prefixer extends Transform { - constructor(private prefix: string) { super(); } - _transform(line: string, _encoding: string, callback: TransformCallback): void { - callback(null, `${this.prefix} ${line}\n`); - } -} - -async function spawn(cmd: string, opts?: SpawnOptions): Promise; -async function spawn(cmd: string, args: string[], opts?: SpawnOptions): Promise; -async function spawn(cmd: string, argsOrOpts?: SpawnOptions | string[], _opts: SpawnOptions = {}): Promise { - return new Promise((c, e) => { - const opts = (Array.isArray(argsOrOpts) ? _opts : argsOrOpts) ?? {}; - const stdio = opts.prefix ? 'pipe' : 'inherit'; - const child = Array.isArray(argsOrOpts) - ? cp.spawn(cmd, argsOrOpts, { stdio, env: process.env, ...opts }) - : cp.spawn(cmd, { stdio, env: process.env, ...opts }); - - if (opts.prefix) { - child.stdout!.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stdout); - child.stderr!.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stderr); - } - - child.on('close', code => code === 0 ? c() : e(`Returned ${code}`)); - }); -} - -async function exec(cmd: string, opts: (cp.ExecOptions & { trim?: boolean }) = {}): Promise { - return new Promise((c, e) => { - cp.exec(cmd, { env: process.env, ...opts }, (err, stdout) => err ? e(err) : c(opts.trim ? stdout.trim() : stdout)); - }); -} - -function getExtensionType(packageJson: any): ExtensionType { - if (packageJson.main) { - return ExtensionType.Misc; - } else if (packageJson.contributes?.themes || packageJson.contributes?.iconThemes) { - return ExtensionType.Theme; - } else if (packageJson.contributes?.grammars) { - return ExtensionType.Grammar; - } else { - return ExtensionType.Misc; - } -} - -async function getExtension(extensionPath: string): Promise { - const packageJsonPath = path.join(extensionPath, 'package.json'); - const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8')); - const type = getExtensionType(packageJson); - const { name, version } = packageJson; - const vsixName = `${name}-${version}.vsix`; - - return { - name, - version, - sourcePath: extensionPath, - installPath: path.join(extensionsPath, name), - type, - vsixPath: path.join(vsixsPath, vsixName) - }; -} - -export async function* getExtensions(): AsyncGenerator { - const extensionsPath = path.join(rootPath, 'extensions'); - const children = await fs.readdir(extensionsPath); - - for (const child of children) { - try { - const extension = await getExtension(path.join(extensionsPath, child)); - - if (extension.type !== ExtensionType.Theme && extension.type !== ExtensionType.Grammar) { - continue; - } - - yield extension; - } catch (err) { - if (/ENOENT|ENOTDIR/.test(err.message)) { - continue; - } - - throw err; - } - } -} - -async function each([cmd, ...args]: string[], opts: { type?: string }) { - for await (const extension of getExtensions()) { - if (opts.type && extension.type !== opts.type) { - continue; - } - - console.log(`👉 ${extension.name}`); - await spawn(cmd, args, { cwd: extension.sourcePath }); - } -} - -async function extractExtension(extension: IExtension): Promise { - await promisify(rimraf)(extension.installPath); - await new Promise((c, e) => { - zip.src(extension.vsixPath) - .pipe(new Transform({ - objectMode: true, - transform(file: File, _, cb) { - if (/^extension\//.test(file.relative)) { - file.base += '/extension'; - cb(null, file); - } else { - cb(); - } - } - })) - .pipe(vfs.dest(extension.installPath)) - .on('error', e) - .on('end', () => c()); - }); -} - -async function runExtensionCI(extension: IExtension, service: BlobServiceClient): Promise { - const vsixName = `${extension.name}-${extension.version}.vsix`; - const commit = await exec(`git log -1 --format="%H" -- ${extension.sourcePath}`, { trim: true }); - const container = service.getContainerClient('extensions'); - const blobName = `${commit}/${vsixName}`; - const blob = container.getBlobClient(blobName); - const prefix = `📦 ${colors.green(extension.name)}`; - - try { - await blob.downloadToFile(extension.vsixPath); - console.log(`${prefix} Downloaded from cache ${colors.grey(`(${blobName})`)}`); - } catch (err) { - if (err.statusCode !== 404) { - throw err; - } - - console.log(`${prefix} Cache miss ${colors.grey(`(${blobName})`)}`); - console.log(`${prefix} Building...`); - await spawn(`yarn install --no-progress`, { prefix, shell: true, cwd: extension.sourcePath }); - await spawn(`vsce package --yarn -o ${vsixsPath}`, { prefix, shell: true, cwd: extension.sourcePath }); - - if (service.credential instanceof AnonymousCredential) { - console.log(`${prefix} Skiping publish VSIX to cache (anonymous access only)`); - } else { - const blockBlob = await blob.getBlockBlobClient(); - await blockBlob.uploadFile(extension.vsixPath); - console.log(`${prefix} Successfully uploaded VSIX to cache`); - } - } - - await extractExtension(extension); -} - -async function ci(): Promise { - const { 'AZURE_STORAGE_ACCOUNT_2': account, 'AZURE_STORAGE_KEY_2': key } = process.env; - - if (!account) { - throw new Error('Missing env: AZURE_STORAGE_ACCOUNT_2'); - } - - const creds = key ? new StorageSharedKeyCredential(account, key) : new AnonymousCredential(); - const service = new BlobServiceClient(`https://${account}.blob.core.windows.net`, creds); - - await mkdirp(vsixsPath); - - const limit = plimit(10); - const promises = []; - - for await (const extension of getExtensions()) { - promises.push(limit(() => runExtensionCI(extension, service))); - } - - await Promise.all(promises); -} - -if (require.main === module) { - program.version('0.0.1'); - - program - .command('each ') - .option('-t, --type ', 'Specific type only') - .description('Run a command in each extension repository') - .allowUnknownOption() - .action(each); - - program - .command('ci') - .description('Run CI build steps for extensions') - .action(ci); - - program.parseAsync(process.argv).catch(err => { - console.error(err); - process.exit(1); - }); -} diff --git a/package.json b/package.json index b6ae4b6cf70..045f0da7271 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,7 @@ "minify-vscode-reh-web": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js minify-vscode-reh-web", "hygiene": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js hygiene", "core-ci": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js core-ci", - "extensions-ci": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js extensions-ci", - "ext": "node build/ext.js" + "extensions-ci": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js extensions-ci" }, "dependencies": { "applicationinsights": "1.0.8",