sdadfadas
62 строки · 2.3 Кб
1/*
2* Licensed to the Apache Software Foundation (ASF) under one
3* or more contributor license agreements. See the NOTICE file
4* distributed with this work for additional information
5* regarding copyright ownership. The ASF licenses this file
6* to you under the Apache License, Version 2.0 (the
7* "License"); you may not use this file except in compliance
8* with the License. You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing,
13* software distributed under the License is distributed on an
14* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15* KIND, either express or implied. See the License for the
16* specific language governing permissions and limitations
17* under the License.
18*/
19
20const { execSync } = require('child_process');21const axios = require('axios');22const { name, version } = require('./package.json');23
24function log(...args) {25console.log('[embedded-sdk-release]', ...args);26}
27
28function logError(...args) {29console.error('[embedded-sdk-release]', ...args);30}
31
32(async () => {33log(`checking if ${name}@${version} needs releasing`);34
35const packageUrl = `https://registry.npmjs.org/${name}/${version}`;36// npm commands output a bunch of garbage in the edge cases,37// and require sending semi-validated strings to the command line,38// so let's just use good old http.39const { status } = await axios.get(packageUrl, {40validateStatus: (status) => true // we literally just want the status so any status is valid41});42
43if (status === 200) {44log('version already exists on npm, exiting');45} else if (status === 404) {46log('release required, building');47try {48execSync('npm run build', { stdio: 'pipe' });49log('build successful, publishing')50execSync('npm publish --access public', { stdio: 'pipe' });51log(`published ${version} to npm`);52} catch (err) {53console.error(String(err.stdout));54logError('Encountered an error, details should be above');55process.exitCode = 1;56}57} else {58logError(`ERROR: Received unexpected http status code ${status} from GET ${packageUrl}59The embedded sdk release script might need to be fixed, or maybe you just need to try again later.`);60process.exitCode = 1;61}62})();63